Searching \ for 'PULSE MEASURING' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=pulse+measuring
Search entire site for: 'PULSE MEASURING'.

Truncated match.
PICList Thread
'PULSE MEASURING'
1998\03\30@122842 by Alastair

flavicon
Hi All
It looks as if the list is always divided into three types of users: those who do know, those who don't and those who don't care!
Anyway as one who doesn't know I'd like any help you've got to give, please.
I need to measure the width of a pulse which occurs at about 30Hz with a 16c(f)84, the pulse width is variable between 1ms and 2ms and I need as high a resolution as possible(about 7bit should do) on the 1ms difference between the two extremes.
As usual the routine needs to use as little as possible processor time.
Any code will be most helpful.

Thanks
Robert

   

1998\03\30@122842 by Alastair

flavicon
Hi All
It looks as if the list is always divided into three types of users: those who do know, those who don't and those who don't care!
Anyway as one who doesn't know I'd like any help you've got to give, please.
I need to measure the width of a pulse which occurs at about 30Hz with a 16c(f)84, the pulse width is variable between 1ms and 2ms and I need as high a resolution as possible(about 7bit should do) on the 1ms difference between the two extremes.
As usual the routine needs to use as little as possible processor time.
Any code will be most helpful.

Thanks
Robert

   

1998\03\30@132348 by Andrew Warren

face
flavicon
face
Alastair <spam_OUTPICLISTTakeThisOuTspamMITVMA.MIT.EDU> wrote:

> I need to measure the width of a pulse which occurs at about 30Hz
> with a 16c(f)84, the pulse width is variable between 1ms and 2ms
> and I need as high a resolution as possible(about 7bit should do)
> on the 1ms difference between the two extremes. As usual the
> routine needs to use as little as possible processor time. Any
> code will be most helpful.

Robert:

Here's a copy of the message I posted the last time someone wanted to
measure RC servo pulse-widths... I hope it helps.

------- Forwarded Message Follows -------

From:          Self <Single-user mode>
To:            .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU
Subject:       Re: Measuring pulse lenght
Date:          Mon, 23 Jun 1997 18:36:53 -0800

Quentin <PICLISTspamKILLspamMITVMA.MIT.EDU> wrote:

{Quote hidden}

Quentin:

I haven't done it before (one of the OTHER Andys is the resident RC
servo expert), but I'd probably do something like this.  It requires
17 words of code space and assumes a 4 MHz clock:

   ; Masure the width of a pulse on RCIN.
   ;
   ; If the pulse is > 2 ms, return with w = 1.
   ; If the pulse is < 1 ms, return with w = 2.
   ; If the pulse is between 1 and 2 ms, return with w = 0 and
   ; TIME = (pulse width in microseconds - 1000)/4... That is:
   ;
   ; Pulse width in microseconds:    TIME:
   ; ----------------------------    -----
   ;         1000                      0
   ;         1100                     25
   ;         1200                     50
   ;         1300                     75
   ;         ....                    ...
   ;         1900                    225
   ;         2000                    250
   ;
   ; NOTE:  THIS ROUTINE ASSUMES A 4 MHZ CLOCK!

   #DEFINE RCIN    PORTA.0         ;or whatever.

   TIME    EQU     [any general-purpose reg]

   ....

   MEASURE_A_PULSE:

       MOVLW   (256-250)       ;Setup to watch the pulse for 1 ms.
       MOVWF   TIME            ;

   WAIT4GAP:

       BTFSC   RCIN            ;Wait for a high-going edge.
       GOTO    WAIT4GAP        ;
                               ;
   WAIT4PULSE:                 ;
                               ;
       BTFSS   RCIN            ;
       GOTO    WAIT4PULSE      ;

   ; We've seen a high-going edge.  Make sure the pulse lasts for at
   ; least 1 millisecond.

   WAIT_1MS:

       BTFSS   RCIN            ;If RCIN is still hi, skip ahead.
       GOTO    ERROR_SHORT     ;Otherwise, the pulse is too short,
                               ;so go exit with w = 2.

       INCFSZ  TIME            ;Have we been watching for 1 ms?
       GOTO    WAIT_1MS        ;If not, loop back and keep waiting.

   ; RCIN has been high for 1 millisecond.  TIME = 0 at this point;
   ; keep watching RCIN, incrementing TIME every 4 microseconds
   ; until either RCIN goes low or TIME = 256.

   TIME_THE_REST:

       BTFSS   RCIN            ;If RCIN is still hi, skip ahead.
       GOTO    GOT_TIME        ;Otherwise, RCIN has gone low after
                               ;1 ms but before 2 ms, so go exit
                               ;with w = 0.

       INCFSZ  TIME            ;Has RCIN been hi for > 2 ms total?
       GOTO    TIME_THE_REST   ;If not, loop back and keep timing.

   ; The pulse is > 2 ms wide [well, actually, it's greater than
   ; 2.016 ms, but who's counting?].  Exit with w = 1.

   ERROR_LONG:

       RETLW   1               ;The pulse is longer than 2
                               ;milliseconds, so return with w = 1.

   ; The pilse is < 1 ms wide, so exit with w = 2.

   ERROR_SHORT:

       RETLW   2               ;The pulse is shorter than 1
                               ;millisecond, so return with w = 2.

   ; The pulse is between 1 ms and 2 ms wide.  Exit with w = 0 and
   ; TIME = (pulse width in microseconds - 1000)/4.

   GOT_TIME:

       RETLW   0               ;The pulse is between 1 and 2
                               ;milliseconds wide.  Return with
                               ;w = 0 and pulse width in TIME.

------- End of Forwarded Message ------

-Andy

=== Andrew Warren - .....fastfwdKILLspamspam.....ix.netcom.com
=== Fast Forward Engineering - Vista, California
=== http://www.geocities.com/SiliconValley/2499

1998\03\30@141106 by Mike Keitz

picon face
On Mon, 31 Mar 1997 18:35:14 +0200 Alastair <EraseMEbizzybspam_OUTspamTakeThisOuTIAFRICA.COM.NA>
writes:
>Hi All

>I need to measure the width of a pulse which occurs at about 30Hz with
>a =
>16c(f)84, the pulse width is variable between 1ms and 2ms and I need
>as =
>high a resolution as possible(about 7bit should do) on the 1ms =
>difference between the two extremes.

There are a lot of different ways to do this, depending on what else the
PIC needs to be doing while it is measuring the pulse.

If it doesn't need to be doing anything, just have software look for the
start of the pulse then count time until the pulse ends.  Since the pulse
is only on about 1/16 of the time, there will be a lot of time between
pulses to do other processes.

The first step toward 'background' measurement would be to have the pulse
cause an interrupt (probably RB0) and the ISR would use a software timer
to measure each pulse once it starts.  This again uses about 1/16 of the
processor's time, in a big block.

A further refinement would be to have the pulse cause an interrupt again,
but the ISR would just save the TMR0 count and reconfigure the interrupt
hardware so the end of the pulse would cause another interrupt.  On this
interrupt, the TMR0 count would be sampled again and the count saved at
the start subtracted from it to find the pulse duration.  This method
uses very little processor time, however the TMR0 timer needs to be
free-running at a suitable rate (ideally, it would roll over at intervals
a little longer than 1 ms.)  If another interrupt is active it could
delay the recognition of the pulse interrupts and cause the pulses to be
mis-timed.

A completely different approach is to establish a pulse-measuring "state
machine" which is executed at rapid, regular intervals.  If the pulse is
present, it increments a counter, if no pulse is present it resets the
counter for the next one.  If the counter was not 0 when it was reset,
this means the pulse just ended so the result should be copied somewhere
else as the pulse length result.  Unfortunately, to acheive the 7-bit
accuracy required, it would need to be executed every 1ms/128 or 7.8 us.
This is about 20 PIC instructions with a 10 MHz clock.  Though it is
conceivable to implement, it would be tricky.  Prehaps it's best to keep
this technique in mind for some other time when the timing is less
demanding.


_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]


'PULSE MEASURING'
1998\04\02@143359 by ken
flavicon
picon face
In article <01BC3E08.F3687160spamspam_OUTdup4-wvb.iafrica.com.na>, Alastair
<@spam@bizzybKILLspamspamIAFRICA.COM.NA> writes
>Hi All
>It looks as if the list is always divided into three types of users: those who
>do know, those who don't and those who don't care!
>Anyway as one who doesn't know I'd like any help you've got to give, please.
>I need to measure the width of a pulse which occurs at about 30Hz with a
>16c(f)84, the pulse width is variable between 1ms and 2ms and I need as high a
>resolution as possible(about 7bit should do) on the 1ms difference between the
>two extremes.
>As usual the routine needs to use as little as possible processor time.
>Any code will be most helpful.
>

Be careful, the standard is always stated as 1 - 2mS but most RC
transmitters actually generate a pulse covering about 0.875 to 2.35mS so
make sure your code can handle this range or you will get all sorts of
unexpected problems.

Ken.

+-----------------------------+--------------------------------------------+
|      Ken Hewitt  G8PWC      |        Email KILLspamkenKILLspamspamwelwyn.demon.co.uk        |
|      /\/\/\/\/\/\/\/\/      |  Homepage   http://www.welwyn.demon.co.uk  |
+-----------------------------+--------------------------------------------+

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...