Searching \ for 'Pulse Width Measurement' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/pwm/index.htm?key=pulse+width
Search entire site for: 'Pulse Width Measurement'.

Truncated match.
PICList Thread
'Pulse Width Measurement'
1997\06\30@101248 by nino.benci

flavicon
picon face
I am in the process of putting together a Pulse Width measurement
controller for a laser trigger unit. I need to measure an incomming
pulse , 20uS min to 10mS max, delay this pulse by 150uS and resend the
measured pulse. A fixed delay pulse trigger would describe it. I've got
the delay and output triggers nutted out and working on an 8MHz 16C84.
The pulse measurement side is causing insomnia. I've looked at Andy Kunz
example for RC Servo's but am having a little difficulty in translating
the Parallax ASM code to MicroChip format. Sorry, i'm MCHIP asm biased.
Any help would be appreciated. Cudos to the one who supplies a solution
with full acknowledgement in possible paper.

Nino Benci
--
-------------------------------------------------
|   From the desk of............................|
|                                               |
|   Antonio L. Benci                            |
|   Chief Technical Officer                     |
|   Department of Physics                       |
|   Monash University                           |
|   Wellington Rd, Clayton                      |
|   Victoria, AUSTRALIA, 3168                   |
|                                               |
|   email: spam_OUTnino.benciTakeThisOuTspamsci.monash.edu.au         |
|                                               |
|   tel:   +61 3 9905 3649 (bh)                 |
|   tel:   +61 3 9580 2176 (ah)                 |
|   fax:   +61 3 9905 3637 (bh)                 |
-------------------------------------------------

1997\06\30@110558 by sdattalo

face
flavicon
face
Antonio Benci wrote:
>
> I am in the process of putting together a Pulse Width measurement
> controller for a laser trigger unit. I need to measure an incomming
> pulse , 20uS min to 10mS max, delay this pulse by 150uS and resend the
> measured pulse. A fixed delay pulse trigger would describe it.

If Andy Warren's pulse measuring solution didn't (or doesn't) work
for you, then maybe this one will:

  ;This (untested) routine will measure the width of a pulse

     CLRF     pulse_width_lo
     CLRF     pulse_width_hi

  ;Wait for the pulse to go high:
     BTFSC    PULSE_PORT,PULSE_BIT
      goto    $-1

  ; 6 cycles per iteration: or 3uS per loop
CHECK_PULSE
     BTFSS    PULSE_PORT,PULSE_BIT
      goto   done

     INCF     pulse_width_hi
     INCFSZ   pulse_width_lo
      DECF    pulse_width_hi

     goto     CHECK_PULSE
done:

The 16-bit variable contains the pulse's width. Each count
corresponds to 3us. Now, is 3us enough resolution?

Scott
--
"The problem with television is not the resolution."
                                Hugh. F. Frohbach

1997\06\30@113325 by Mike Keitz

picon face
On Tue, 1 Jul 1997 00:11:00 -0700 Antonio Benci
<.....nino.benciKILLspamspam@spam@sci.monash.edu.au> writes:
>I am in the process of putting together a Pulse Width measurement
>controller for a laser trigger unit. I need to measure an incomming
>pulse , 20uS min to 10mS max, delay this pulse by 150uS and resend the
>measured pulse. A fixed delay pulse trigger would describe it. I've
>got
>the delay and output triggers nutted out and working on an 8MHz 16C84.
>The pulse measurement side is causing insomnia. I've looked at Andy
>Kunz
>example for RC Servo's but am having a little difficulty in
>translating
>the Parallax ASM code to MicroChip format. Sorry, i'm MCHIP asm
>biased.
>Any help would be appreciated. Cudos to the one who supplies a
>solution
>with full acknowledgement in possible paper.
>

Your description sounds like a delay line.  A digital soultion would be
characterized by the amount of uncertanty in the measurement of start and
stop time of the input pulse caused by sampling.  A PIC will be able to
sample at 1/4 the crystal rate; an 8 MHz PIC could resolve the pulse's
start and end to within 500 ns.

One could first consider the non-PIC solution of a long shift register
which merely shifts the sampled pulse through.  To get performance
equivalent to the proposed PIC implementation it would require a shift
register of 300 stages clocked at 2 MHz.  Such registers used to be
available in CMOS but are probably specialized items now.  A virtual
shift register can be built with a RAM and a counter to retreive an old
sample, store new sample, go to next address (think of it as a
constant-length FIFO).  This gets into some complication with needing
extra logic to coordinate the reading and writing process.  However,
higher resolution (on the order of twice the RAM's access time, or 20-30
ns with readily available CMOS SRAMs) is the benefit.

Assuming 200-500 ns resolution is acceptable, a PIC will work, having the
benefit of being able to use a standard part and add new features easily
through software.  This looks like an ideal application for the
capture/compare unit found in most 28-pin PIC16CXX.  Set the timer1 to
free-run (timer mode).  Set one CCP unit to capture the incoming pulse
and one to compare and generate the output pulse.  The program would be

set for capture rising edge
wait for capture
S = captured value
set to capture falling edge
add 150 us to S and set compare to generate rising edge
wait for capture
E = captured value
wait for compare (may have already occurred if input pulse > 150 us
add 150 us to E and set compare to generate falling edge
wait for compare
start over

The waits could be software polling if the PIC has nothing else to do, or
interrupt-driven.  Using interrupt driven will leave almost all of the
PIC porcessing time free to add more features such as outputting the
measured length of the pulse, etc.  There is no danger of the timer
overflowing, so use as fast a PIC clock as possible to improve
resolution.  At 33 MHz the sample period will be about 125 ns.

The PIC16C84 does not have a CCP module that makes this task so simple.
The job could be done, but it would require considerable use of "tricks"
to achieve 1 instruction cycle resolution.  I would probably approach it
by using the TIMER0 running continuous as a time base, the RB0 interrupt
for capture, and software synchronized to TIMER0 for generating the
output pulse.  For a one-off project it would be much simpler to switch
to a PIC having the hardware capture/compare features.

1997\06\30@125219 by James

flavicon
face
At 11:32 AM 6/30/97 -0400, you wrote:
{Quote hidden}

Why not use a CPLD or FPGA?
James

1997\06\30@145710 by Andrew Warren

face
flavicon
face
Scott Dattalo <.....sdattaloKILLspamspam.....unix.SRI.COM> wrote:

>    ; 6 cycles per iteration: or 3uS per loop
> CHECK_PULSE
>       BTFSS    PULSE_PORT,PULSE_BIT
>        goto   done
>
>       INCF     pulse_width_hi
>       INCFSZ   pulse_width_lo
>        DECF    pulse_width_hi
>
>       goto     CHECK_PULSE
> done:
>
> The 16-bit variable contains the pulse's width. Each count
> corresponds to 3us. Now, is 3us enough resolution?

   Scott:

   I count SEVEN cycles (3.5 uS) per iteration, not six... Am I
   missing something, or did you mean to re-order it like this:

       ; 6 cycles per count (3 uS per count)

       CHECK_PULSE:

           INCF     pulse_width_hi
           INCFSZ   pulse_width_lo
           DECF     pulse_width_hi

           BTFSC    PULSE_PORT,PULSE_BIT
           GOTO     CHECK_PULSE

       DONE:

   In any case, the loop can be unrolled a bit to sample once every
   five cycles (2.5 uS):

       ; 5 cycles per count (2.5 uS per count)

           MOVLW   1                        ;At CHECK_PULSE,
           MOVWF   pulse_width_lo           ;pulse_width_lo must
                                            ;contain an odd number.

       CHECK_PULSE:

           BTFSS    PULSE_PORT,PULSE_BIT
           GOTO     DONE

           INCF     pulse_width_hi
           INCFSZ   pulse_width_lo
           DECF     pulse_width_hi

           BTFSS    PULSE_PORT,PULSE_BIT
           GOTO     DONE

           INCF     pulse_width_lo

           goto     CHECK_PULSE

       DONE:

   And... Although I haven't tested this, I THINK you can cut it
   down to 5 cycles per loop another way:

      ; 5 cycles per count (2.5 uS per count)

       CHECK_PULSE:

           INCFSZ   pulse_width_lo
           DECF     pulse_width_hi

           BTFSC    PULSE_PORT,PULSE_BIT
           GOTO     CHECK_PULSE

       DONE:

           MOVF     pulse_width_lo
           ADDWF    pulse_width_hi

   Does that work?  I don't know; I may be off by one...

   -Andy

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

1997\06\30@191602 by nino.benci

flavicon
picon face
One reply was....

> From:           James <jamesspamspam_OUTRADIXGROUP.COM>

> At 11:32 AM 6/30/97 -0400, you wrote:
> >Your description sounds like a delay line.  A digital soultion would be
> >characterized by the amount of uncertanty in the measurement of start and
> >stop time of the input pulse caused by sampling.  A PIC will be able to
> >sample at 1/4 the crystal rate; an 8 MHz PIC could resolve the pulse's
> >start and end to within 500 ns.
> >
> >One could first consider the non-PIC solution of a long shift register
> >which merely shifts the sampled pulse through.  To get performance
> >equivalent to the proposed PIC implementation it would require a shift
> >register of 300 stages clocked at 2 MHz.  Such registers used to be
> >available in CMOS but are probably specialized items now.
>
> Why not use a CPLD or FPGA?
> James
>

Can I get one in an 18 PIN DIP package ???

Nino Benci.
******************************************************
* Antonio (Nino) Benci                               *
* Chief Technical Officer                            *
* Monash University - Dept of Physics                *
* Wellington Rd, Clayton. 3168                       *
* Victoria, Australia.                               *
* TEL - 61 3 9905 3649, FAX - 61 3 9905 3637         *
* EMAIL - @spam@nino.benciKILLspamspamsci.monash.edu.au               *
* WWW - http://www.physics.monash.edu.au/services/ews.html   *
******************************************************


'Pulse Width Measurement'
1997\07\01@102420 by Ray Gardiner
flavicon
face
>On Tue, 1 Jul 1997 00:11:00 -0700 Antonio Benci
><KILLspamnino.benciKILLspamspamsci.monash.edu.au> writes:
>>I am in the process of putting together a Pulse Width measurement
>>controller for a laser trigger unit. I need to measure an incomming
>>pulse , 20uS min to 10mS max, delay this pulse by 150uS and resend the
>>measured pulse. A fixed delay pulse trigger would describe it. I've
>>got
>>the delay and output triggers nutted out and working on an 8MHz 16C84.
>>The pulse measurement side is causing insomnia. I've looked at Andy
>>Kunz

<snip>

>The PIC16C84 does not have a CCP module that makes this task so simple.
>The job could be done, but it would require considerable use of "tricks"
>to achieve 1 instruction cycle resolution.  I would probably approach it
>by using the TIMER0 running continuous as a time base, the RB0 interrupt
>for capture, and software synchronized to TIMER0 for generating the
>output pulse.  For a one-off project it would be much simpler to switch
>to a PIC having the hardware capture/compare features.

I agree, it would be easier with a 16c74 or anything with a CCP
module, however, in the interests of a challenge why not try
something along the following lines.

 1. Wait in a tight loop for rising edge.

 2. Start TIMER0 interrupts running at say 100us (200*.5us)
    that would mean presetting TMR0 to 56. (I think 256-200)

 3. Wait in a tight loop for falling edge, during which time
    the interrupt routine is ticking along every 100us

 4. When you get the falling edge, Immediately read TMR0 and
    add (100-TMR0) to the 100us count. Disable interrupts at
    this point.

Fine Tuning Time.
Count the clock cycles (latency) and derive the constant
overhead to subract from the measured time above.

Problems may have.
Keep the interrupt service routine short. Forget about
doing other stuff while in this pulse measuring mode.

In the worst case (20us pulse) you should get +-1or2 cycles
Is this sufficiently accurate for your needs? If not then
consider a redesign using a pic with the counter module.



Ray Gardiner  Technical Director DSP systems Pty. Ltd. RemoveMErayTakeThisOuTspamdsp-systems.com
private email to:- spamBeGonerayspamBeGonespamnetspace.net.au          http://www.dsp-systems.com

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