Pwm En Arduino

Páginas: 6 (1308 palabras) Publicado: 9 de noviembre de 2012
EAS 199 Fall 2011
v: November 14, 2011

Basic Pulse Width Modulation Gerald Recktenwald
gerry@me.pdx.edu

1

Basic PWM Properties

Pulse Width Modulation or PWM is a technique for supplying electrical power to a load that has a relatively slow response. The supply signal consists of a train of voltages pulses such that the width of individual pulses controls the effective voltage levelto the load. Both AC and DC signals can be simulated with PWM. In these notes we will describe the use of PWM on an Arduino for controlling LEDs and DC motors. The PWM pulse train acts like a DC signal when devices that receive the signal have an electromechanical response time that is slower than the frequency of the pulses. For a DC motor, the energy storage in the motor windings effectivelysmooths out the energy bursts delivered by the input pulses so that the motor experiences a lesser or greater electrical power input depending on the widths of the pulses. For an LED, using PWM causes the light to be turned on and off at frequency than our eyes can detect. We simply perceive the light as brighter or dimmer depending on the widths of the pulses in the PWM output. Figure 1 shows a voltagesignal comprised of pulses of duration τo that repeat every τc units of time. The output of a PWM channel is either Vs volts during the pulse or zero volts otherwise. If this signal is supplied as input to a device that has a response time much larger than τc , the device will experience the signal as an approximately DC input with an effective voltage of Veff = Vs τo τc (1)

The ratio τo /τc iscalled the duty cycle of the square wave pulses. The effective DC voltage supplied to the load is controlled by adjusting the duty cycle.

2

Using PWM on an Arduino

An Arduino Uno has 14 digital input/output (I/O) pins1 . Conventional, i.e., not PWM, operation of the digital I/O pins is controlled with the pinMode, digitalRead and digitalWrite functions. The pinMode function is used toconfigure a pin as an input or output. When a digital I/O pin is configured as an input, digitalRead reads the state of the pin, which will be either HIGH or LOW. In an Arduino sketch, HIGH is a predefined constant that is evaluated as “true” in a conditional
1 http://arduino.cc/en/Main/ArduinoBoardUno

τo Vs τc
Figure 1: Nomenclature for definition of PWM duty cycle.

...

EAS 199 :: Basic PWMOutput
int PWM_out_pin = 9; // Must be one of 3, 5, 6, 9, 10, or 11 // for Arduino Uno void setup() { pinMode(PWM_out_pin, OUTPUT); } void loop() { byte PWM_out_level; PWM_out_level = ... // Code logic to set output level

2

analogWrite( PWM_out_pin, PWM_out_level); }

Listing 1: Skeleton of an Arduino sketch to demonstrate the use of pinMode and analogWrite in controlling PWM output.expression, and is equivalent to a numerical value of 1. Electrically, a value of HIGH means the pin voltage is close to 5 V. Similarly, the constant LOW is interpreted as “false” in conditional expressions, it is numerically equivalent to 0, and electrically the pin voltage is 0. When a digital I/O pin is configured for output, digitalWrite is used to set the pin voltage to HIGH or LOW. On an ArduinoUno, PWM output is possible on digital I/O pins 3, 5, 6, 9, 10 and 11. On these pins the analogWrite function is used to set the duty cycle of a PWM pulse train that operates at approximately 500 Hz2 . Thus, with a frequency fc = 500 Hz, the period is τc = 1/fc ∼ 2 ms. As with conventional digital I/O, the pinMode function must be called first to configure the digital pin for output. The skeleton of asketch in Listing 1 shows the basic code components for using PWM on an Arduino. Two integer variables, PWM_out_pin and PWM_out_level are used to indicate the pin number and output level respectively. In the setup function, the statement
pinMode(PWM_out_pin, OUTPUT);

configures the PWM_out_pin for output. The OUTPUT symbol is a constant defined by the Arduino programming tools (the IDE or...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • PWM
  • Pwm
  • que es pwm
  • arduino
  • Arduino
  • Que es arduino
  • Arduinos
  • ARDUINO

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS