Truncated match.
PICList
Thread
'Pulse Measurement Loop'
1998\10\23@150407
by
Andy Kunz
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?
Thanks.
Andy
==================================================================
Andy Kunz - Statistical Research, Inc. - Westfield, New Jersey USA
==================================================================
1998\10\23@175919
by
Dwayne Reid
|
>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_low
clrf MH_mid
clrf MH_high ;used as known zero for main loop
MH_loop
btfss PULSE
goto MH_1st
movlw 1
btfss PULSE
goto MH_2nd
addwf MH_low,F
btfss PULSE
goto MH_3rd
rlf MH_high,W ;get C into W lsb (add 0 or 1 to next byte)
btfss PULSE
goto MH_4th
addwf MH_mid,F ;add previous carry
btfss PULSE
goto MH_5th
;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
btfss PULSE
goto MH_6th
nop ;spare cycle!
btfss PULSE
goto MH_7th
clrwdt
btfsc PULSE
goto MH_loop
MH_8th
incf MH_high,F ;MH_high now used to accumulate LSBs
MH_7th
incf MH_high,F
MH_6th
incf MH_high,F
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
incf MH_high,F
MH_4th
incf MH_high,F
MH_3rd
decf MH_low,F ;undo increment
incf MH_high,F
MH_2nd
incf MH_high,F
MH_1st
;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_mid,F
rlf MH_high,F ;
rlf MH_low,F
rlf MH_mid,F
rlf MH_high,F
rlf MH_low,F
rlf MH_mid,F
rlf MH_high,F ;none of this affects LSB count in w
iorwf MH_low,F ;put LSBs into low byte
;done!
Dwayne Reid <spam_OUTdwaynerTakeThisOuT
planet.eon.net>
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
- Today
- New search...