Pins 3, 9, 10 y 11 are disabled if you use Timer 1 and 2 (Not PWM)?

Hello

I'm doing a project using a Arduino UNO. I have to use the timer 1 and 2. I thought that if you use that timers with interrupts, you could use the pins 3, 9, 10 y 11 unless you have programmed that timers for PWM.

Well, the problem is that I can't use that pins, and I need them. Do you know if is it possible?

Thank you.

The reason you can't use them is because the Arduino init() function (wiring.c attached to your code during compilation) sets every timer to use PWM. The only thing you need to do is reset the timers.

TCCR1A = 0;
TCCR1B = 0;
TCCR2A = 0;
TCCR2B = 0;

Needless to say, if you then want to use PWM the timers will need to be configured again.

DKWatson:
The reason you can't use them is because the Arduino init() function (wiring.c attached to your code during compilation) sets every timer to use PWM. The only thing you need to do is reset the timers.

TCCR1A = 0;
TCCR1B = 0;
TCCR2A = 0;
TCCR2B = 0;

Needless to say, if you then want to use PWM the timers will need to be configured again.

Thank you for answering.

I understand you. In my code, I have this:

TCCR1A = 0; //Inicializamos los registros de control
TCCR1B = 0;
TCCR1A |= (1 << COM1A1)|(1 << COM1A0)|(1 << COM1B1)|(1 << COM1B0); //NO CTC. 3 interrupciones

TCCR2A = 0; //Inicializamos los registros de control
TCCR2B = 0;
TCCR2A |= (1 << COM2A1)|(1 << COM2A0)|(1 << COM2B1)|(1 << COM2B0); //NO CTC. 3 interrupciones
TCCR2B |= (1 << CS20)|(1 << CS21)|(1 << CS22); //Prescalado a 256

Then, I don't programme PWM... But anyway, can't I use that pins?

For further clarification, if you look at I/O multiplexing in the datasheet, you see that those pins share functions with other peripherals. Those in question are OC1A, OC1B, OC2A and OC2B. These become the default as soon as the respective timer is set to any mode other than normal. The mode of each timer is set by the waveform generator mode bits (WGM[2:0]). There are 8 possible modes, seven of which will reassign the pins. Normal mode, WGM[2:0] - 0x00, leaves the pins alone and the timers function as normal timers.

Sure. It's done all the time.

DKWatson:
Sure. It's done all the time.

Thank you again!

I'm going to try using only the OVF interrupt of the timer 2. If I don't use OC2X, I think that I won't have problems. Do you agree?

You can still use OCR2A and OCR2B.

DKWatson:
You can still use OCR2A and OCR2B.

I think that I understood wrong the Register when I was reading one months ago. If I put this:

TCCR2A = 0; //Inicializamos los registros de control
TCCR2B = 0;
TCCR2B |= (1 << CS20)|(1 << CS21)|(1 << CS22); //Prescalado a 256

OCR2A = 255/3;
OCR2B = 2*255/3;
TIMSK2 |= (1 << OCIE2A)|(1 << OCIE2B)|(1 << TOIE2);

I'm using normal mode, then I can use pins 3 and 11, and I can use the functions: ISR(TIMER2_COMPX_vect)/ISR(TIMER2_OVF_vect).

You are helping me a lot. Thank you.

All good. Just make sure that if you activate all the interrupts, you must include the ISR in your code, even if it is empty.