Good morning, Am trying to generate three different signals using Arduino due with given below specifications :
signal 1 : pulse of peak to peak 3.2 V, 200 us delay , 200 ns rise/fall time, 100 us peak, and 300 us pulse period.
signal 2 : pulse of peak to peak 3.2 V, 350 us delay , 200 ns rise/fall time, 100 us peak, and 300 us pulse period.
signal 3 : pulse of peak to peak 3.2 V, 1000 us delay , 200 ns rise/fall time, 1000 us peak, and 2000 us pulse period.
Am getting the signal but with delay other than the specifications, frequency of the signals is also different when it is connected to the oscilloscope for verification. Please help me to resolve the issue, I used below code to generate the waveforms.
void setup()
{
// Set up PWM on digital pins D9, D8, D7, and D6 for channels 4 through to 7 respectively
PMC->PMC_PCER1 |= PMC_PCER1_PID36; // Enable PWM controller
PIOC->PIO_ABSR |= PIO_ABSR_P24 | PIO_ABSR_P23 | PIO_ABSR_P22 | PIO_ABSR_P21; // Set the port C PWM pins to peripheral type B
PIOC->PIO_PDR |= PIO_PDR_P24 | PIO_PDR_P23 | PIO_PDR_P22 | PIO_PDR_P21; // Set the port C PWM pins to outputs
PWM->PWM_CLK = PWM_CLK_PREA(0) | PWM_CLK_DIVA(1); // Set the PWM clock A rate to 84MHz (84MHz/1)
PWM->PWM_SCM = PWM_SCM_SYNC7 | PWM_SCM_SYNC6 | PWM_SCM_SYNC5 | PWM_SCM_SYNC4;
PWM->PWM_CH_NUM[0].PWM_CPRD = 25200; // Set PWM period for channel 0
PWM->PWM_CH_NUM[4].PWM_CMR = PWM_CMR_DTE | PWM_CMR_CPRE_CLKA; // Configure channel 4
PWM->PWM_CH_NUM[4].PWM_CDTY = 8400; // Set duty cycle for channel 4
PWM->PWM_CH_NUM[5].PWM_CMR = PWM_CMR_DTE | PWM_CMR_CPRE_CLKA; // Configure channel 5
PWM->PWM_CH_NUM[5].PWM_CDTY = 8400; // Set duty cycle for channel 5
PWM->PWM_CH_NUM[6].PWM_CMR = PWM_CMR_DTE | PWM_CMR_CPRE_CLKA; // Configure channel 6
PWM->PWM_CH_NUM[6].PWM_CDTY = 84000; // Set duty cycle for channel 6
// Enable channels with delays
PWM->PWM_ENA = PWM_ENA_CHID4; // Enable channel 4
delayMicroseconds(200); // Delay 200 microseconds
PWM->PWM_ENA = PWM_ENA_CHID5; // Enable channel 5
delayMicroseconds(350); // Delay 350 microseconds
PWM->PWM_ENA = PWM_ENA_CHID6; // Enable channel 6
delayMicroseconds(1000); // Delay 1000 microseconds
PWM->PWM_SCUC = PWM_SCUC_UPDULOCK; // Set the update unlock bit to trigger an update at the end of the next PWM period
}
void loop()
{
// Empty loop, no repeated actions
}
type or paste code here