I’m using an ATTINY85 to generate a PWM output (using TIM0 in OCR mode), and this PWM output is being switched on and off an regular intervals. What I am finding is that when switching on the PWM output, there is a delay before it actually starts outputting. Look at the screenshot below, the green line shows the state I am putting the PWM into (either on or off via TCCR1) and yet there is a delay of what looks like one full cycle before it starts. I’ve tried also resetting TCNT0 to 0 but this had no effect.
(timebase is 20us)
SET(DDRB, PB1);
SET(DDRB, PB2);
// setup PWM for 460khz w/ 8mhz clock
TCCR1 = (1<<PWM1A) | (1<<COM1A1) | (1<<COM1A0) | (1<<CS10); // prescaler = none;
GTCCR = (1<<FOC1A);
OCR1A = 9; // 460.750khz
OCR1C = 18;
#define BIT_DELAY ((1000000/38400))
while(1) {
SET(TCCR1, PWM1A);
SET(PORTB, PB2);
_delay_us(BIT_DELAY);
CLR(TCCR1, PWM1A);
CLR(PORTB, PB2);
_delay_us(BIT_DELAY);
}
