Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: TimerOne running at twice speed

  1. #1

    TimerOne running at twice speed

    I programmed a Teensy 4.1 using Timer1 at the TimerOne library. It is easy to manage and works very well bu goes 2x faster than expected.
    I have seen at the TimerOne.h file at the setPeriod) function that it is multiplied the microseconds by 0.0000005f and perhaps should be 0.0000010f

       void setPeriod(unsigned long microseconds) __attribute__((always_inline)) {
    	uint32_t period = (float)F_BUS_ACTUAL * (float)microseconds * 0.0000005f;

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Please show the complete program I should copy into Arduino and run on a Teensy 4.1 to reproduce the problem. Even if the code is "trivial", even if the bug is "obvious", please reply with a complete program so I don't have to guess the code you tried.

  3. #3
    Hey Paul, here is:

    //In the setup menu:
        //TEST Timer1
        Serial.println("========== ini test Timer1 ========");
        Timer1.initialize(100UL);//Interrupcion cada 100us
        Timer1.attachInterrupt(timer1_funcion); // Calls function timer1_funcion() 
        Serial.println("========== end test Timer1 ========");
    //AND here is the called function:
    void timer1_funcion()
      static uint32_t timer1_openloop=0,loop=0; 
      if (timer1_openloop>=10000) { Serial.println((String) "LOOP: " + loop);timer1_openloop=0;loop++;}
    If you run that code it should appear 8 Serial prints between ini test and end test, but appears 16 in 8 seconds (the delay function waits 8 seconds)

  4. #4
    Senior Member
    Join Date
    Nov 2012
    The global variables used/declared in the interrupt routine, must also be declared volatile.
      volatile static uint32_t timer1_openloop=0,loop=0;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts