Hi everyone!
When I use this code the PWM seems to hover around 2.25 volts. I wanted to use this code to Pulse an IR LED but there is an issue. During the Time the PWM is turned off with the CS00 Prescaler, It seems to work sometimes then other times spike the voltage to the full load of around 5V.
Anyone experience this before?
This below works, Why is adjusting the prescaler keeping the Pin on High, Is it a timing isssue as PWM is being generated?
UPDATE:
When I use this code the PWM seems to hover around 2.25 volts. I wanted to use this code to Pulse an IR LED but there is an issue. During the Time the PWM is turned off with the CS00 Prescaler, It seems to work sometimes then other times spike the voltage to the full load of around 5V.
Anyone experience this before?
Code:
int main(void)
{
DDRB |= (1<<PB0); //Set pin PB0 as output
TCNT0 = 0;
TCCR0A=0;
TCCR0B=0;
TCCR0A |=(1<<COM0A0); //Timer0 in toggle mode Table 11-2
TCCR0A |=(1<<WGM01); //Start timer 1 in CTC mode Table 11.5
TCCR0B |= (1 << CS00);// Prescaler table 11.6
OCR0A=104; //CTC Compare value
while(1)
{
TCCR0B |= (1 << CS00);// Prescaler table 11.6
_delay_ms(5000);
TCCR0B &= ~(1 << CS00);// Prescaler table 11.6
_delay_ms(5000);
}
}
UPDATE:
Code:
while(1)
{
DDRB |= (1<<PB0); //Set pin PB0 as output
//TCCR0B |= (1 << CS00);// Prescaler table 11.6
_delay_ms(2000);
//TCCR0B &= ~(1 << CS00);// Prescaler table 11.6
DDRB &= ~(1<<PB0); //Set pin PB0 as output
_delay_ms(3000);
}
Last edited: