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

From ROBOTC API Guide
Jump to: navigation, search
(What is PWM)
 
(12 intermediate revisions by 2 users not shown)
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|}}
  
[[Category:need to be finished]]
+
== What is PWM ==
 +
PWM works by turning a circuit on and off very rapidly succession. By adjusting the ratio of the time on and the time off, it is possible to adjust the brightness of an 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 (a cycle consists of a consecutive high and low period). If the Duty-Cycle is 100% then the output is continually high and the LED would be at full brightness. If the Duty-Cycle is 0%, the output is continually low so the LED would be kept off. If the duty cycle is set to a percentage in between, then the LED will reflect that in its brightness. For example, if the duty cycle is set to 50%, the output is on 50% of the time and off the other 50%. In this scenario, the LED would appear be at 50% of its full brightness (dimmed). To find the brightness level, divide the time high with the total cycle time (also known as the period of the wave form).
 +
[[image:PWM_Duty_Cycle_Graphic.png|thumb|c|center|700px|]]
 +
<br />
 +
 
 +
== 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 values between 1.0ms and 2.0ms (expected range for servos), you can change the position of the servo simply by changing the PWM signal. A  1.0ms high pulse moves the servo to one extreme, a 2.0ms pulse moves it to the opposite extreme, and 1.5ms pulse moves it to the center position.
 +
 
 +
== PWM on a Microcontroller ==
 +
Due to the high frequency that PWM operates at, generating a PWM signal strictly through the ATMega328 microprocessor would essentially prevent users from doing anything else with an Arduino. 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, digital pins 3, 5, 6, 9, 10, and 11 can be used for PWM. ROBOTC lists all the compatible pins under the 'Motor' tab of the Motor and Sensors Setup window and automatically configures hardware PWM for the user.

Latest revision as of 19:08, 10 October 2012

PWM
PWM
PWM


What is PWM

PWM works by turning a circuit on and off very rapidly succession. By adjusting the ratio of the time on and the time off, it is possible to adjust the brightness of an 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 (a cycle consists of a consecutive high and low period). If the Duty-Cycle is 100% then the output is continually high and the LED would be at full brightness. If the Duty-Cycle is 0%, the output is continually low so the LED would be kept off. If the duty cycle is set to a percentage in between, then the LED will reflect that in its brightness. For example, if the duty cycle is set to 50%, the output is on 50% of the time and off the other 50%. In this scenario, the LED would appear be at 50% of its full brightness (dimmed). To find the brightness level, divide the time high with the total cycle time (also known as the period of the wave form).

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 values between 1.0ms and 2.0ms (expected range for servos), you can change the position of the servo simply by changing the PWM signal. A 1.0ms high pulse moves the servo to one extreme, a 2.0ms pulse moves it to the opposite extreme, and 1.5ms pulse moves it to the center position.

PWM on a Microcontroller

Due to the high frequency that PWM operates at, generating a PWM signal strictly through the ATMega328 microprocessor would essentially prevent users from doing anything else with an Arduino. 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, digital pins 3, 5, 6, 9, 10, and 11 can be used for PWM. ROBOTC lists all the compatible pins under the 'Motor' tab of the Motor and Sensors Setup window and automatically configures hardware PWM for the user.