problem with timers in the V3.x arduino ide board manager

micro_step
Posts: 1
Joined: Sat Jul 20, 2024 11:42 am

problem with timers in the V3.x arduino ide board manager

Postby micro_step » Sat Jul 20, 2024 11:50 am

  1. In version 2.x (espressif systems esp32 board manager) the timer configuration for example “timer = timerBegin(1,80,true);” allows you to choose the timer in this case timer1 but in version 3. x you only enter the frequency e.g. “timer = timerBegin(1000000);” then when I want to stop the timer if it automatically chose the timer used by freeRTOS when I stop the timer everything stops (or so I interpret that is happening). how am I supposed to choose the timer I want? if I want to use x timer for the use I want to give it how do I select it now in version 3.x?
  2.  
  3. I put a simplification of the code where only the timer is handled, in this case is for the V2.X board manager where if I set the timer 0 I get the same problem as the code adapted for V3.X but as in V2. X I can choose the timer when entering another timer you can see only the printout of “running” when the timer is disabled and “running” with “enter” when the timer is enabled (something that with timer 0 if it stops also stops all execution ie nothing is printed).
  4.  
  1.  
  2. TaskHandle_t Tarea0;
  3. hw_timer_t *timer = NULL;
  4.  
  5. bool estado_dimmer = true;
  6. bool flag = false;
  7.  
  8. void IRAM_ATTR reloj() {
  9.   flag = true;
  10.  
  11. }
  12.  
  13. void d_on_off(bool on_off) {  
  14.      
  15.   if (on_off){
  16.  
  17.       if(estado_dimmer == false){
  18.           Serial.println("todo activado");
  19.       timerStart(timer);
  20.       estado_dimmer = true;
  21.     }
  22.     else{
  23.       Serial.println("ya esta todo activado");
  24.     }  
  25.  
  26.   }
  27.   else{
  28.  
  29.       if(estado_dimmer == true){
  30.       Serial.println("todo desactivado");
  31.       timerStop(timer);
  32.       estado_dimmer = false;
  33.     }
  34.     else{
  35.       Serial.println("ya esta todo desactivado");
  36.     }
  37.  
  38.   }
  39. }
  40.  
  41.  
  42. void setup() {
  43.  
  44.  
  45.   timer = timerBegin(1,80,true);//timer = timerBegin(1000000);
  46.   timerAttachInterrupt(timer, &reloj ,true);
  47.   timerAlarmWrite(timer, 2000000, true);
  48.   timerAlarmEnable(timer);
  49.  
  50.   xTaskCreatePinnedToCore(loop0,"Tarea_0",1000,NULL,1,&Tarea0,1); // Core 1
  51.  
  52.  
  53.   Serial.begin(115200);      
  54.  
  55. }
  56.  
  57. void loop() { //el por defecto
  58.  
  59.  
  60. }
  61.  
  62.  
  63. void loop0(void *parameter){
  64.  
  65.   while(1==1){
  66.  
  67.  
  68.     Serial.println("andando");
  69.  
  70.     if(flag){
  71.       Serial.println("entro");
  72.       flag=false;
  73.     }
  74.  
  75.  
  76.   int valorIngresado;    
  77.  
  78.   if (Serial.available() ) {  
  79.     valorIngresado = Serial.parseInt();
  80.  
  81.     if(valorIngresado == 300){
  82.  
  83.       d_on_off(true);
  84.          
  85.     }
  86.     else if(valorIngresado == 400){
  87.  
  88.       d_on_off(false);
  89.            
  90.     }else {
  91.  
  92.       Serial.println("Ingresar el valor 300 o 400.");
  93.     }
  94.     while (Serial.available() ) {
  95.       Serial.read();
  96.     }
  97.   }
  98.  
  99.       vTaskDelay(1000 / portTICK_PERIOD_MS);
  100.  
  101.   }
  102. }

Who is online

Users browsing this forum: No registered users and 43 guests