Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
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
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.