Page 1 of 1
10bit duty cycle operates in 8bit FL4-ARM
Posted: Fri Oct 28, 2011 1:42 pm
by Odox00
Hi
I can't get PWM(0) on my ECIOARM to work in 10bit it is still in 8bit resolution even when I use "SetDutyCycle10bit".
I have to increase SetDutyCycle10bit (INT) by 8 to get a change in pulse length. Is it suppose to be like this or am I missing something?
Re: 10bit duty cycle operates in 8bit FL4-ARM
Posted: Fri Oct 28, 2011 2:32 pm
by Benj
Hello,
The 10-bit mode basically adds two bits to the least significant side of the PWM mark space ratio allowing for slightly more resolution.
The PWM period itself should not change. Is this what you are finding?
Edit: Sorry I thought you were using PIC. I'm currently not sure what happens for ARM I will have a dig in and see what I can find out for you.
Re: 10bit duty cycle operates in 8bit FL4-ARM
Posted: Fri Oct 28, 2011 2:38 pm
by Benj
Hello again,
Right it looks like the ARM hardware only supports 8-bit PWM operation. The function simply takes the 10-bit value you pass in and shifts it down to 8-bits. I think the only reason the function is there is so we can import 10-bit PWM programs from PIC and AVR into ARM without error.
Re: 10bit duty cycle operates in 8bit FL4-ARM
Posted: Fri Oct 28, 2011 2:41 pm
by Benj
Right Last one.
It looks like the ARM does support up to 16-bit PWM so I was wrong about that.
The problem lies in changing the bit depth from 8 to 10 which would have the effect of changing the overall period on ARM which means the period value shown in the component properties would be incorrect for 10-bit operation. Maybe we can do something about this for v5.
How about using a timer interrupt for now and bit banging out the PWM. This way you can get any resolution you require.
There is an example of bit banged PWM available from here:
http://www.matrixmultimedia.com/article.php?a=52
Re: 10bit duty cycle operates in 8bit FL4-ARM
Posted: Fri Oct 28, 2011 2:47 pm
by Benj
Ok last post I promise.
One way to get 10-bit PWM working using the peripheral would be to use the custom code feature.
Edit the Enable function and change the following lines
AT91F_PWMC_CfgChannel(AT91C_BASE_PWMC, 0, 0x020b, %a, 2); // Set channel parameters
to
AT91F_PWMC_CfgChannel(AT91C_BASE_PWMC, 0, 0x020b, 1023, 2); // Set channel parameters
and
AT91F_PWMC_CfgChannel(AT91C_BASE_PWMC, 1, 0x020b, %a, 2); // Set channel parameters
to
AT91F_PWMC_CfgChannel(AT91C_BASE_PWMC, 1, 0x020b, 1023, 2); // Set channel parameters
Then edit the SetDutyCycle10bit function and change this following line.
nDuty = (nDuty >> 2) & 0xff;
to
//nDuty = (nDuty >> 2) & 0xff;
Let me know how you get on. As I say the period shown in the component properties will be incorrect but you should get 10-bit resolution.
Re: 10bit duty cycle operates in 8bit FL4-ARM
Posted: Mon Oct 31, 2011 12:03 pm
by Odox00
Thanks it works, like you suggested in your last post.
I only had some permission issues with Win7 not allowing to change files in program files folder. Had to move the file to my desktop, make the changes, and move it back.
Not that I need it, but would it be possible to use 16bit resolution?
Re: 10bit duty cycle operates in 8bit FL4-ARM
Posted: Mon Oct 31, 2011 6:09 pm
by Benj
Hello,
16-bit resolution is possible by changing the code like this.
AT91F_PWMC_CfgChannel(AT91C_BASE_PWMC, 0, 0x020b, 65535, 2); // Set channel parameters
AT91F_PWMC_CfgChannel(AT91C_BASE_PWMC, 1, 0x020b, 65535, 2); // Set channel parameters
This line also still needs to be commented out.
//nDuty = (nDuty >> 2) & 0xff;
You should then be able to pass in a 16-bit value from Flowcode using the function as is. Beware about signed / unsigned maths in Flowcode using INT variables. I don't think this should be an issue for this but just something to be aware of if things do start acting strange.
As the resolution is now 16-bit the overall period will be 6/8-bits larger giving you an even lower overall PWM frequency.