-1
\$\begingroup\$

I am working with an STM32F0 running at 3.3 V. I'm trying to drive a motor controller with PWM from the microcontroller. The motor controller requires an analog input of between 0 - 5 V to control the duty cycle of the motor.

I have the output pin of the microcontroller (5 V tolerant) configured as open drain, high speed, and I am using a 220 ohm pullup resistor to 5V. PWM frequency is approximately 12 kHz.

When I measure the output at the microcontroller pin, I get 0.5 V when the pin has 0% duty cycle, and +- 2.9 V when the pin has 100% duty cycle.

If I use a 2k2 resistor, the problem gets worse and I get about 1.8 V at the output pin on 100% duty cycle. I also tried connecting the pin directly to 5 V, however when I do this, it does not get pulled low on 0% duty cycle, but sits at 5 V.

As far as I understand, this configuration should work correctly. Can anyone provide any suggestions as to why this is not working for me?

\$\endgroup\$
  • 1
    \$\begingroup\$ Not an answer; just info: You may have fried your pin (at least) when you hooked it up directly to 5V. When you tried to pull it low, you created a short through your microcontroller... \$\endgroup\$ – bitsmack Oct 14 '16 at 22:24
  • \$\begingroup\$ Yeah, the 5 V direct was a last resort. I tested it after that and it works as normal in push-pull and as it was working in open drain. Thanks for your comment. \$\endgroup\$ – makepeace Oct 14 '16 at 22:31
  • 1
    \$\begingroup\$ What is the input current to the pin of your "motor controller"? You need to specify what kind of motor controller you have. \$\endgroup\$ – Voltage Spike Oct 14 '16 at 23:03
  • \$\begingroup\$ You can always put an extra transistor between the micro pin and the motor controller pin as a buffer. For frequencies of 12kHz this would work well. \$\endgroup\$ – crowie Oct 15 '16 at 2:45
  • \$\begingroup\$ I've realised my issue. There was an LED connected to ground on the pin I was using. Fixed now. Thanks for your comments. \$\endgroup\$ – makepeace Oct 15 '16 at 13:05
2
\$\begingroup\$

Assuming your measurements are correct and assuming they are taken with the motor controller connected, it is behaving like a nonlinear input similar to a diode or diodes with a few hundred ohms in series, and heavily loading the PWM output. To confirm this, connect the motor controller input to 5V with only a resistor of 220R and 2.2K (nothing else at all, no micro at all) and measure the input voltage. If the voltages are the same as you state, then it is confirmed. Otherwise either the PWM is not what you think or something else is funny about the micro.

If this is so, you will need a low pass filter and buffer of some kind.

This is a plausible situation if it's a cheap motor controller that is mains powered, because good isolation is expensive.

\$\endgroup\$
  • \$\begingroup\$ I tried the above, and I got 1.8V. I then measured the 5 V ref of the motor controller (it is usually controlled my a potentiometer), and it was at 1.8V... Going to get a new controller as it seems this one is terrible. Thanks for your help. \$\endgroup\$ – makepeace Oct 15 '16 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.