Go Down

Topic: which pin is it as a output for this 1 Mhz clock (Read 136 times) previous topic - next topic

ED201

I found this nice code,  I cannot find which pin on arduino due or it simply does not work



/******************************************************************************/
/***               1MHz/ 50% Duty cycle PWM thru TIOA0                      ***/
/******************************************************************************/

void setup() {

/*************  Timer Counter 0 Channel 0 to generate PWM pulses thru TIOA0  ************/
  PMC->PMC_PCER0 |= PMC_PCER0_PID27;                      // Timer Counter 0 channel 0 IS TC0, TCO power ON
  PMC->PMC_PCER0 |= PMC_PCER0_PID12;                      // PIOB power ON, page 38
 
  PIOB->PIO_PDR |= PIO_PDR_P25;
  PIOB->PIO_ABSR |= PIO_ABSR_P25;                        // PB25 is driven by the TC, peripheral type B, page 858

  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_UP_RC        // 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 = 42;  //<*********************  Frequency = (Mck/2)/TC_RC  = 1 MHz
  TC0->TC_CHANNEL[0].TC_RA = 21;  //<********************   Duty cycle = (TC_RA/TC_RC) * 100 = 50 %

  TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC0 counter and enable

}

void loop() {
 
}

ard_newbie

I found this nice code,  I cannot find which pin on arduino due or it simply does not work
What is the most relevant document to find pinouts ?

ED201

on the pin layout I see that it might be AD0, A7

but nothing there when I connect osciloscope.


ard_newbie


You must be the only one to see TIOA0 on A7/AD0 !!!

ED201

now i see on pin 2, If I was as good as you I wouldn't ask

I use already this pin for TFT screen

would it be possible to move to another pin like analog pins A8, A9 etc

or maybe on one of the 36 pin panel I see it also have the PWM pins

ard_newbie

You can use TIOA1 as well, but you will have to modify the sketch. TIOA1 is output by Timer Counter 0 Channel 1, and the pin is PA2:

Code: [Select]

/******************************************************************************/
/***               1MHz/ 50% Duty cycle PWM thru TIOA1                      ***/
/******************************************************************************/

void setup() {

/*************  Timer Counter 0 Channel 0 to generate PWM pulses thru TIOA0  ************/
  PMC->PMC_PCER0 |= PMC_PCER0_PID28;                      // Timer Counter 0 channel 1 IS TC0, TC1 power ON, page 38
 
  PIOA->PIO_PDR |= PIO_PDR_P2;
  PIOA->PIO_ABSR &= ~PIO_PA2A_TIOA1;                      // PA2 is driven by the TC, peripheral type A, page 858

  TC0->TC_CHANNEL[1].TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK1  // MCK/2, clk on rising edge
                              | TC_CMR_WAVE               // Waveform mode
                              | TC_CMR_WAVSEL_UP_RC        // UP mode with automatic trigger on RC Compare
                              | TC_CMR_ACPA_CLEAR          // Clear TIOA1 on RA compare match
                              | TC_CMR_ACPC_SET;           // Set TIOA1 on RC compare match


  TC0->TC_CHANNEL[1].TC_RC = 42;  //<*********************  Frequency = (Mck/2)/TC_RC  = 1 MHz
  TC0->TC_CHANNEL[1].TC_RA = 21;  //<********************   Duty cycle = (TC_RA/TC_RC) * 100 = 50 %

  TC0->TC_CHANNEL[1].TC_CCR = TC_CCR_SWTRG | TC_CCR_CLKEN; // Software trigger TC0 counter and enable

}

void loop() {
 
}

ED201

Thanks I see nice 1 Mhz square on analog 7 pin

Go Up