Kevin asked:
I want to measure a slow-speed (~1 sec) digital event using an input line on a CC16. The On time is about 50mS. What is an example of efficient MultiTrack code to measure the pulse interval?
Hi Kevin, the following MultiTrack task will measure the input pulse period to 10mS. It produces a new reading for each pulse and has a data ready semaphore. The result is a floating point number. I haven't tested this code.
Start
LaunchTask PulseInterval
RunTasksForever
;------ Pulse interval task ----------------
; Short name PI_
;Measures the interval (period) in 10mS increments between pulses
;on an input. The result is available in fPI_PulseInterval
;as a floating point number. Semaphore sPI_Rdg is set
;each time a new reading is available. If you clear sPI_Rdg when
;you read out a result, you can synchronise another program
;to "do its thing" only each time a new reading is
;available.
;*** Make sure your program won't hang if there are no input pulses.
;Note the program uses InputF to bypass the input debounce filter, which
;introduces a 10-20mS delay.
iPI_Pulse iEQU 0
tmrPI_PulseInt defTIME24
fPI_PulseInterval defFLOAT
sPI_Rdg defSEM
PulseInterval:
;Initially wait until input is OFF
PI_0:
YieldTask
InputF iPI_Pulse
GoIfT PI_0
;Wait for first ON transition
PI_1:
YieldTask
InputF iPI_Pulse
GoIfF PI_1
;Start timing from leading (ON) edge.
PI_Set2:
STStart tmrPI_PulseInt
;Wait for OFF transition (end of start pulse)
PI_2:
YieldTask
InputF iPI_Pulse
GoIfT PI_2
;Wait for ON transition of the next (stop) pulse
PI_3:
YieldTask
InputF iPI_Pulse
GoIfF PI_3
fSTTimeSince tmrPI_PulseInt
fStore fPI_PulseInterval
SetS sPI_Rdg
GoTo PI_Set2 ;This Stop pulse becomes the
;Start of the next period.
