Interrupt frequency?

Status
Not open for further replies.

MrMikey83

New Member
I have motor encoders connected to interrupts on my ATmega32 and need to be able to convert the number of interrupts to a value like feet per second. How should I go about doing this?
~Mike
 
this is for your balancing bot ?, which is comming along nicely , i might add..
how many pulses do the encoders output per revolution??
 
the formula for feet per second would be... this is hard to explain but here goes..your wheels are 5 inches in diameter ?
in the numerator Pi *Diameter (Rev pulses inches)
in thr demominator 7 pulses * (your time base in (seconds)( Rev)
where (REV & pulses) cancel out and you are left with inches per second..

or put another way
(Pi * 5 inches )/7 *( whatever time base you end up with in seconds)

or put another way say your bot is going real slow and your uController recieves 7 pulses in 1 sec.. then it will have gone 15.7 inches in one sec..
hope this helps..
divide this number by 12 for feet per sec.
 
Yes, I can calculate the values, but how would I go about capturing this through the interrupts?
Perhaps I could use the counter...

Timer1 = 0;
SensorCount = 0;
while(Timer1<50000)
{}
SensorTime = SensorCount;

So, it resets the timer and the Count Value, then waits for the Timer1 to get to a set amount. Then it sends the count value to SensorTime for use by the rest of the program.

I think that will work...same basic idea I used to capture the timing of the radio receiver signals.

Anyway, I'm running the timer at 500kHz. How many timer tics will go by in .1 seconds?
 
You will need a quadrature reading off your encoder so you can tell the direction of rotation. It will also double your resolution. All you need is another IR sensor that is spaced so it gives a reading 90degrees out of phase with the first sensor.

The easiest way to deal with encoders is to count pulses. Each change in state generates an interrupt. In that interrupt you check what the new state is and increment or decrement your position counter depending on which way the wheel turned.

Timing the time between pulses is problematic because if the wheel doesn't turn for a while your timer overflows and you have an undefined speed.
 
Why do I need to sense rotation dirrection?
I'm using an output to control the forward and backward motion of each motor so why couldn't I use that signal to tell which way the motor is going?
 
Its important to sense direction because inputs in the wrong direction can cause your controller to run away. Say your robot is on a hill and is applying force to keep from rolling backwards. If it rolls back a bit and gets a input edge. It thinks it's moving forward and so it'll reduce the power to the motors. This power reduction causes it to roll backwards even more causing more input edges making the problem worse. The same problem is true with any external force.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…