Question
Timers and PWM. For this problem assume a CPU frequency of 19MHz. a). Give the C code to configure the registers (e.g. TCCR0A, etc.) to
Timers and PWM. For this problem assume a CPU frequency of 19MHz.
a). Give the C code to configure the registers (e.g. TCCR0A, etc.) to set the 8-bit Timer0 in Fast PWM mode with a frequency as close to 500Hz as possible. Comment each line of code to indicate how you are configuring it. Remember to assume a 18MHz clock frequency. Hint: You should try all of the possible clock prescalers to determine which gives you the best value.
b) What is the actual frequency that the timer will run at?
c) How would you configure it to approximately a 30% duty cycle (on 30% of the time)? Give the C code setting the Atmel registers to do this (make sure to set OCR0B).
d) If you used Timer1 instead, could you get closer to an actual frequency of 500Hz? Configure the registers for Timer1 for 500Hz and make sure to show and comment your code. What is the actual frequency you achieve with your configuration?
e) Describe the differences between Fast PWM and Phase Correct PWM mode and why you may want to use Phase Correct PWM in some circumstances. You may want to include a picture of the signals to help with your description.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started