« Tech Support: Many timers | Main | New counter feature »

Tech Support: Interval measurement

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.

TrackBack

TrackBack URL for this entry:
http://www.splatco.com/cgi-sys/cgiwrap/microcon/managed-mt/mt-tb.cgi/56

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


About

This page contains a single entry from the blog posted on July 14, 2007 5:21 PM.

The previous post in this blog was Tech Support: Many timers.

The next post in this blog is New counter feature.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.33