'Pulse Measurement Loop'
I recall a while ago somebody (Scott?) posted a routine for very accurate
measurement of pulses.
I need to measure a 500-2500 instruction cycle pulse at 4 or better cycle
resolution on a standard PORTB pin (not int-on-change) in a '711.
I also need to catch and report invalid (short or long) pulses.
Anybody have that posting?
Andy Kunz - Statistical Research, Inc. - Westfield, New Jersey USA
|>I recall a while ago somebody (Scott?) posted a routine for very accurate
>measurement of pulses.
>I need to measure a 500-2500 instruction cycle pulse at 4 or better cycle
>resolution on a standard PORTB pin (not int-on-change) in a '711.
>I also need to catch and report invalid (short or long) pulses.
>Anybody have that posting?
I posted the orginal question and several very helpful souls found the
answer I am now using. The core of the routine came from Scott Dattalo. Enjoy!
The following is snipped from one of my messages to Scott:
BTW: the code works VERY well. Its being used to measure the pulse duty
cycle ratio from Analog Devices TMP03 / 04 temperature sensors and can
resolve down to fractins of a degree (far more accuracy than the sensor). I
cleaned the normalize part of the routine up slightly as follows at the end
of this message.
The entire measurement routine (wait for HI, wait for LO, measure LO,
measure HI, test for noisy signal, normalize everything, multiply HI pulse
by constant, divide by LO pulse, average 16 samples) takes about 400 code
spaces - left me lots of room for the rest of the project in a 12c508.
;up to 19 bit pulse timer with 3 cycle resolution
;concept by Scott Dattalo, this version by Dwayne Reid
;now measure HI period
clrf MH_high ;used as known zero for main loop
rlf MH_high,W ;get C into W lsb (add 0 or 1 to next byte)
addwf MH_mid,F ;add previous carry
;use either line below (not both)
btfss MH_mid,5 ;5 = 16 bits; 6 = 17 bits; 7 = 18; skpc = 19
; skpc ;5 = 16 bits; 6 = 17 bits; 7 = 18; skpc = 19
nop ;spare cycle!
incf MH_high,F ;MH_high now used to accumulate LSBs
MH_5th ;use either line below (not both)
btfsc MH_mid,5 ;5 = 16 bits; 6 = 17 bits; 7 = 18; skpnc =19
; skpnc ;5 = 16 bits; 6 = 17 bits; 7 = 18; skpnc =19
goto overflow ;
subwf MH_mid,F ;undo increment, if any
decf MH_low,F ;undo increment
;normalize high period
movfw MH_high ;get LSB count into w
clrf MH_high ;
clrc ;make room for lower 3 LSBs
rlf MH_low,F ; (shift everything to the left 3 bits)
rlf MH_high,F ;
rlf MH_high,F ;none of this affects LSB count in w
iorwf MH_low,F ;put LSBs into low byte
Dwayne Reid <planet.eon.net> dwayner
Trinity Electronics Systems Ltd Edmonton, AB, CANADA
(403) 489-3199 voice (403) 487-6397 fax
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- New search...