[Newbie question] Voltage, Arduino PWM vs LED PWM vs MCPWM vs BPWM

Posts: 2
Joined: Sat Aug 12, 2017 4:37 pm

[Newbie question] Voltage, Arduino PWM vs LED PWM vs MCPWM vs BPWM

Postby iblanco » Sat Aug 12, 2017 4:58 pm

Hi everyone,

I'm a newbie not just with ESP32 but also with electronics in general so please be patient and sorry for the probably stupid question.

I've been playing with controlling a DC motor with my Arduino. I used an L293D chip, i controlled direction with 2 digital outputs from the arduino and 1 pwm output connected to the enable of the L293D. By changing the PWM signal in the arduino I control the speed of the motor.

Now I'm waiting for my ESP32 Dev kit board to arrive and meanwhile I'm ready a little bit about ESP32 and ESP-IDF.

I'm a bit confused about how I could achieve the same with the ESP32. Well, in fact I want to use an L298N circuit instead of the L293D but as far as i understand they work in a similar way.

My first question is about voltage. If I did understand right PWM works by upping and lowering the signal in the output pin in a very fast and precise way, so that the final result is that instead of getting and average of 5 volts in the output it might look like 4 volts, 3 volts or whatever. The driver checks this voltage and depending on it sends "more power" to the DC motor? Or maybe it justs turns it on an of in the same rate as the PWM signal?

If I did understand right the GPIO pins in the Devkit board work at 3.3volts so that this mean that the driver will move the motor more slowly ? Or am I mislead and the only thing that matters is the frequency of the signal?

Apart from that. What is the difference between the PWM in an arduino GPIO pin and the ones in the ESP32? I've read that there are 2 kinds of PWM in the ESP32 the so called LED PWM and the MCPWM.

By the name it seems that I should use the Motor Control PWM but looking at the example code I see that I have to configure 2 pins for the PWM unit, not just one as I would expect. Sadly the examples do not show any schematichs or wiring diagrams so I'm not sure how I'm supposed to hook those 2 pins to the L298N. Can I just attach one of those two pins of the controller to the enable pin of the L298N and manage the directions pin with two regular digital pins? Is the second pin useless in my case?


Posts: 155
Joined: Thu Dec 08, 2016 2:53 pm

Re: [Newbie question] Voltage, Arduino PWM vs LED PWM vs MCPWM vs BPWM

Postby f.h-f.s. » Sun Aug 13, 2017 1:38 pm

You have to supply the l293n with 5v(4.5~7v) to power it.

VSS | Logic Supply Voltage (pin 9) | 4.5 | 5 | 7V

Quoted from https://www.sparkfun.com/datasheets/Robotics/L298_H_Bridge.pdf page 3

The chip can trigger on 3.3v logic. (if you set a logic pin to 3.3v it will see it as a 1)
See: input Low Voltage(pins 5, 7, 10, 12), Input High Voltage(pins 5, 7, 10, 12), Enable Low Voltage (pins 6, 11), Enable High Voltage (pins 6, 11)
on page 3 of that datasheet.

So you can use this chip IF you have a 5v supply.

My guess is you want to PWM the enable line of the l293n and set input1 and input2 as the direction, with output1 and output2 connected to the motor?
You would connect a normal GPIO to input1 and input 2 to set the direction.
input1 on the l293n connected to GPIO1 which is set to HIGH(1) and input2 on the l293n connected to GPIO2 set to LOW(0) for clockwise
(input1 -> GPIO1 set to LOW and input2 = GPIO2 set to HIGH for counterclockwise)

Then you would have your l293n enable pin connected to a pwm source from the esp32. That would need to be a single pin indeed and i think I would use the LED PWM module.

If you had a 2-Pole Permanent Magnet Motor (read http://www.electronics-tutorials.ws/blog/pulse-width-modulation.html) you would use MCPWM to alternate the two poles and make the motor move.

(Just so you know, I haven't done any work with the l293n and or motor control with the esp32. This is my best guess =P)

Posts: 2
Joined: Sat Aug 12, 2017 4:37 pm

Re: [Newbie question] Voltage, Arduino PWM vs LED PWM vs MCPWM vs BPWM

Postby iblanco » Tue Aug 15, 2017 11:39 am

Thanks a lot.

I've been testing the L298n breakout with 3.3v for the directions pins and an external 7,5volts battery for the motors power and yes, it seems to work as you suggested. I then tried doing the same with a 5v and of course it did work too. And I didn't notice any speed difference, I even measured the voltage in the output for the motor connection and didn't notice much difference when using the 3.3v vs 5 volts, maybe 0,2 volts but not much.

But I don't have yet a way to generate a PWM pulse in 3.3volts (I expect the ESP32 dev kit board to arrive tomorrow) so i have done the tests by letting the enable pins jumper on. I would expect this pin to be powered from the logic's power supply, no the battery, in that case my test suggests that a PWM enable signal of 3.3v might be enough to drive the motor at nearly full speed. But if I'm wrong and the jumper connects to some kind of regulated 5volts my tests might just be wrong. I also might not be considering the limitations of the motor I'm using for test, it is a very small DC motor that came with and eleego kit so maybe I'm just overpowering it and this is the reason for it to work at full speed despite of having a smaller PWM signal.

Just in case, I've bought some bi-directional level shifters. They'll come handy when trying to connect sensors so they won't be wasted money in any case.

Once more thanks for your help.

Who is online

Users browsing this forum: No registered users and 6 guests