I've tried to use the Adafruit ZeroTimer library with an ItsyBitsy M4 Express board, but get a number of compilation errors related to TC4 and TC5. Is there a fix for this someplace, or can the library be rebuilt to exclude the timers that don't exist on the processor used in the ItsyBitsy M4?
Thanks for any word on this.
ZeroTimer library problem with ItsyBitsy M4 Express
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jstanle1
- Posts: 47
- Joined: Sat Dec 12, 2015 5:53 pm
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: ZeroTimer library problem with ItsyBitsy M4 Express
The ZeroTimer library is written for M0+ microcontrollers, and hasn't been ported to the M4 yet.
I'm afraid we don't know of any existing timer libraries for the M4 though.
I'm afraid we don't know of any existing timer libraries for the M4 though.
- jstanle1
- Posts: 47
- Joined: Sat Dec 12, 2015 5:53 pm
Re: ZeroTimer library problem with ItsyBitsy M4 Express
Thanks for the word on this.
I'm actually using the ZeroTimer library with a Metro M4 Express -- it luckily just works there.
It looks like the only problem running it on the ItsyBitsy M4 Express is the difference in the number of timers in the two processors used on those boards. If there were a version of the library for the SAMD51G, it might work on the ItsyBitsy M4.
Barring that, I don't mind writing directly to registers to program the hardware but I'm not sure how to do that in the Arduino environment; any clues about doing that would be appreciated.
Thanks.
I'm actually using the ZeroTimer library with a Metro M4 Express -- it luckily just works there.
It looks like the only problem running it on the ItsyBitsy M4 Express is the difference in the number of timers in the two processors used on those boards. If there were a version of the library for the SAMD51G, it might work on the ItsyBitsy M4.
Barring that, I don't mind writing directly to registers to program the hardware but I'm not sure how to do that in the Arduino environment; any clues about doing that would be appreciated.
Thanks.
- jstanle1
- Posts: 47
- Joined: Sat Dec 12, 2015 5:53 pm
Re: ZeroTimer library problem with ItsyBitsy M4 Express
I managed to hack a version of the ZeroTimer library that works with ItsyBitsy M4 Express after all -- a matter of taking out references to timers 4 and 5 and changing the timer output pin designations to match the ItsyBitsy pins. There's only a single timer, but that's fine. Hardware PWM works; I haven't tried the interrupts.
In any case, apparently there's enough similarity between the 'g' and 'j' parts to make this possible without too much strain.
I would like to change the clock this timer uses -- it's not clear to me how to go about this; any word on how to do that would be appreciated.
Thanks.
In any case, apparently there's enough similarity between the 'g' and 'j' parts to make this possible without too much strain.
I would like to change the clock this timer uses -- it's not clear to me how to go about this; any word on how to do that would be appreciated.
Thanks.
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: ZeroTimer library problem with ItsyBitsy M4 Express
You'll have to read the relevant sections of the SAMD51 datasheet for the details (and there are plenty):
http://ww1.microchip.com/downloads/en/D ... 01507B.pdf
As a general overview, the SAMD architecture has about three layers and two options for timers. It begins with any of 8 raw clock sources called Generators, any or all of which can be active at the same time. Those feed the Generic Clock Controller peripheral, which has 12 instances of a prescaler connected to an output multiplexer. You choose the generator clock you want to use as a source, the prescaler value if you want to reduce the raw frequency to some other value, then assign the output to one or more Peripheral Clock Control channels.
There are two kinds of timers: simple Timer/Counter (TC) instances and Timer/Counter for Control (TCC) instances. There are six TC instances and six TCC instances in the SAMD51J.
Each TC instance on the SADM51 can be configured as an 8, 16, or 32-bit counter, and has a PERIOD register that represents the counter's maximum value. You can configure it to count up or down, the counter will wrap around at PERIOD either way, and will generate an interrupt each time it wraps around. Each TC instance has two Compare registers used to generate PWM or handle external event timing, each of which will generate an interrupt when the counter equals the comparison value.
Each TCC instance can be configured as a 16 or 24-bit counter, and has a PERIOD register that represents the counter's maximum value. Along with the simple count-up and count-down modes of a TC instance, a TCC instance can alternate counting up to PERIOD and then down to zero on each cycle, generating interrupts at both ends. Each TC instance has four comparison registers that generate PWM, and each one generates an interrupt when the counter equals the comparison value.
Each TC and TCC instance has its own binary prescaler (1:1, 1:2, 1:4, ... 1:1024) that's applied to its Generic Clock input.
http://ww1.microchip.com/downloads/en/D ... 01507B.pdf
As a general overview, the SAMD architecture has about three layers and two options for timers. It begins with any of 8 raw clock sources called Generators, any or all of which can be active at the same time. Those feed the Generic Clock Controller peripheral, which has 12 instances of a prescaler connected to an output multiplexer. You choose the generator clock you want to use as a source, the prescaler value if you want to reduce the raw frequency to some other value, then assign the output to one or more Peripheral Clock Control channels.
There are two kinds of timers: simple Timer/Counter (TC) instances and Timer/Counter for Control (TCC) instances. There are six TC instances and six TCC instances in the SAMD51J.
Each TC instance on the SADM51 can be configured as an 8, 16, or 32-bit counter, and has a PERIOD register that represents the counter's maximum value. You can configure it to count up or down, the counter will wrap around at PERIOD either way, and will generate an interrupt each time it wraps around. Each TC instance has two Compare registers used to generate PWM or handle external event timing, each of which will generate an interrupt when the counter equals the comparison value.
Each TCC instance can be configured as a 16 or 24-bit counter, and has a PERIOD register that represents the counter's maximum value. Along with the simple count-up and count-down modes of a TC instance, a TCC instance can alternate counting up to PERIOD and then down to zero on each cycle, generating interrupts at both ends. Each TC instance has four comparison registers that generate PWM, and each one generates an interrupt when the counter equals the comparison value.
Each TC and TCC instance has its own binary prescaler (1:1, 1:2, 1:4, ... 1:1024) that's applied to its Generic Clock input.
- jstanle1
- Posts: 47
- Joined: Sat Dec 12, 2015 5:53 pm
Re: ZeroTimer library problem with ItsyBitsy M4 Express
Thanks for your reply -- there are definitely a lot of details. I'll look through the specs to learn more about the clocks.
- agent2003
- Posts: 6
- Joined: Mon Dec 24, 2018 12:13 pm
Re: ZeroTimer library problem with ItsyBitsy M4 Express
Hi - would you be able to post the files that you modified and the directories these are stored in? I would like to do the same thing on my ItsyBitsy M4. Thanksjstanle1 wrote:I managed to hack a version of the ZeroTimer library that works with ItsyBitsy M4 Express after all -- a matter of taking out references to timers 4 and 5 and changing the timer output pin designations to match the ItsyBitsy pins. There's only a single timer, but that's fine. Hardware PWM works; I haven't tried the interrupts.
In any case, apparently there's enough similarity between the 'g' and 'j' parts to make this possible without too much strain.
I would like to change the clock this timer uses -- it's not clear to me how to go about this; any word on how to do that would be appreciated.
Thanks.
- jstanle1
- Posts: 47
- Joined: Sat Dec 12, 2015 5:53 pm
Re: ZeroTimer library problem with ItsyBitsy M4 Express
Agent2003, sorry I didn't see your post sooner. Have you gotten this to work? If not, I can post notes and see if I can attach the hacked-up ZeroTimer library.
- Dennis_van_Gils
- Posts: 1
- Joined: Mon Feb 11, 2019 3:56 pm
Re: ZeroTimer library problem with ItsyBitsy M4 Express
I was struggling with setting up an interrupt service routine (ISR) timer on a SAMD51 as well on an Adafruit M4 Feather Express board. I have made a library which can be used for this. The method names are identical to the ZeroTimer library for M0 boards (SAMD21) such that it is easy to port from SAMD21 to SAMD51.
See GitHub: https://github.com/Dennis-van-Gils/SAMD ... rruptTimer
Have fun,
Dennis van Gils
See GitHub: https://github.com/Dennis-van-Gils/SAMD ... rruptTimer
Code: Select all
#include <Arduino.h>
#include "SAMD51_InterruptTimer.h"
void myISR() {
// Your code
}
void setup() {
TC.startTimer(50, myISR); // Call myISR() every 50 usec
}
Dennis van Gils
Please be positive and constructive with your questions and comments.