Timer counter timer 1 TC0 channel 1 on Due

Hello,
I am using Arduino Due and I am using the all the Timer counter 9 of them independently to creat PWM wave but I am stuck with timer 1 is not working, I dont know if I need to change something in the code. I use all the digital pins that is related to the timer counter and I still need one and I am trying with Analog pin 7 A7 on arduino Due, because in the datasheet of SAM , it shows that I can use it.

can I use this analog pin to create the pwm through timer counter

#define STEP_PIN_61 61 // motor 8


float frequency = 10000.0;


void setup() {

  Serial.begin(9600);
 
  pinMode(STEP_PIN_61, OUTPUT);
 


 setupTimer5();

}
void loop() {

}


void setupTimer5() {

  

  PMC->PMC_PCER0 |= PMC_PCER0_PID28;                    // // Enable peripheral TC1 (TC0 Channel 1)
  PIOA->PIO_ABSR |= PIO_ABSR_P2;           //  the multiplexer to peripheral A for TIOA1 , D61
  PIOA->PIO_PDR |= PIO_PDR_P2;             // Disable the GPIO on the corresponding pins

volatile int32_t rc = (84000000 / 2) / frequency;              // //by PWM_FREQUENCY Velocity = TIMER_CLOCK / RC.  

TC0->TC_CHANNEL[1].TC_CMR =   TC_CMR_BCPC_SET |           // Set TIOB on counter match with RC0
                              TC_CMR_ACPC_SET |           // Set TIOA on counter match with RC0
                              TC_CMR_BCPB_CLEAR |         // Clear TIOB on counter match with RB0
                              TC_CMR_ACPA_CLEAR |         // Clear TIOA on counter match with RA0
                              //TC_CMR_ABETRG   |           // TIOA is used as the external trigger
                              TC_CMR_WAVE |               // Enable wave mode
                              TC_CMR_WAVSEL_UP_RC |       // Count up with automatic trigger on RC compare
                              //TC_CMR_EEVT_XC0 |           // Set event selection to XC0 to make TIOB an output make an output
                              TC_CMR_TCCLKS_TIMER_CLOCK1; // Set the timer clock to TCLK1 (MCK/2 = 84MHz/2 = 42MHz)

   TC0->TC_CHANNEL[1].TC_RA = rc / 2;                        // Load the RB0 register TIOA1

   TC0->TC_CHANNEL[1].TC_RC = rc;                       // Load the RC0 register period

    

  //NVIC_SetPriority(TC7_IRQn, 0);    // Set the Nested Vector Interrupt Controller (NVIC) priority for TC6 to 0 (highest) 
  NVIC_EnableIRQ(TC1_IRQn);         // Connect TC6 to Nested Vector Interrupt Controller (NVIC)

  TC0->TC_CHANNEL[1].TC_IER |= TC_IER_CPCS;                // Enable interrupts for TC7 (TC2 Channel 1)
  TC0->TC_CHANNEL[1].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Enable the timer TC7

}

void TC1_Handler() {
  uint32_t status = TC0->TC_CHANNEL[1].TC_SR;  // Read the status register of Channel 1



}

Generally, without going through your code, using Timer/Counter the pins are fixed. Each Timer/Counter has 2 outputs, TIOA and TIOB. They are assigned to pins according to table 36-4 of the datasheet.

For PWM the Due also has special HW, see chapter 38 of the manual: "The PWM macrocell controls 8 channels independently."

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.