Pins 3, 9, 10 Y 11 Are Disabled If You Use Timer 1 And 2 (Not PWM)?

Pins 3, 9, 10 y 11 are disabled if you use Timer 1 and 2 (Not PWM)? Projects Programming June 22, 2018, 1:44pm 1

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.

June 22, 2018, 1:56pm 2

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.

June 22, 2018, 2:09pm 3

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?

June 22, 2018, 2:12pm 4

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.

June 22, 2018, 2:13pm 5

Sure. It's done all the time.

June 22, 2018, 2:18pm 6

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?

June 22, 2018, 2:26pm 7

You can still use OCR2A and OCR2B.

June 22, 2018, 2:34pm 8

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.

June 22, 2018, 6:21pm 9

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.

Topic Replies Views Activity
Arduino PWM pins 3 and 11 are not working while using Timer1 Programming 5 1530 May 5, 2021
Timer Interrupts and PWM Pins Programming 5 40784 May 5, 2021
Set Timer for PWM and use pin as digital in/out? Programming 9 1637 May 6, 2021
3 out of 4 timer pins don't do anything Programming 15 770 August 24, 2021
PWM on certain pins do not output Programming 12 752 December 14, 2022
Unfortunately, your browser is unsupported. Please switch to a supported browser to view rich content, log in and reply.

Tag » Arduino Timer1 Pwm Pins