How to count pulses using Modulus Down counter

Started by nrmlguru June 25, 2005
Hello,
I am Gurumurthy. I am using 68hc12 for controlling the DC
motor.
I have an encoder which gives the feedback interms of pulses (100
pulses per revolution).

I want to read these pulses and thereby i got to decide the
speed of the motor.

I tried it with configuring onr of the timer into Input
capture
mode and based on interrupt mode I am counting the pulses. But
getting
the pulses at timer i/p and then executing an ISR is taking too much
time. Inbetween this time I am loosing some of the counts(pulse
count).

How can it be overcome?? Is Modulus down counter going to help
me in this regard??

Please help me in this regard. If u provide an excample code
it
will be great.

Thank you

Regards
Gurumurthy


Instead of counting pulses use the number of timer ticks beween pulses to calculate the speed. Don't know what processor speed you are running or what your prescaler is set to so I can't give you the exact calculation.

Dean

----- Original Message -----
From: nrmlguru
To: 68HC12@68HC...
Sent: Saturday, June 25, 2005 10:53 AM
Subject: [68HC12] How to count pulses using Modulus Down counter Hello,
I am Gurumurthy. I am using 68hc12 for controlling the DC
motor.
I have an encoder which gives the feedback interms of pulses (100
pulses per revolution).

I want to read these pulses and thereby i got to decide the
speed of the motor.

I tried it with configuring onr of the timer into Input
capture
mode and based on interrupt mode I am counting the pulses. But
getting
the pulses at timer i/p and then executing an ISR is taking too much
time. Inbetween this time I am loosing some of the counts(pulse
count).

How can it be overcome?? Is Modulus down counter going to help
me in this regard??

Please help me in this regard. If u provide an excample code
it
will be great.

Thank you

Regards
Gurumurthy
------
Yahoo! Groups Links

a.. To



In a message dated 6/25/05 3:25:22 P.M. Eastern Daylight Time,
dean@dean... writes:

I have an encoder which gives the feedback interms of pulses (100
pulses per revolution).

=======================
I think some HC12s have encoder inputs. My memory isnt so hot sometimes.
There are examples of using edge sensitive interrupts to read the encoders. If
you have a timer iterrupt that gives you time, and the encoder count, you can
compute speed very accurately.


Hey dean

I am using a processor mc98s12dg256 with 8MHz clock.
If I use a timer in IC mode then how to keep track of two consecutive
pulses? --- In 68HC12@68HC..., "Dean Manion" <dean@m...> wrote:
> Instead of counting pulses use the number of timer ticks beween
pulses to calculate the speed. Don't know what processor speed you
are running or what your prescaler is set to so I can't give you the
exact calculation.
>
> Dean
>
> ----- Original Message -----
> From: nrmlguru
> To: 68HC12@68HC...
> Sent: Saturday, June 25, 2005 10:53 AM
> Subject: [68HC12] How to count pulses using Modulus Down counter > Hello,
> I am Gurumurthy. I am using 68hc12 for controlling the DC
> motor.
> I have an encoder which gives the feedback interms of pulses (100
> pulses per revolution).
>
> I want to read these pulses and thereby i got to decide
the
> speed of the motor.
>
> I tried it with configuring onr of the timer into Input
> capture
> mode and based on interrupt mode I am counting the pulses. But
> getting
> the pulses at timer i/p and then executing an ISR is taking too
much
> time. Inbetween this time I am loosing some of the counts(pulse
> count).
>
> How can it be overcome?? Is Modulus down counter going to
help
> me in this regard??
>
> Please help me in this regard. If u provide an excample
code
> it
> will be great.
>
> Thank you
>
> Regards
> Gurumurthy >
> --------------------------------
----------
> Yahoo! Groups Links
>
> a.. To >
>


You should use the pulse accumulator instead of
triggering an interrupt each time you receive a pulse.
By using the pulse accumulator in conjunction with a
periodic interrupt based off of the mod down counter
you could determine the speed of your motor.

If you have the mod down counter interrupt every 10ms
you can calculate the difference in the pulse
accumulator now, and 10ms ago. That difference will
give you the number of pulses in the last 10ms, using
that you can easily figure out the speed of the motor. Hope this helps.

Jason M. Liszewski
Embedded Systems Engineer
Syn-Tech Systems, Inc.
--- nrmlguru <nrmlguru@nrml...> wrote:

> Hello,
> I am Gurumurthy. I am using 68hc12 for
> controlling the DC
> motor.
> I have an encoder which gives the feedback interms
> of pulses (100
> pulses per revolution).
>
> I want to read these pulses and thereby i
> got to decide the
> speed of the motor.
>
> I tried it with configuring onr of the timer
> into Input
> capture
> mode and based on interrupt mode I am counting the
> pulses. But
> getting
> the pulses at timer i/p and then executing an ISR is
> taking too much
> time. Inbetween this time I am loosing some of the
> counts(pulse
> count).
>
> How can it be overcome?? Is Modulus down
> counter going to help
> me in this regard??
>
> Please help me in this regard. If u provide
> an excample code
> it
> will be great.
>
> Thank you
>
> Regards
> Gurumurthy

____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com



On Mon, Jun 27, 2005 at 10:52:20AM +0000, nrmlguru wrote:
> If I use a timer in IC mode then how to keep track of two consecutive
> pulses?

Each time the input capture fires, it triggers an interrupt.
The interrupt handler should read the timer channel register for the
capture to get the time (in TCNT ticks) at which the capture happened.
Successive calls to the interrupt handler can look at the increment of
the captured times to see how long it was between the previous event
and the current one.

Stephen

--
Stephen Trier
Technical Development Lab
Cleveland FES Center
sct@sct@...