I'm using Timer1 to generate a 25KHz PWM signal on a Digispark ATtiny85 board, which works fine with the setup code. However, after that starts, nothing else in my code seems to run. I tried to blink the on-board LED in the loop and it never did. I even tried to just write the LED high, suspecting delay() depends on Timer1, and that never even ran! Are you just not supposed to use Timer1 at all for your application?
Here is my code. It generates a 25KHz PWM signal with 50% duty cycle, but does not turn on the on-board LED. Commenting out the register initialization makes the LED turn on fine, and it blinks fine if I uncomment the rest of the loop code.
#define LED_PIN 4
#define PCB_LED 1
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(PCB_LED, OUTPUT);
pinMode(LED_PIN, OUTPUT);
//Below registers generates 25KHz PWM on pin 4 (PB4) using Timer1
GTCCR = _BV(PWM1B) | _BV(COM1B1);
OCR1B = 19; //Start out duty cycle 50%
OCR1C = 39; //1MHz / (39+1) = 25KHz
TCCR1 = 0x01;
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(PCB_LED, HIGH);
// delay(1000);
// digitalWrite(PCB_LED, LOW);
// delay(1000);
}