ISR based on Overflow from Arduino UNO to Arduino DUE

Good morning I would like to adapt the following part of code wrote for Arduino UNO in order to make it works on Arduino DUE, but I'm not able to find the corresponding register in Arduino DUE:

    void setup() {
      // put your setup code here, to run once:
      TIMSK1 &= ~(1<<TOIE1); //disable register del timer 1

      TCCR1A &= ~((1<<WGM11) | (1<<WGM10)); 
      TCCR1B &= ~((1<<WGM12) | (1<<WGM13)); //WGM10 = WGM11 = WGM12 = WGM13 = 0 : “Normal” timer 
      TIMSK1 &= ~(1<<OCIE1A); //Timer 1 interrupt in case of overflow
      TCCR1B |= (1<<CS10);  // set "1" in CS11
      TCCR1B &= ~((1<<CS12)|(1<<CS11)); // set 0 in CS12  e CS10   //pre scaler 8 

      TCNT1H = 0xC1;  
      TCNT1L = 0x81; //initializing counter
      TIMSK1 |= (1<<TOIE1);  //set interrupt 

     Serial.begin(9600);
     pinMode(pin, OUTPUT);
   }

   ISR(TIMER1_OVF_vect){ // 1000 Hz
      TCNT1H = 0xC1;  
      TCNT1L = 0x81; //initializing counter
   }

Time for the Tech Reference Manual; and since the architecture is very different, direct comparison of "names" will not exist. My guess is that you will need to dig-into the Arduino core to understand how functions are related.

You may find these online resources useful:

Multiple Results (microchip.com)

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

I try looking at the datasheet and some example to write this code, but is not working:

        '''
        void tc_setup()
        {
          PMC->PMC_PCER1 = PMC_PCER1_PID35;                      // TC8 power ON : Timer Counter 2 channel 2 IS TC8
        
          PIOD->PIO_PDR = PIO_PDR_P7                             // pin is controlled by the corresponding peripheral not by the PIO Controller. The pin is no more driven by GPIO
                          | PIO_PDR_P8;
          PIOD->PIO_ABSR |= PIO_PD7B_TIOA8                       //Set TIOA8 and TIOB0 to the peripheral
                           | PIO_PD8B_TIOB8;                   
        
          TC2->TC_CHANNEL[2].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1  //MCK/2, clk on rising edge
                                      | TC_CMR_EEVT_XC2           //TIOB in output
                                      | TC_CMR_WAVE               //Waveform mode
                                      | TC_CMR_WAVSEL_UP       //UP mode with automatic trigger on RC Compare
                                      | TC_CMR_BCPB_SET           //Set TIOB on RB compare match
                                      | TC_CMR_BCPC_CLEAR         //Clear TIOB on RC compare match
                                      | TC_CMR_ACPA_CLEAR         //Clear TIOA on RA compare match
                                      | TC_CMR_ACPC_SET;          //Set TIOA on RC compare match
        
          //MIO CASO
          // (84MHz/2)= 42000000
          // 1/42000000 = 0.00000000...
          // 0.001/0.000000... = 42000 (periodo richiesto 1ms)
          //( (2^32) - 42000 + 1 = 4294963097 ) --> in caso di overflow
        
          TC2->TC_CHANNEL[2].TC_RC = 42000;                       //TIOA8 Frequency = Mck/2/TC_RC          <-- step che vogliamo fare 
          TC2->TC_CHANNEL[2].TC_RA = 21000;                       //Any Duty cycle in between 1 and TC_RC
          TC2->TC_CHANNEL[2].TC_RB = 21000;                       //Any Duty cycle in between 1 and TC_RC
        
          TC2->TC_CHANNEL[2].TC_IER = TC_IER_COVFS;                // Interrupt on RC compare match
          NVIC_EnableIRQ(TC8_IRQn);
          TC2->TC_CHANNEL[2].TC_CV = 4294963097;                  //The current value of the counter is accessible in real time by reading the TC Counter Value Register (TC_CV)
        
          TC2->TC_CHANNEL[2].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC8 counter and enable
        }  
        
        // ISR(TC2_SR2_COVFS){  //should I use this in some way?
        void TC8_Handler() {
        
          TC2->TC_CHANNEL[2].TC_CV = 4294963097;                       // Read and clear status register
          PIOB->PIO_ODSR ^= PIO_ODSR_P27;               // Toggle LED every 1 Hz
          
        }

      '''

Reality time:

I think of 4 options:

  • Some member has worked-thru and willing to share,
  • You work thru and share with community,
  • You stay with Uno, or
  • You abandon the project.
 ISR(TIMER1_OVF_vect){ // 1000 Hz

So you're just looking for a 1kHz interrupt?

Create a function called int sysTickHook(), and it should get called every millisecond.
return 0 if you want to run the normal millis() timing function as well.
Unlike the AVR's periodic interrupt, the Due's:

  1. Occurs at exactly 1kHz
  2. has this "hook" capability for inserting a user function.

I wouldn't like to set it just at 1 kHz, but I would like to make it works in order to change the start parameter of the register every time depending on the required frequency. millis is not that accurate as the interrupt.