Arduino DUE PWM palse

I want to generate pulses by comparing the values of the timer counter and the RA register, but I have set the digital 2 pin of the Arduino DUE on the PB25 to output, but no pulses are generated. What should I do? Also, I don't understand why I need to use TC0_Handler and the "status & TC_SR_CPAS" part.
Can someone please help me?

void tc_setup() {

  PMC->PMC_PCER0 |= PMC_PCER0_PID27;    //TC0 power ON : Timer Counter 0 channel 2 IS TC0 p.31
  PMC->PMC_PCER0 |= PMC_PCER0_PID28;    //TC1
  PMC->PMC_PCER0 |= PMC_PCER0_PID29;    //TC2
  
  TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // チャネル制御レジスタ,カウンタークロックイネーブル
  TC0->TC_CHANNEL[1].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN;
  TC0->TC_CHANNEL[2].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN;
  
  PIOB->PIO_PDR |= PIO_PDR_P25;           // PB25 is no more driven by the GPIO p858 インプット/アウトプットライン
  //PIOB->PIO_PDR |= PIO_PDR_P25;
  //PIOB->PIO_PDR |= PIO_PDR_P25;
  PIOB->PIO_ABSR |= PIO_PB25B_TIOA0;

  TC0->TC_CHANNEL[0].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1  // MCK/2, clk on rising edge
                              | TC_CMR_WAVE               // Waveform mode
                              | TC_CMR_WAVSEL_UPDOWN        // UP mode with automatic trigger on RC Compare
                              | TC_CMR_ACPA_CLEAR          // Clear TIOA0 on RA compare match
                              | TC_CMR_ACPC_SET;           // Set TIOA0 on RC compare match
   
  TC0->TC_CHANNEL[0].TC_RC = 28000;  //<*********************  Frequency = (Mck/2)/TC_RC  Hz = 15 KHz
  TC0->TC_CHANNEL[0].TC_RA =  sinwave_u;  //<********************   Duty cycle = (TC_RA/TC_RC) * 100  %  = 80 %

 TC0->TC_CHANNEL[0].TC_IER = TC_IER_CPCS       // Interrupt on RC compare match
                              | TC_IER_CPAS;    // Interrupt on RA compare match
                             
  NVIC_EnableIRQ(TC0_IRQn);                     // Interrupt enable
                           
  TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC0 counter and enable
}

void TC0_Handler()
{
 uint32_t status;
 status = TC0->TC_CHANNEL[0].TC_SR;  // Read and clear TC0 status register

 if(status & TC_SR_CPAS) {
  // Toggle pin 1
 }
 else  if(status & TC_SR_CPCS)
  {
  // Toggle pin 2
 }
}

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