I'm using an Arduino Nano 33 BLE. I'd like to use three of the nRF52840 32 bit timers to control stepper motor velocities. I've found several references that say Timer0 and Timer2 are used by the "system". I have to admit I'm a little foggy on what the "system" is, assuming its some combination of Arduino libraries and/or mbedOS. Assuming Timer0 and Timer2 are off limits, that should leave Timer1, Timer3, and Timer4 available for application usage.
However, when I check timer registers, I see Timer1 in use, and Timer0 and Timer2 not in use. I realize that Timer0 and Timer2 can still be reserved for "system" usage, even though they are not in use at the moment. It's Timer1's status that surprises me. Timer1 seems to be set to go off every 0x70000010 micro seconds (about 30 minutes).
So here is my question: What timers am I safe to use without stepping on the "system"?
Thanks,
BB61
p.s. Here is the timer status and code used to check timer status.
10:29:21.984 -> Press Any Key to Begin
10:29:22.392 -> OK - Begin
10:29:22.392 -> TIMER0 Mode:0 ENSET Bits: 0 0 0 0 CC Regs(0x): 0 0 0 0
10:29:22.392 -> TIMER1 Mode:0 ENSET Bits: 1 0 0 0 CC Regs(0x): 70000010 28 0 0
10:29:22.392 -> TIMER2 Mode:0 ENSET Bits: 0 0 0 0 CC Regs(0x): 0 0 0 0
10:29:22.392 -> TIMER3 Mode:0 ENSET Bits: 0 0 0 0 0 0 CC Regs(0x): 0 0 0 0 0 0
10:29:22.392 -> TIMER4 Mode:0 ENSET Bits: 0 0 0 0 0 0 CC Regs(0x): 0 0 0 0 0 0
#include <nrf_timer.h>
// Serial.print one line of status for given timer.
void showTimerStatus(NRF_TIMER_Type* timer_address, int num_cc_regs){
Serial.print("Mode:");
Serial.print((int)nrf_timer_mode_get(timer_address));
Serial.print(" ENSET Bits: ");
for (int i = 0; i < num_cc_regs; i++)
{
bool enset = nrf_timer_int_enable_check(timer_address, (nrf_timer_cc_channel_t)1<<(16+i));
Serial.print(enset ? 1 : 0);
Serial.print(" ");
}
Serial.print(" CC Regs(0x): ");
for (int i = 0; i < num_cc_regs; i++)
{
uint32_t cc = nrf_timer_cc_read(timer_address, (nrf_timer_cc_channel_t)i);
Serial.print(cc,16);
Serial.print(" ");
}
Serial.println(" ");
}
void setup() {
Serial.begin(9600);
unsigned int start_milli = millis();
while (Serial.available() == 0){ // wait for char from terminal
unsigned int elapsed = millis() - start_milli;
if (elapsed > 1000) {
Serial.println("Press Any Key to Begin");
start_milli = millis();
}
}
while (Serial.read() != -1); // clear buffer
Serial.println("OK - Begin");
// See what timers are currently in use
Serial.print("TIMER0 ");
showTimerStatus(NRF_TIMER0, 4);
Serial.print("TIMER1 ");
showTimerStatus(NRF_TIMER1, 4);
Serial.print("TIMER2 ");
showTimerStatus(NRF_TIMER2, 4);
Serial.print("TIMER3 ");
showTimerStatus(NRF_TIMER3, 6);
Serial.print("TIMER4 ");
showTimerStatus(NRF_TIMER4, 6);
}
void loop() {
}