What timers and ressources use Analogwrite

Hi
I have implemented a quarter second clock using the 16 bits timer 1and I want to add tone melody routine using analogwrite but with timer 2 or 0
What resources use the analogwrite and delay functions?
Is there a way to tell them not to modify my timer 1, output compare interruption 1A so it doesn’t interfere with my existing code
Thanks

What resources use the analogwrite and delay functions?

The UNO has three timers, and 6 PWM pins. One timer controls PWM on two pins. The datasheet tells you which pins go with which timer.

delay() doesn't use resources. It relies on millis() ticking regularly.

Is there a way to tell them not to modify my timer 1, output compare interruption 1A so it doesn't interfere with my existing code

No. You need to use a timer that is not being used for other purposes(, or not use those other purposes).

blotfib:
What resources use the analogwrite and delay functions?

Generally with Atmega based Arduino bords like "UNO (Atmega328) or MEGA2560 (Atmega2560) TIMER0 is already occupied by the internal timing functions like millis() and micros(), so better not mess around with TIMER0 on Atmega boards or internal timing with millis() and micros() might be destroyed.

Besides of TIMER0 additional timers will be used when using analogWrite on PWM-pins.

Which timers will be used depends on the Arduino board.

So if you are not telling the Arduino board and PWM-pins you want to use ==> No answer possible about which timers are occupied with usage of analogWrite() function.

Don't write timer code that interferes with hardware timers already in use by the Arduino core library!

to your question

The Atmel AVR ATMega 168 or ATmega328 have 3 timers, called timer0, timer1 and timer2. Timer0 and timer2 are 8bit timers and timer1 is a 16bit timer. On a Mega (AVR ATmega1280 or the ATmega2560) you have 6 timers, Timer 0, timer1 and timer2 are identical to the ATmega168/328 and timer3, timer4 and timer5 are all 16bit timers.

All timers depend on the system clock - most often 16MHz

On your Arduino :

  • timer0 is been used for the software Sketch timing functions, such as delay(), millis() and micros() ==> if you change timer0 registers, you influence the Arduino timing function.

  • timer1 on Arduino Uno or timer5 on Arduino Mega is used for the servo library

  • timer2 is used by the tone() function ==> to make your life easy you can use that function to achieve what you want to do with less work

Timer 3,4,5 are only available on Arduino Mega boards if you don't use PWM

if you want to use PWM

On a UNO as we only have 3 timers but 6 PWM pins, they go in pairs and the relation between timers and PWM outputs is as follow:

  • timer0 = Pins 5, 6
  • timer1 = Pins 9, 10
  • timer2 = Pins 11, 3

On a MEGA you have 6 timers but 15 PWM pins (PWM: 2 to 13 and 44 to 46) , they also go in pair or triples

  • timer0 = Pins 4, 13
  • timer1 = Pins 11,12
  • timer2 = Pins 9, 10
  • timer3 = Pin 2, 3, 5
  • timer4 = Pin 6, 7, 8
  • timer5 = Pin 44, 45, 46

if you want to explore timer you can change the Timer behavior (different clock sources can be selected for each timer independently) through the timer register values (prescaler, Timer/Counter Register, Interrupt Mask Register, ...) and timers can be configured in different modes such as PWM or CTC.

plenty of examples are available on line and in the forum but I would suggest you explore the tone() function

Thanks
I have a low cost nano V3
I programmed the Timer 1 with
OCR1A = 15625; // 62.5 ns *
With a 256 prescaler, with no output ocr1
Just an interrupt to fire an ISR on for match

So I will use tone function hoping it will relay on timer 2 with PWM ocr2

you should be fine then