Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

Timers do not work

2 posters

Go down  Message [Page 1 of 1]

1Timers do not work Empty Timers do not work Thu Mar 18, 2021 10:29 pm

pausar2000



Timers do not work in comparison mode, when setting directly from registers. The interruption does not happen, for the arduino Mega 2560

2Timers do not work Empty Re: Timers do not work Fri Mar 19, 2021 11:16 pm

arcachofo

arcachofo

Hi.

Can you share the code that is not working?

If not, can you tell which values are you using for those registers?

3Timers do not work Empty Re: Timers do not work Mon Mar 22, 2021 2:55 pm

pausar2000



//this is the code for arduino mega, setting the timer in comparison mode
//In the 4.13 of simulIde versiĆ³n the code works good

/*program that turns a led on and off at 350 ms intervals
using timer 1 in CTC (A) mode or comparison mode*/


#define LED 13

void config_timer(void);

void setup() {
// put your setup code here, to run once:
pinMode(LED,OUTPUT);
config_timer();
}

void loop() {
// put your main code here, to run repeatedly:

}

ISR(TIMER1_COMPA_vect) //Interrupt Service Routine
{
TCNT1=0;
digitalWrite(LED,digitalRead(LED)^1);
}

void config_timer(void){
TCCR1A = TCCR1B = 0;//ELIMINAR CUALQUIE CONF PREVIA DEL TIMER
TCNT1 = 0;//Borro cualquier conteo o valor previo

OCR1A = 21875;// SE COMPARA el timer 1 CONTRA 21875 CONTEOS...con el fin de obtener 350 ms
TCCR1B |= (1 << WGM12); //se configuro el timer 1 en modo de comparaciĆ³n CTC..
TCCR1B |= (1<

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum