120Hz Pulse Signal

Hi,

I am looking to use my Arduino Due to generate an output pulse of 120Hz. I am new to Arduino so am unsure about how to do this, could anyone please help with this?

Thanks :)

There are lots of PWM example sketches in the DUE sub forum.

You might use PWM or TC libraries from antodom, or a direct register programing (see pinout diagram from Graynomad + Sam3x datasheet PWM chapter):

/************************************************************************************/
/*                 PWMH2   -   PWM frequency = 120Hz                                */
/************************************************************************************/

void setup () {
  

  // PWM Set-up on pin PC7 (Arduino Pins 39(PWMH2): see Datasheet chap. 38.5.1 page 973
  PMC->PMC_PCER1 |= PMC_PCER1_PID36;                   // PWM power ON - datasheet page 38
  PWM->PWM_DIS = PWM_DIS_CHID2;                        // Disable PWM channel 2

  // Select Instance=PWM; Signal=PWMH2 (channel 2); I/O Line=PC7 (P7, Arduino pin 39, see pinout diagram) ; Peripheral type B
  PIOC->PIO_PDR |= PIO_PDR_P7;                          // Set the pin to the peripheral PWM, not the GPIO
  PIOC->PIO_ABSR |= PIO_PC7B_PWMH2;                     // Set PWM pin perhipheral type B

  PWM->PWM_CLK = PWM_CLK_PREB(0) | PWM_CLK_DIVB(16);   // Set the PWM clock rate to 84MHz/16. 
  PWM->PWM_CH_NUM[2].PWM_CMR = PWM_CMR_CPRE_CLKB;      // The period is left aligned, clock source as CLKB on channel 2
  PWM->PWM_CH_NUM[2].PWM_CPRD = 43750;                 // Channel 2 : Set the PWM frequency 84MHz/16/CPRD = 120HZ ;
  PWM->PWM_CH_NUM[2].PWM_CDTY = 50;                    // Channel 2: Set the PWM duty cycle to x%= (CDTY/ CPRD)  * 100 % ;

  PWM->PWM_ENA = PWM_ENA_CHID2;

}

void loop() {

  // Update PWM frequency with PWM->PWM_CH_NUM[2].PWM_CPRDUPD if you need to modify PWM frequency after setup()
  // Update PWM Duty cycle with PWM->PWM_CH_NUM[2].PWM_CDTYUPD if you need to modify PWM duty cycle after setup()
}