timer arduino zero

Hi

If I define 2 timers, when will they start? Are they starting at the exact same time? Or what is the time difference?

Thanks

Normally they will start when you tell them to start. Whether you can get them to start at the same time depends on how you have start them.

How do I tell them when to start? I set them up in the "setup" and they start automatically after the setup at the same time (that's the question is it really the same time, what's the time difference?) as the "loop".

gab27:
How do I tell them when to start?

With the appropriate start command of course.

gab27:
How do I tell them when to start? I set them up in the "setup" and they start automatically after the setup at the same time (that's the question is it really the same time, what's the time difference?) as the "loop".

Timers in Arduino don't start automatically, you must be giving some command like Timer.start something. In the setup function, you have to initialize your timers and then in loop section, where you want to start the timer, place timer.start . Moreover, tell us which Timer Library you are using and also share your code to get better help.

jackthom41:
Timers in Arduino

You're jumping to conclusions. OP never mentioned what kind of timers they want to use. Internal timers? External timers? What kind? No info. Hence my perfectly generic answers, wondering whether OP would get to their senses, read the sticky, and post a proper question.

void setup() {

noInterrupts();

REG_GCLK_CLKCTRL = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID_TCC0_TCC1);
  while ( GCLK->STATUS.bit.SYNCBUSY == 1 );
  REG_GCLK_CLKCTRL = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID_TC4_TC5);
  while ( GCLK->STATUS.bit.SYNCBUSY == 1 );
  
  // TCC0.
  
  TCC_0->CTRLA.reg &= ~TCC_CTRLA_ENABLE;       // Disable the timers
  while (TCC_0->SYNCBUSY.bit.ENABLE == 1);     // wait for sync
  
  TCC_0->CTRLA.reg |= TCC_CTRLA_PRESCALER_DIV64;
  
  TCC_0->WAVE.reg |= TCC_WAVE_WAVEGEN_MFRQ;         // Set wave form on match frequnecy configuration -> CC0 match.
  while (TCC_0->SYNCBUSY.bit.WAVE == 1);            // wait for sync.
  
  TCC_0->CC[0].reg = compare_value;
  while (TCC_0->SYNCBUSY.bit.CC0 == 1);             // wait for sync.
  
  TCC_0->INTENSET.reg = 0;                 // disable all interrupts.
  TCC_0->INTENSET.bit.OVF = 1;             // enable overfollow.

  NVIC_EnableIRQ(TCC0_IRQn);               // enable InterruptVector.
  TCC_0->CTRLA.reg |= TCC_CTRLA_ENABLE ;   // enable TCC_0.
  while (TCC_0->SYNCBUSY.bit.ENABLE == 1); // wait for sync.

// TC5.
  
  TC_5->CTRLA.reg &= ~TC_CTRLA_ENABLE;
  while (TC_5->STATUS.bit.SYNCBUSY == 1);
  
  TC_5->CTRLA.reg |= TC_CTRLA_PRESCALER_DIV8;
   while (TC_5->STATUS.bit.SYNCBUSY == 1);
  
  TC_5->CTRLA.reg |= TC_CTRLA_MODE_COUNT16;
  while (TC_5->STATUS.bit.SYNCBUSY == 1);
  TC_5->CTRLA.reg |= TC_CTRLA_WAVEGEN_MFRQ;
  while (TC_5->STATUS.bit.SYNCBUSY == 1);

  TC_5->CC[0].reg = compare_value;
  while (TC_5->STATUS.bit.SYNCBUSY == 1);

  TC_5->INTENSET.reg = 0;
  TC_5->INTENSET.bit.OVF = 1;

  NVIC_EnableIRQ(TC5_IRQn);
  TC_5->CTRLA.reg |= TC_CTRLA_ENABLE ;
  while (TC_5->STATUS.bit.SYNCBUSY == 1);
 

  interrupts();
}

To be more specific: How do I say them when to start? with interrupts(), or TC_CTRLA_ENABLE, or do they start after the setup()?
For me they should start at the same time or as nearly at the same time.