Digital to Analog Converter using PWM

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi this will be a short tutorial on digital to analog conversion using pulse width modulation digital to analog conversion is needed to generate other voltages than your usual low and high values from your transistor logic CPUs and microcontrollers usually can just output low and high values on their pins but they can be used to generate analog voltage this arduino bot is running on 5 volts transistor logic but i'm still able to generate 1 volt output as you can see if you don't know how pulse width modulation is working here is a short introduction your pwm is working on a certain period here it is 5 milliseconds and during this period you set your pin to high for a certain time here it's 1 millisecond and then to low for the rest of the period the ratio between the active time and the period length is called duty cycle in this example it's 1/5 that's 20% and this duty cycle determines the average voltage that we get since our high value is 5 volts we get average of 1 volt output let's check how this looks on the oscilloscope the settings are 5 volts per division vertical and 1 millisecond per division in horizontal direction the voltmeter did show 1 volt but this was an average value since it's much slower than the oscilloscope quite often we need a more smooth signal than this to smoothen this rectangular signal we can use a low pass filter you sent a signal through a resistor to limit the current and smoothen the curve using a capacitor I'm using 10 kilo ohms and 10 microfarads here you can calculate these values using some complicated formulas or just try out and take what's working for you the voltmeter is still showing 1 volt output and the oscilloscope is also showing a nice flat 1 volt output using Arduino you can generate PWM on some dedicated ports using analog right but I'm using here a soft WM which works on any port the only thing that you have to manage there is to get the timing right so let's generate three volts to light up an LED we just set the output pin high for three milliseconds and low for two milliseconds the Arduino code around the loop prolongs the low phase a bit but 295 is close enough the LED doesn't light up the problem is obvious our low pass filter limits the current by 10k ohms it's not enough current to light up the LEDs so the voltage drops to one point seven two volts that's a trade-off when we are using the low pass filter so let's add an amplifier as a voltage follower to get the current that we need to light up the led now it's working let's verify the voltage output of the amplifier excellent let's change the duty cycle to generate 2 volts and dim the LED a bit there is one problem of the pulse width modulation it's working with time in our example we used milliseconds and our resolution were 5 milliseconds that's not very high we could just generate 5 voltage levels to get a higher precision we have to count a bit more for an 8 bit resolution we need 256 time units and this time unit can just be as low as one cycle of our processing unit since we have to be able to count compare and change the level any time if we want 8 bit precision at 16 megahertz we can just generate 62 kilo samples per second 16 bit precision for quality sound is not possible with PWM but I will show you how to generate a better resolution using a resistor ladder next time if you think that this circuit is too complicated to just demand LED then you are completely right we could just connect this directly to the PWM but this was just an example because of persistence of vision the LED looks steady on but it's just blinking very fast for example the resolution of hearing is 1000 times more precise that's why we might need an higher precision for sound so let's get to their conclusion there are certainly some advantages you just need one pin and very few components this could guarantee a small form-factor and cheap production cost another advantage is PWM is implemented by hardware in the most microcontrollers are probably just on few pins one advantage is it's just sufficient for the most purposes the disadvantages are you have to decide if you want high frequency or high precision both at the same time are not possible if you implement this by software you need a precise timing there one big disadvantage is that you generate noise when you are not using a low pass but probably are losing precision when you do thank you for watching and see you next time
Info
Channel: bitluni
Views: 113,529
Rating: undefined out of 5
Keywords: Pulse-width Modulation, Digital-to-analog Converter, Arduino (Computing Platform), Electronic, Sound, dimming, Light-emitting Diode (Invention), oscilloscope, analog, voltage, low pass filter, persistance of vision
Id: oU-WQVaHm4g
Channel Id: undefined
Length: 5min 36sec (336 seconds)
Published: Tue Jan 14 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.