Electronics > Projects, Designs, and Technical Stuff
DC motor controller
OM222O:
it looks like that timer 1 allows for counting external signals. I don't think it's possible to use both singals on the same counter however. That makes me wonder how I can find the direction of rotation? I'm setting it in software when the motor is moving but if there is external forces like another robot colliding with us, that would be hard to check. should I just check it when the timer for the first signal has overflown and caused an interrupt?
I'm still looking at the datasheet and trying to figure out the details of the timers since I haven't used them outside of the normal PWM before, so please if you have an example using it as a pulse counter, share it.
P.S: yes, the drive train is only a small portion of the whole project.
max_torque:
It would be easy to count the encoder pulses over some fixed time period with an external counter IC, and the controller can just read those pulses when it wants an update.
Something like a SN74LV8154 can be used as 16b counters or a cascaed 32b counter, and the counts can be read v quickly from the parrallel output.. Use an AVR timer to generate a gating output at a suitable frequency, and read the pulse counts at each of those intervals. To avoid "Missed" counts, don't reset the counter, just let it overflow and deal with that in s/w (if new counts < old counts, counts = New+(65535-old))
https://www.ti.com/lit/ds/symlink/sn74lv8154.pdf?ts=1595964924282&ref_url=https%253A%252F%252Fwww.google.com%252F
Because the puse counting is handled externally the AVR is free to run the motor control loops
langwadt:
--- Quote from: max_torque on July 28, 2020, 07:38:34 pm ---It would be easy to count the encoder pulses over some fixed time period with an external counter IC, and the controller can just read those pulses when it wants an update.
Something like a SN74LV8154 can be used as 16b counters or a cascaed 32b counter, and the counts can be read v quickly from the parrallel output.. Use an AVR timer to generate a gating output at a suitable frequency, and read the pulse counts at each of those intervals. To avoid "Missed" counts, don't reset the counter, just let it overflow and deal with that in s/w (if new counts < old counts, counts = New+(65535-old))
https://www.ti.com/lit/ds/symlink/sn74lv8154.pdf?ts=1595964924282&ref_url=https%253A%252F%252Fwww.google.com%252F
Because the puse counting is handled externally the AVR is free to run the motor control loops
--- End quote ---
why make a hairball of logic and all the issues that come with that when you can just pick one of the many MCUs can that easily do it all?
thm_w:
--- Quote from: Siwastaja on July 28, 2020, 05:00:11 pm ---IMHO, 500kHz encoder signal shouldn't be a problem for the 16MHz AVR hardware timer/counter module, that's the point. Have you tried it? Are you having a problem, and if yes, what kind?
So you don't need to process every pulse in software.
The counters count the pulses for you; you only add extra bits in overflow interrupts (500kHz/256 is manageable interrupt rate because the ISR is very short). Then you can do actual calculations at 1kHz, for example, looking at the counter values.
--- End quote ---
Maybe I'm missing something here, how are you counting the quadrature pulses using a plain timer/counter peripheral? If the motor is going forward or backward, the count will increase on both channels.
Normally you'd have dedicated logic to decode this: http://ww1.microchip.com/downloads/en/DeviceDoc/70063b.pdf
Navigation
[0] Message Index
[*] Previous page
Go to full version