0

I need to control the speed of my autonomous Arduino Uno robot, but I have been restricted. I can not use any MCU libraries such as analogWrite, any hardware devices or modules from the MCU (timers).

I have thought of just turning the motors off and on at very small intervals and putting that in a loop. But I am trying to find a more efficient and clean way of doing it. I need to be able to control the speed to 75%, 50%, and 25% of the normal speed, and turning the motors on and off, it gets complicated.

How do I control the speed of the motors in a more efficient way?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
criver.to
  • 520
  • 2
  • 9
  • 18
  • Why are you restricted? Those restrictions sound ridiculous. – David Grayson Oct 03 '12 at 04:43
  • Well, with the restrictions you mention, there aren't a lot of other options out there. Controlling the speed of motors the way you describe it makes the most sense. Are you allowed to use different kinds of motors, or is that a restriction also? If not, why not think about using stepper motors? I'm not real familiar with the hardware you are using, what sort of feedback can you expect from your motor position / angle / whatever? You should be able to get more precise control of your motor if you can make use of fb. – happy coder Dec 01 '12 at 17:58

1 Answers1

0

You said you have some very restrictive conditions:

I can not use any MCU libraries such as analogWrite, any hardware devices or modules from the MCU (timers).

Get a motor controller with a serial interface and whenever you want to change the speed, bit-bang a few serial bytes out to it. You just need to connect the Arduino's GND to the controller's GND, choose an Arduino pin to be the TX line, and connect that pin to the controller's RX line. Then use digitalWrite and delayMicroseconds to bit-bang some serial bytes.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • Don't use bit-banging. The AVRs used in the Arduino have proper builtin USART (serial-to-USB) hardware, one should absolutely use that. As a general rule of thumb, in case of embedded programming, as many things as possible should be done by the built-in hardware if possible, software emulation is more expensive and thus it is considered bad practice. –  Oct 03 '12 at 04:54
  • @H2CO3: Please read the original question where it says "I can not use any MCU libraries such as analogWrite, any hardware devices or modules from the MCU (timers)." So I would appreciate an upvote. – David Grayson Oct 03 '12 at 17:53