What's really the best way to control a motor with an Arduino or other microcontroller?

Status
Not open for further replies.

HR19

Member
So I've asked before about PWM to analog, but I've found some different options. Background...

I am planning a project where I will need to control up to 4 separate motors through 4 separate motor controllers. The typical throttle control is 0-5V hall effect sensor throttle (functionally like using a pot as a voltage divider). I intend to use an Arduino or similar such device to act as the throttle. I've asked about converting PWM to analog, and I've had suggestions such as low-pass filter or using a DAC. I found a breakout with at quad-DAC from Adafruit for only $7.50 with I2C interface so it would be very inexpensive to use that. But I just found two other ideas and I want to know what people who are either smarter than me or more experienced with electronics than me (or both) think.

I don't want to use a low-pass filter. I've read a lot about them but there's just too much variance for my taste. So the options I'm considering...there are PWM-to-analog breakouts available for fairly cheap, and this would require the least amount of coding. I take my input, set the PWM output on the pin I want, and the converter gives me the right output. The quad DAC would be a little cheaper, but it would require a bit more programming (although admittedly, not a whole lot). And the quad DAC would be a single device, whereas I'd need 4 of the PWM converters (presumably more energy efficient as well). The third option I'm considering is a digital pot. I'd still need 4 of these instead of the one DAC, but they're also available for quite cheap, wouldn't be much more expensive than the quad DAC, and would ultimately require about the same amount of coding and give me about the same precision (close enough for my purposes at least). The more I write this the more I think that the quad DAC is probably the best solution. It looks to be the simplest, easiest to implement, and cheapest, but the idea of using the 4x digital pots is still intriguing to me. What would you guys do in my situation?
 
As long as you're only wanting 0-5V signals, then a simple PWM and low pass filter is all you require - I've no idea what you mean by 'too much variance'?.

Bear in mind a motor is a crude analogue device, and is VERY slow, so it's not even like you have any need for speed.
 
With a low pass filter, there's potential delay and/or reduction in the signal, as well as it's a bit wavy peak-to-peak. I'd rather have a smoother output via one of the other options.
 
With a low pass filter, there's potential delay and/or reduction in the signal, as well as it's a bit wavy peak-to-peak. I'd rather have a smoother output via one of the other options.

If any of those things are true, then you're doing it completely wrongly - and I've already explained that speed isn't an issue as a motor is such a very slow device.

But pick any method you fancy, all will work equally well, as long as you implement them properly.

As for 'bit wavy peak-to-peak' - again, that's because you're doing it badly. The old analogue tuning systems used 33V p-p PWM for the varicap tuning, and even with 33V p-p there was no visible variation using a 1mV/cm scope on the tuning rail - they simply used a two stage passive RC filter.
 
I saw a number of videos on YouTube where people connected their oscilloscopes to show what happens to the signal. In all cases, the waviness was minimal, but present. Maybe I can get better results by combining an RC and an RL low-pass filter? But I don't want my motors to be jittery.

I understand that you believe motors are slow to respond, but I don't want to make it slower, and I don't want it to be jittery. The controller and motor I have seems quite fast to respond. Either I don't know what you mean by "slow" or "slow" is relative and I don't care to add to its "slowness."
 

With properly done PWM and correct low-pass filters there should be no jitter - but it wouldn't affect the motor in any way, so doesn't really matter.


'Slow' is relative - micro-controllers work in uS (or nS), motors works in tens or hundreds of mS - the difference is absolutely massive - motors are VERY, VERY slow.

You could alter the motor speed many times over using the micro, and the actual motor speed would never change at all because it takes so long for the motor to respond to the changes, regardless of how you control it.
 
The PMW frequency can in principle be anything from tens to thousands of times faster than the required motor response time.

eg. Use 10KHz or faster PWM cycle and a couple of 1 KHz low pass stages.
The 10KHz will be just about immeasurable and the motor system is unlikely to see anything above 100Hz or so anyway.

That is not by any means a "slow" response and does not have any detrimental effect on the end result.

If someone is trying to use eg. 100Hz PWM cycle and filter that, the it would give poor results, but it's a daft thing to do for anything where you want fast, clean, signal.

I don't use Arduinos, but if the built-in PWM routines do not allow high frequency settings, there are add-on libraries that do - eg. see this info:


Using the built-in PWM, programmed properly, should work fine.

The quad DAC board has the advantage of 12 bit resolution on all channels though, so finer control than PWM as is seems there are no more than two 16 bit PWMs and others 8 bit on arduinos.
 
Before we get to far along making recommendations, could you please share your requirements:

How well must your speed be controlled? What is your...
- Acceptable change in RPM over one minute,
- acceptable change in Angular velocity per revolution
- acceptable change in angular velocity per degree of rotation.

How much error did you measure when using PWM? How was it measured...
- change in RPM over several minutes of monitoring.
- change in angular velocity within a revolution.

And how quickly should your motor respond to a new input?
 
Arduino standard PWM is 490Hz. I'd need 4 outputs, so those high frequency libraries won't work as it would only give me two high frequency outputs, but that is a really cool suggestion, thank you. It looks like my only real options then are the DAC or the digital pot.
Um...these questions are beyond the scope of my knowledge. It's going to be a vehicle, not like some type of machinery, so it doesn't need to be super precise. I'd just like a decently fast response time.
 
All other electric vehicles use some form of pwm, why doesn't it work for you?
 
All other electric vehicles use some form of pwm, why doesn't it work for you?
EVs use PWM from the controller to the motor, not necessarily for the throttle. In my research the throttle is most commonly an analog signal, 0-5V, via hall effect sensor as a voltage divider, at least for e-bike and golf cart motor controllers.
 
EVs use PWM from the controller to the motor, not necessarily for the throttle. In my research the throttle is most commonly an analog signal, 0-5V, via hall effect sensor as a voltage divider, at least for e-bike and golf cart motor controllers.

I don't see the relevance? - the required signal for the motor is PWM (to give speed control), it makes no difference what the original signal was - it 'might' be an analogue voltage?, it depends where it comes from and how it was designed. It could just as easily be a digital signal, transferring a numeric speed value - or countless different alternatives.

A VERY long time ago (decades) the UK magazine ETI did designs for two PWM speed controls (ESC's) for controlling an electric motor from the output of a radio control receiver - the whole point of the article was to demonstrate different design techniques. One was down digitally, the other completely analogue, both offered similar performance,

But regardless, your original premise is wrong, but any of the suggestions you have made would work equally well - the 'best' one would be the one you design and implement the best. If the standard Arduino PWM is only 490Hz, then that's rather low (but still perfectly viable for motor control) - but there are numerous PIC devices that have multiple hardware PWM outputs, specifically designed for this type of application.
 
Lower frequency pwm can have better low speed torque. Use pins 5 or 6 for double frequency (980Hz) pwm on many arduino boards - nano boards for sure.
 
The relevance is that if a certain device (the motor controllers) is expecting an analog voltage but instead gets a PWM signal, it may not respond/function correctly, and this is exactly what happened when I connected a PWM output from my Arduino to my current motor and controller. The motor was jittery, constantly trying to start and stop.

My original premise is that if a device is designed to work based on 0-5V analog signal, it will probably work best that way, since that's how it was designed. How is that premise wrong?
 
The way I read this is that the OP wants to use the existing motor control circuit and emulate the throttle with an Arduino. Correct?

Mike.
 
The way I read this is that the OP wants to use the existing motor control circuit and emulate the throttle with an Arduino. Correct?

Mike.
Yes, that's right. Since the Arduino can't handle 20+ amps at 50+ volts, I'll have to use a dedicated controller (I guess I could build one with some MOSFETs and stuff with the Arduino, but...no, I'll just use the one I bought online).
 

Well this is the first time you've mentioned that's what you're trying to do - I presumed, like everyone else, you were using the PWM to directly feed an H bridge or similar - as is usual with an Arduino.

In which case your filtering from the PWM was incorrect, what were you using?.
 
Well this is the first time you've mentioned that's what you're trying to do - I presumed, like everyone else, you were using the PWM to directly feed an H bridge or similar - as is usual with an Arduino.

From my original post...

...The typical throttle control is 0-5V hall effect sensor throttle (functionally like using a pot as a voltage divider). I intend to use an Arduino or similar such device to act as the throttle...
So anyone who got the wrong implication missed one of the most crucial parts of my original post.

EDIT:
In which case your filtering from the PWM was incorrect, what were you using?.
I have not yet tried using a filtered PWM as a throttle control. After doing some research I didn't believe it would be the best option for my situation due to peak-to-peak variance, as well as settling time, especially since the PWM frequency is relatively low on an Arduino-type device.
 
I would send the Arduino out through a 1800 ohm resistor to the analog sensor. Then put a 33uF capacitor between the sensor input and ground. This will flatten your 490Hz PWM signal to less noise than one bit of ADC resolution so your sensor will not care whether the Arduino is controlling it ot you are manually controlling it.
The RC filter will get to your new throttle position in under 0.1seconds - which is faster than you can move your foot pedal.
 
Last edited:
I'll buy some caps and try it out and let you know.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…