How to count pulses using Modulus Down counter

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to count pulses using Modulus Down counter

2,430 Views
khumphri
NXP Employee
NXP Employee

This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.

 

Posted: Sat Jun 25, 2005  3:53 pm

 

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. In between 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.

 


 

Posted: Sat Jun 25, 2005  7:44 pm

 

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.

 


 

Posted: Mon Jun 27, 2005  10:51 am

 

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?

 


 

Posted: Fri Jul 8, 2005  5:07 pm

 

> 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.

 


 

Posted: Sat Jun 25, 2005  10:54 pm

 

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

 


 

Posted: Mon Jun 27, 2005  1:30 pm

 

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.

Labels (1)
0 Kudos
Reply
1 Reply

655 Views
JoeGaudet
Contributor I
I've been trying to do a similar thing, but with much lower resolution.

However my current issue is that the MDCU generates interuppts way to much.

I am useing a 4 mhz processor, and even with the prescaler set to 16 I cannot get a process in edgewise without being intrerrupted.

Should this be the case ?

- Joe
0 Kudos
Reply