[Video] ESP32 - Pulse Width Modulation

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

[Video] ESP32 - Pulse Width Modulation

Postby kolban » Mon Jan 30, 2017 11:54 pm

A You Tube video on the ESP32 and Pulse Width Modulation (PWM):

https://www.youtube.com/watch?v=rarE-WI_Y0A

Illustrates LED dimming and servo motor control.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

MrDuco
Posts: 2
Joined: Thu Mar 09, 2017 10:00 am

Re: [Video] ESP32 - Pulse Width Modulation

Postby MrDuco » Thu Mar 09, 2017 2:40 pm

Hi kolban, you are really doing a greate job with all your videos!!!

I wonder if you can help me in the right direction. I'm trying to control a servo, and have succeded to complie and run your servoSweep example.

But I cannot for the world figure out how to move the servo to a certain point, as you descibe in the video (and document)
I have tried to read all there is about PWM and changing values in your code, but no success. Can you give any tips or example how this could be accomplished.

Thanks

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: [Video] ESP32 - Pulse Width Modulation

Postby kolban » Thu Mar 09, 2017 3:06 pm

A servo is controlled by a PWM signal. Commonly they have a period of 20ms. That means that the signal repeats every 20ms. However, common servo encoding uses the first couple of ms to control the position. If we imagine a PWM signal as being broken into two parts ... the time that the signal is high and the time that the signal is low.

Commonly:

if the signal is high for 1 ms and low for 19 ms, then the servo turns 100% in one direction.
if the signal is high for 2 ms and low for 18 ms, then the servo turns 100% in the other direction.
if the signal is high for 1.5 ms and low for 18.5ms, then servo turns 50% of the direction.

... and so on ...

So algorithmically ... if the signal is high for 1 + n/180 then the servo turns n degrees (based on granularity of the servo device itself).
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

MrDuco
Posts: 2
Joined: Thu Mar 09, 2017 10:00 am

Re: [Video] ESP32 - Pulse Width Modulation

Postby MrDuco » Mon Mar 13, 2017 7:27 am

Thanks for the answer, I will try again and see if I succeed

Who is online

Users browsing this forum: No registered users and 28 guests