Seeed-Studio / ArduinoCore-samd

49 stars 27 forks source link

Fix some wrong register values #66

Closed wh201906 closed 2 weeks ago

wh201906 commented 1 year ago

The function setPeriod() sets the wrong register value. According to the comment, these timer library is inspired on the khoih-prog/SAMD_TimerInterrupt, which has the right code.

For TC3: https://github.com/khoih-prog/SAMD_TimerInterrupt/blob/88c4a730ce3396cdf71f69936d24e6eb0d7f9b0a/src/SAMDTimerInterrupt.hpp#L424-L430 https://github.com/khoih-prog/SAMD_TimerInterrupt/blob/88c4a730ce3396cdf71f69936d24e6eb0d7f9b0a/src/SAMDTimerInterrupt.hpp#L724-L730 For TCC: https://github.com/khoih-prog/SAMD_TimerInterrupt/blob/88c4a730ce3396cdf71f69936d24e6eb0d7f9b0a/src/SAMDTimerInterrupt.hpp#L810-L812

wh201906 commented 1 year ago

The formula for the timer period can also be found in the datasheet DS40001882D


30.6.2.6.3 图片


31.6.2.5.5 图片


In the current code, the +1 is ignored, so the register value is wrong.

Lesords commented 2 weeks ago

Hello,

I appreciate what you did, but I won't consider merging this code now.

Because the code you modified has nothing to do with this formula.

And to be precise, you should modify the entire setPeriod function instead of the final result.

Like here: TimerTC3.cpp