e Fig, a Switch is connected to PB1. Using CTC Mode and Prescaler-1024. Wris Pro
ID: 2266583 • Letter: E
Question
e Fig, a Switch is connected to PB1. Using CTC Mode and Prescaler-1024. Wris Program in which, If the switch is closed the Wave form generator create a 60 H2Z wa Otherwise, it XTAL- 8MHZ. (10 Points) generates a wave with frequency of 50 HZ. Assume the Mega32 SW1 PB1 (Oco) Trimer Clock-| / 8 MHz = 0.125 0.125 s * 1024 128 s Twave = 1/ 50 Hz = 0.02 s Toggle= 0.02 s / 2 = 0.01 s 10,000 10000 / 128-78125 OCR0 = 77 Twave = 1/ 60 Hz = 0.0 16 s Toggle= 0.016 s / 2-0.008 s = 8,000 8000 / 128 = 62.5 OCR0 = 61 Develop the Program in Here:Explanation / Answer
Answer:- The code can be written as-
#include "avr/io.h"
int main(void)
{
DDRB &= ~(1<<PB1); /* make PB1 as input pin */
DDRB |= (1<<PB3); /* make PB3 as output pin */
while(1)
{
if(PINB & (1<<PB1) == 1) /* check if switch is ON */
{
TCCR0 = 0b00001101; /* set CTC mode and prescaling of 1024 */
OCR0 = 61; /* set the output compare value for 60 Hz as computed above */
}
else
{
TCCR0 = 0b00001101; /* set CTC mode and prescaling of 1024 */
OCR0 = 77; /* set the output compare value for 50 Hz as computed above */
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.