I'm following this tutorial to generate square waves using the timers of the attiny85, but I'm afraid this could mess with something else in the chip.

This is the relevant snippet:

// Set up Timer/Counter0 for 20kHz interrupt to output samples.
TCCR0A = 3<<WGM00;             // Fast PWM
TCCR0B = 1<<WGM02 | 2<<CS00;   // 1/8 prescale
TIMSK = 1<<OCIE0A;             // Enable compare match, disable overflow
OCR0A = 49;                    // Divide by 400

I understand that this might affect delay(), but as I'm using watchdog timer to send the attiny to sleep, I think this in this case it should not affect this specific function.

Are there another negative consequences of modifying this timer?

  • so, what is your question? ... the easiest thing would be to write a program that tests timer0 affect on sleep() – jsotola Jul 13 '20 at 16:09
  • 3
    Timer 0 is usually used for millis() and delay(). – Majenko Jul 13 '20 at 16:15
  • 1
    I don't see how this could affect sleep. It does affect millis and delay, if you are using a "core" that implement that for the ATTiny85. I think most of them use the overflow interrupt (e.g ATTinyCore does). Your code disables that, so as long as you never call delay() or millis() there shouldn't be a problem. – Gerben Jul 13 '20 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.