Go Down

Topic: Three differently adjustable frequency PWM channels Arduino Due (Read 687 times) previous topic - next topic

redflood

Hi everyone,
I have two problems when using Arduino Due as below:
1. I want to create three differently adjustable frequency PWM channels.
2. The frequency is up to 1MHz.
Could you please suggest me some advice how I can do it and is it possible?

ard_newbie


redflood

My big question is can I generate three different periods for each channel? Currently, I can generate two different periods (frequencies). I read the source and realized that the command PWMC_ConfigureClocks takes two input clock sources. I am wondering about could I create three independent PWM channels (different frequency/period).

ard_newbie


You can update a PWM frequency in loop() with PWM_CPRDUPD register; likewise you can update duty cycle in loop() with PWM_CDTYUPD register. Note that you will have to set UPDULOCK bit in PWM_SCUC to trigger an update of PWM frequency.

redflood

Thank you for your answer. I am confusing about the below line
PWMC_ConfigureClocks( pwm_clockA_freq, pwm_clockB_freq, VARIANT_MCK );
There are only two clock sources A and B, it will affect to all PWM channels (all channels will inherit that two frequencies). So I can not find a way to create the third PWM channel that has a different frequency with A and B. So how I can solve this problem. Thank you so much!

ard_newbie

PWMC_ConfigureClocks() doesn't set two frequencies for a same PWM signal, it simply sets parameters of PWM_CLK register. First one is DIVA, second one is PREA if you select clockA in PWM_CMR (or DIVB, PREB if you select clockB)

See :https://searchcode.com/file/46088176/MakefileBasedBuild/Atmel/sam3x/sam3x-ek/libraries/libchip_sam3x/source/pwm.c

Go Up