3 timer and latch mode example – Rockwell Automation 57C421B Pulsetach Input Module/DCS 5000/AutoMax User Manual
Page 40

4Ć18
4.4.3
Timer and Latch Mode Example
The following is an example of a BASIC task that handles interrupts
from the module. All variables declared as COMMON are assumed
to have previously been defined during configuration.
In the example below, the task counts pulses generated by the
internal 200 kHz clock. Each time an external latch input signal is
received, the task latches the counter data and then clears the
counter.
1
!ă
2
!ăTIMER AND EXTERNAL LATCH MODE EXAMPLE
3
!ăTASK NAME: PG_LATCH
4
!ăPRIORITY: 10
5
!ă
1000
COMMON COUNT%
\!ăCounter data
1005
COMMON ISCR%
\!ăInterrupt status & control
1010
COMMON RESET@
\!ăCounter reset
1015
COMMON EXT_LATCH_EN@ \!ăExternal latch enable
1020
COMMON LATCH_POLARITY@ \!ăExternal latch polarity
1025
COMMON LATCH_RESET@
\!ăExternal latch interrupt reset
1030
COMMON TIM_MOD@
1035
COMMON LAT_INT@
1040
COMMON CCLK_EN@
1045
COMMON CLR_MOD1@
1050
COMMON CLR_MOD2@
1200
LOCAL DELTA%
\!ăTime between external events
3000
!ă
3001
!ăThe following statement connects the name COUNTER_EVENT
3002
!ăto the interrupt defined in ISCR%. The event name should
3003
!ăbe as descriptive as possible. The watchdog timeout has
3004
!ăbeen disabled because the event is not periodic.
3005
!ă
3006
!ă
3007
!ă
3010
EVENT NAME=COUNTER_EVENT, INTERRUPT_STATUS=ISCR% ă
ă&
TIMEOUT=DISABLED
4000
!
4001
!ăThe following statements initialize the counter and set
4002
!ăup the interrupt control. Constant clock" is enabled on
4003
!ăthis module. If there is more than one interrupt task in
4004
!ăa chassis, the task that enables constant clock" should
4005
!ăalways be the lowest priority task.
4006
!ă
4010
RESET@ = TRUE \ RESET@ = FALSE \!ăZero counter
4015
EXT_LATCH_EN@ = TRUE
\!ăEnable the external latch
4020
LATCH_POLARITY@ = FALSE \!ăLatch input is high true
4025
TIM_MOD@ = ON
\! Timer mode
4030
LAT_INT@ = ON
\! External latch int. enable
4035
CLR_MOD1@ = OFF
\! Clear counter after
4040
CLR_MOD2@ = ON
\! External latch
4045
CCLK_EN@ = ON
\! Enable CCLK
5988
!
5989
!ăPlace additional initialization software here.
5990
!
5991
!ă
5992
!ăThe next statement synchronizes the task to the occurence
5993
!ăof the external latch via the interrupt. Task execution
5994
!ăwill be suspended until the interrupt occurs. When the
5995
!ăinterrupt occurs, if this task is the highest priority
5996
!ătask waiting to execute, it will become active. If it is
5997
!ănot the highest priority task, it will remain suspended
5998
!ăuntil all other higher priority tasks have been executed
5999
!ăat which point it will then become active.
6000
WAIT ON COUNTER_EVENT
6997
!
6998
!ăThe following statements perform the interrupt service
6999
!ăroutine.
7000
DELTA% = COUNT%
\!ăRead time between external events
7005
LATCH_RESET@ = FALSE
\!ăReset the interrupt
7010
GOTO 6000
\!ăWait for the next event
32767
END