Andy_P
Newbie level 2
AVR STUDIO4 and PWM
I am trying to simulate PWM on AVRSTUDIO 4, using the timer0 of ATMEGA8535.
All works except the setting or clearing of pin OC0 which is PB3 in this case.
this is the relevant part of the program:
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x08;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER0 initialize - prescale:8
// WGM: PWM Phase correct
// desired value: 1mSec
// actual value: 1,020mSec (-2,0%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x01; //set count
OCR0 = 0x80; //set compare
TCCR0 = 0x62; //start timer
}
Anyone experience in this field?
I am trying to simulate PWM on AVRSTUDIO 4, using the timer0 of ATMEGA8535.
All works except the setting or clearing of pin OC0 which is PB3 in this case.
this is the relevant part of the program:
void port_init(void)
{
PORTA = 0x00;
DDRA = 0x00;
PORTB = 0x00;
DDRB = 0x08;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}
//TIMER0 initialize - prescale:8
// WGM: PWM Phase correct
// desired value: 1mSec
// actual value: 1,020mSec (-2,0%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
TCNT0 = 0x01; //set count
OCR0 = 0x80; //set compare
TCCR0 = 0x62; //start timer
}
Anyone experience in this field?