Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

TimerB0 does not trigger interrupt #4

Closed
cattledogGH opened this issue Nov 10, 2022 · 2 comments
Closed

TimerB0 does not trigger interrupt #4

cattledogGH opened this issue Nov 10, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@cattledogGH
Copy link

TimerB0 will not trigger an interrupt.
I think there is a bug in TimerInterrupt::setFrequency()

 //if ((_timer <= 0) || (callback == NULL) || ((frequencyLimit) < 1) )
  if ((_timer < 0) || (callback == NULL) || ((frequencyLimit) < 1) )

If I make this change to the source code, TimerB0 appears to be working properly.

Simple Blink sketch using TimerB0 will not blink LED. TimerB1 blinks the LED as expected.

#define TIMER_INTERRUPT_DEBUG 0
#define _TIMERINTERRUPT_LOGLEVEL_ 0

#define USING_16MHZ true
#define USING_8MHZ false
#define USING_250KHZ false

#define USE_TIMER_0 true  
//#define USE_TIMER_1 true  

#include "megaAVR_TimerInterrupt.h"

#define FREQUENCY 1

volatile uint32_t TimerCount = 0;

void printResult(uint32_t currTime)
{
  Serial.print(F("Time = "));
  Serial.print(currTime);
  Serial.print(F(", TimerCount = "));
  Serial.println(TimerCount);
}

void TimerHandler()
{
  TimerCount++;
  digitalWrite(13, !digitalRead(13));  //blink led
}

void setup()
{
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);

  Serial.begin(115200);
  while (!Serial);

  ITimer0.init();
  ITimer0.attachInterrupt(FREQUENCY, TimerHandler);
  //ITimer1.init();
  //ITimer1.attachInterrupt(FREQUENCY, TimerHandler);  
}

#define CHECK_INTERVAL_MS 10000L

void loop()
{

  static uint32_t lastTime = 0;
  static uint32_t currTime;

  currTime = millis();

  if (currTime - lastTime > CHECK_INTERVAL_MS)
  {
    printResult(currTime);
    lastTime = currTime;
  }
}

Expected behavior

TimerB0 triggers interrupt to blink led and increase count.

Actual behavior

No interrupt is triggered. Count ==0 and led does not blink

Debug and AT-command log (if applicable)

[TISR] setFrequency error

Information

  • Occurs with megaAVR_TimerInterrupt version 1.6.1
  • Occurs with Arduino IDE version both 1.8.19 and 2.0.1 and Windows 10.
  • Occurs with MegaCoreX 1.1.0 and megaAVR 1.8.7 cores. Latest updates.
  • Occurs at all timer and processor frequencies.
  • All other Bn timer interrupts work normally with the library code.
@khoih-prog
Copy link
Owner

HI @cattledogGH

Thanks for your real bug spot. I'll fix the mistake and will quickly release a new version.

Best Regards,

@khoih-prog khoih-prog added the bug Something isn't working label Nov 11, 2022
khoih-prog added a commit that referenced this issue Nov 11, 2022
### Release v1.7.0

1. Fix bug disabling `TCB0`. Check [TimerB0 does not trigger interrupt #4](#4)
2. Use `allman astyle` and add `utils`
khoih-prog added a commit that referenced this issue Nov 11, 2022
### Release v1.7.0

1. Fix bug disabling `TCB0`. Check [TimerB0 does not trigger interrupt #4](#4)
2. Use `allman astyle` and add `utils`
@khoih-prog
Copy link
Owner

khoih-prog commented Nov 11, 2022

Hi @cattledogGH

Thanks to your bug spot, the new megaAVR_TimerInterrupt v1.7.0 has just been released to fix bug disabling TCB0. Your contribution is noted in Contributions and Thanks.

Looking forward to receiving more of your valuable bug reports.

Best Regards,


Release v1.7.0

  1. Fix bug disabling TCB0. Check TimerB0 does not trigger interrupt #4
  2. Use allman astyle and add utils

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants