Difference between revisions of "Tutorials/Arduino Projects/Additional Info/PWM"

From ROBOTC API Guide
Jump to: navigation, search
(PWM as a signal)
Line 1: Line 1:
 
{{DISPLAYTITLE:PWM}}
 
{{DISPLAYTITLE:PWM}}
 +
<yambe:breadcrumb self="PWM">Arduino_Projects|Arduino Tutorials and Guided Projects</yambe:breadcrumb>
 
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/BoeBot/How_to_Dim_an_LED|How to dim LEDs using the Arduino (BoeBot)</yambe:breadcrumb>
 
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/BoeBot/How_to_Dim_an_LED|How to dim LEDs using the Arduino (BoeBot)</yambe:breadcrumb>
 +
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/BoeBot/Continuous_Rotation_Servo_Intro|What is a Continuous Rotation Servo? (BoeBot)</yambe:breadcrumb>
 
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/VEX/How_to_Dim_an_LED|How to dim LEDs using the Arduino (VEX)</yambe:breadcrumb>
 
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/VEX/How_to_Dim_an_LED|How to dim LEDs using the Arduino (VEX)</yambe:breadcrumb>
 +
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/VEX/Continuous_Rotation_Servo_Intro|What is a Continuous Rotation Servo? (VEC)</yambe:breadcrumb>
 
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/Lego/How_to_Dim_an_LED|How to dim LEDs using the Arduino (Lego)</yambe:breadcrumb>
 
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/Lego/How_to_Dim_an_LED|How to dim LEDs using the Arduino (Lego)</yambe:breadcrumb>
 
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/Tetrix/How_to_Dim_an_LED|How to dim LEDs using the Arduino (Tetrix)</yambe:breadcrumb>
 
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/Tetrix/How_to_Dim_an_LED|How to dim LEDs using the Arduino (Tetrix)</yambe:breadcrumb>
<yambe:breadcrumb self="PWM">Arduino_Projects|Arduino Tutorials and Guided Projects</yambe:breadcrumb>
+
<yambe:breadcrumb self="PWM">Tutorials/Arduino_Projects/Mobile_Robotics/Tetrix/Continuous_Rotation_Servo_Intro|What is a Continuous Rotation Servo? (Tetrix)</yambe:breadcrumb>
 +
 
 
{{tl|1|}}
 
{{tl|1|}}
  

Revision as of 18:36, 8 August 2012

PWM
PWM
PWM


What is PWM

PWM works by turning the circuit on and off very rapidly. By adjusting the ratio of the time on and the time off, it is possible to adjust the brightness of the LED. This ratio is called the Duty-Cycle and is the percentage of time the output is high with respect to the time of one cycle (when the output goes high then low then back to high). If the Duty-Cycle is 100% then the output is high all the time and thus the LED would be a full brightness. If the Duty-Cycle is 0%, the output is off all the time, so the LED would just be off. Now if the Duty-Cycle is set to 50%, the output is on 50% of the time and off the other 50%. In this setup, the LED would appear be at 50% of its full brightness, an thus appears to be dimmed. This works by basically averaging the time on with the time off.

PWM Duty Cycle Graphic.png


PWM as a signal

Since PWM have set periods, it is possible to change the Duty-Cycle to transmit data. This is a common practice for controlling servo motors. By setting the Duty-Cycle to some value between an expected range of values, it is possible to map the value of the Duty-Cycle in the range, to another range of values that you will actually use. For instance with servos, the PWM signal is between 1.0ms and 2.0ms, but the servo maps these values to between -100% and 100%.

PWM on a Microcontroller

Due to the high frequency that PWM operates at, to get an accurate signal using code would basically prevent you from doing anything else with the chip. To eliminate this problem, chip manufacturers included hardware to generate the PWM signal. However not every I/O pin supports PWM output. For the Arduino UNO, only digital pins 3, 5, 6, 9, 10, and 11, support it. Luckily, ROBOTC has a tab in the Motors and Sensors Setup window that lists the pins that can be used. ROBOTC also handles all of the complex options that need to be set for the hardware PWM to work.