6
http://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/ technology workshop living food play outside Arduino RC Circuit: PWM to analog DC by DavidW10 on September 28, 2014 Table of Contents Arduino RC Circuit: PWM to analog DC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Intro: Arduino RC Circuit: PWM to analog DC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 1: Pulse width modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 2: RC Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Step 3: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 4: Ripple and time of response to change in voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 5: Frequency Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Step 6: Arduino RC circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Step 7: Scope: no voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Step 8: Scope: 50% signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Step 9: Scope: full power, 5 volts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Step 10: Scope: a closer look at the RC output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Arduino RC Circuit PWM to Analog DC

Embed Size (px)

DESCRIPTION

Arduino RC Circuit PWM to Analog DC

Citation preview

  • http://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/

    technology workshop living food play outside

    Arduino RC Circuit: PWM to analog DCby DavidW10 on September 28, 2014

    Table of Contents

    Arduino RC Circuit: PWM to analog DC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    Intro: Arduino RC Circuit: PWM to analog DC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    Step 1: Pulse width modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    Step 2: RC Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

    Step 3: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Step 4: Ripple and time of response to change in voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Step 5: Frequency Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    Step 6: Arduino RC circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Step 7: Scope: no voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    Step 8: Scope: 50% signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Step 9: Scope: full power, 5 volts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

    Step 10: Scope: a closer look at the RC output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

  • http://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/

    Intro: Arduino RC Circuit: PWM to analog DCArduino is a platform that can be used to develop interactive objects. For this project we will use the the Arduino Mega 2560. It has 54 digital input/output pins, of which15 can be used as pulse width modulation (PWM) outputs.PWM allows the strength of the output to be varied. For example, to change the brightness of an LED. In this Instructable, an RC filter will be used to flatten the PWMsignal. As we will see, the RC filter has some limitations due to a certain amount of residual "waviness" in the RC output.

    Step 1: Pulse width modulationPWM signals are rectangular waves, varying from zero to +5 V, with a frequency near 500 Hz. If the signal is high for 50% of the time, the voltage delivered will be 2.5 V.

    But for some uses, it is preferable to have a flat analog DC signal at 2.5 volts, rather than a digital stream of square waves with a 50% duty cycle. One method to flattenthe PWM is to use an RC (resistor/capacitor) filter.

    Step 2: RC FilterThe RC filter is a simple circuit element used to convert a pulsed signal to a flatter signal. The key concept is that the capacitor shunts the varying voltage to ground,producing a DC voltage.

  • http://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/

    Step 3: The RC filter has two values that determine how it will modulate the incoming PWM signal: R, the resistance in Ohms, and C, the capacitance in Farads. There are manytools online for exploring RC circuits. One that is useful is http://sim.okawa-denshi.jp/en/CRtool.php, from Okawa electronic design and manufacturing in Japan.For the purposes of this project, I entered the values of 1 kohm for the resistor and 100 uF for the capacitor.The RC analysis tool produces some key insights:

    1) The cut-off frequency2) The ripple3) The settling time.

    Step 4: Ripple and time of response to change in voltageThis image shows two things: the ripple in the RC output (the "waviness" of the line, which is small for these R and C values) and the response time. Note that theresponse is mostly complete by 0.2 seconds, which means that a change in voltage will result in a change in brightness in the LED in much less than a one second. Youcan put your own numbers in the RC calculator here: http://sim.okawa-denshi.jp/en/CRlowkeisan.htm.

    Step 5: Frequency AnalysisThe efficiency with which the RC filter blocks PWM signals depends on the frquency of the signal. For this RC filter (1 kohm/100uF), the top graph shows that the signal isreduced by 40 decibels* at 500 Hz.

    *0.0001 power ratio; http://en.wikipedia.org/wiki/Decibel

  • http://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/

    Image Notes1. 500 Hz, reduced 40 db (about 0,001, http://en.wikipedia.org/wiki/Decibel)2. undefined3. undefined

    Step 6: Arduino RC circuitThe Arduino board produces a PWM signal from digital pin 10. The PWM signal passes through R1 and the capacitor (the RC components). The output from the RC filterpasses through the second resistor (used to limit current to LED). The current flows through the LED to ground.The signals before and after the RC filter can be seen by placing oscilloscope probes at the points indicated in the diagram.

    This picture was made using Fritzing.

    Example code to control the Arduino board and vary the PWM can be found on the Arduino website: http://arduino.cc/en/tutorial/fading. Change the digital input from pin9 to pin 10.

    Step 7: Scope: no voltageThe scope shows two traces: the PWM input and the RC filter output. Here both are at baseline, 0 V.

  • http://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/

    Step 8: Scope: 50% signalThe Arduino digital pin 10 is sending a PWM signal with 50% duty cycle (half time high, half time low). This is the rectangular wave.The RC output is the blue flat line. Note the scale is set at 2 volts. Each horizontal line represents an increment of 2 volts. The PWM varies from 0 to 5 volts, whereas theRC output is steady near 2.5 volts.

    Step 9: Scope: full power, 5 voltsAt full power of 5 volts, both the input and RC output are steady "on" at 5 V.

  • http://www.instructables.com/id/Arduino-RC-Circuit-PWM-to-analog-DC/

    Step 10: Scope: a closer look at the RC outputThe scale was changed from 2 V to 0.2 V to zoom in on the RC output, Note the waviness of the blue line above the square wave - this is the RC output.

    The values of R and C can be increased to further flatten the line, but then the response time increases. If the RC value (the product of the R and C values) is too high,there will be a noticeable lag in the change of the brightness of the LED as the voltage is changed. The values that produce the best compromise between response timeand less ripple depend on the design goals.

    Bottom line, the RC filter is not the answer if you need a clean DC signal. Alternatives: add second RC filter, digital-to-analog converter, digital potentiometer.

    Related Instructables

    control arduinousing joystickbybigbodysmallbrain

    How to usePulse-WidthModulation byJColvin91

    QuickStart - onetransistor DCmotor controller(Photos) bycavelamb

    Using PWM tocontrol the lightintensity of aLED byhimshekhar.das

    PWM VariableSpeed DiscoBall (video) bybennelson

    Fun With PICAssembly -Episode 3 byboomer48

    Advertisements

    Comments3 comments Add Comment

    ibenkos says: Oct 18, 2014. 12:01 PM REPLYSmart idea! Thanks for shearig :)

    BrittonG says: Oct 6, 2014. 2:27 PM REPLYcan someone explain why we need both the 5v and the output pin 10? I was under the impression that the 5v pin was an *input* and was used to be able topower the arduino externally? TIA

    seamster says: Sep 29, 2014. 1:14 PM REPLYInteresting! Thanks for sharing this.