Introduction To Pulse Width Modulation (PWM)
Introduction To Pulse Width Modulation (PWM)
10/24/2016 2
What is PWM?
1
Duty cycle = 20%
on off
0.2
Width
period
Maximum
voltage
100 %
75 %
50 %
50 % =
0
t t
Analog Digital
control control
10/24/2016 6
Usage of PWM
Motor Control
Intensity of LED
10/24/2016 7
How to generate PWM signal?
Software method
o Using counter
• Count to 100 in a loop
• Set the output value to 1 in the beginning of the loop
• Set the output value to 0 as soon as the counter
reaches the value of required duty cycle.
• Continue the process
o Using interrupt
• Home work
• Think about the concept
10/24/2016 8
Your tasks
Create projects in a usual way using provided
SOPCINFO file.
Type the code in your application project.
Change duty cycle variable and observe the
effect on oscilloscope or LED.
Using oscilloscope, verify the duty cycle.
o Is it precise?
o Is it efficient?
10/24/2016 9
Software PWM
Output pin:
o GPIO_0[0] ==> find this pin in the user manual
o Using the manual find out the correct pin and
observe the resulting PWM on the oscilloscope
o In C program, use the following instructions to
change the output
• IOWR(PIO_0_BASE, 0, 0); // set output 0
• IOWR(PIO_0_BASE, 0, 1); // set output 1
Control LED (optional):
o Apply the PWM signal to LED, observe the intensity
10/24/2016 10
Questions
10/24/2016 11
Hardware PWM IP
PWM NIOS core JTAG Uart
Blaster
USB
RAM
Your PC
Programmable/configurable
Precise
10/24/2016 12
Hardware PWM IP
Follow the simple use sequence
o Enable
o Configure
o Modify
o Disable
Only one function for controlling two PWM signals
motor_setting(phase1, duty1,
phase2, duty2,
period, enable);
10/24/2016 13
Hardware PWM IP
motor_setting(phase1, duty1,
phase2, duty2,
period, enable);
Enable mask= 1
Common Disable = 0
period
10/24/2016 14
Questions
10/24/2016 15