Go Down

Topic: [solved]PWM inittiation on registers (Read 776 times) previous topic - next topic


If you want two PWM outputs with the same frequency and duty cycle, you need two channels.

PWMH/PWML inverted is very useful in 2-bit Gray Up/Down Counter. Note that figure 38.6 page 981 of Sam3x datasheet is wrong, you will find a correct figure page 962 of Sam4S datasheet (The two uc share a very similar PWM controller).

I read again the datasheet and a "0" has no effect on PWM_DIS and PWM_ENA, only a "1", your code is correct.


Ok, I understand.
I was looking on bad column on pinout diagram from this forum :P (fail :/ )
When I want to set peripheral type A Should i do it this way? e.g.
Code: [Select]
Do you know where(In what file?) all these declarations(e.g. PMC_PCER1_PID36) are ?


May 15, 2017, 06:22 am Last Edit: May 15, 2017, 06:36 am by ard_newbie
Header files :


And  PIOE->PIO_ABSR &= ~(PIO_ABSR_P15); is the way to select peripheral type A for PE15, but all pins are not broken out, AFAIK you can only access to PIOA, B, C and D.

Some 3rd party arduino DUE compatible boards have more broken out pins like this one:


Now I can boldly experiment.
Thank you for your help and full commitment :)


So there is no way to set PWMH 1 to a 30% duty cycle and PWML1 to 30% duty cycle in the same time?
And when I set:
Code: [Select]
PWM_CPRD = 1024;
PWM_CDTY = 256;
25% duty cycle
for PWMH it mean 25% LOW , 75% HIGH
When it's PWML its 25% HIGH, 75% LOW?
PWMH1 and PWML1 are complementary outputs. If PWMH1 is high at the moment, PWML1 is low and vice versa.  You do not set the duty cycle of PWMH1 and PWML1 independently.  You set the duty cycle of PWM Channel 1. Your two parameters listed PWM_CPRD and PWM_CDTY only tell part of the story. I'm assuming for the time being your waveform is left aligned with your period length being 1024 clock cycles. The PWMHx starting state (high/low) is defined by a flag in the parameter PWM_CMRx when the counter starts.  The PWMHx output will then switch states when the count reaches 256.  When the count reached 1024, we cycle back to the beginning.

I have already addressed the issue back in March in the article:
describing implementating multichannel PWM. In a nutshell, I was running the 8 PWM channels up to 1 MHz.  If have to have 12-bit resolution, your max frequency will be 20.5 KHz. I also include a heavily commented sketch that covers PWM setup in more detail.
If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

Go Up