Pulse Width Modulation
Pulse Width Modulation
Modulation
2
Pulse Width Modulation
A technique for getting an analog like output by means
of digital
Toggles a digital output fast enough, making any
attached device to react not to the individual pulses, but
to the % of time that the output is high in one cycle
How fast?
3
Duty Cycle
Percentage of time that output is high in one cycle
4
Average Voltage
5
PWM
Using 8-bit Timer
6
Waveform Generation
7
PWM Frequency
In Non-Inverted mode, while
Timer counts, if a compare match
occurs, Waveform Generator
clears OCnX pin and sets it when
Timer comes to Bottom
Waveform Generator generates a
one PWM cycle
8
Timer / Counter Registers
TCCRnB (Timer/Counter Control Register n B)
9
Timer / Counter Registers
TCCRnA (Timer/Counter Control Register n A)
10
Timer / Counter Registers
TCCRnA (Timer/Counter Control Register n A)
11
Timer / Counter Registers
OCRnA (Output Compare Register n A) and OCRnB
hold values to be compared against TCNTn register
If 8-bit, can hold a value between 0 and 28 – 1
If 16-bit, can hold a value between 0 and 216 – 1
12
Timer / Counter Registers
TIFRn (Timer Interrupt Flag Register n)
13
Timer / Counter Registers
TIMSKn (Timer Interrupt MaSK Register n)
14
System 15
fader - Gradually fades the light of an
LED again and again
15
ATmega328P PWM Pinout
16
Hardware
Schematic
Diagram
17
Hardware
Wiring Diagram
18
Firmware
Algorithm
19
C Program
20
Using Hexadecimal Constants
21
Using Labeled Constants
22
Firmware
Algorithm for Arduino
23
Firmware
Source Code (using Arduino Wrapper Functions)
24
True Analog Output
Three options
Switch to a microcontroller
with built-in DAC
Add a DAC breakout
Use a RC filter
25
Questions
26