Go Down

Topic: Help with PWM ! (Read 416 times) previous topic - next topic

TYTY

I am trying to get a square output with 1.5us period, but the duty cycle is 80ns/1500ns=0.053.
On DUE.

My code:
#include <Arduino.h>
void setup()
{
  int32_t mask_PWM_pin = digitalPinToBitMask(7);
REG_PMC_PCER1 = 1<<4;               // activate clock for PWM controller
REG_PIOC_PDR |= mask_PWM_pin;  // activate peripheral functions for pin (disables all PIO functionality)
REG_PIOC_ABSR |= mask_PWM_pin; // choose peripheral option B   
REG_PWM_CLK = 0;                     // choose clock rate, 0 -> full MCLK as reference 84MHz
REG_PWM_CMR6 = 0<<9;             // select clock and polarity for PWM channel (pin7) -> (CPOL = 0)
REG_PWM_CPRD6 = 125;                // initialize PWM period -> T = value/84MHz (value: up to 16bit)
REG_PWM_CDTY6 = 8;                // initialize duty cycle, REG_PWM_CPRD6 / value = duty cycle
REG_PWM_ENA = 1<<6;               // enable PWM on PWM channel (pin 7 = PWML6)
}
 
void loop()
{

}


but changing REG_PWM_CDTY6 is no use as the duty cycle is always wrong(250ns/period).
could anyone help me get the signal desired?

Go Up