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?
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.