10bit duty cycle operates in 8bit FL4-ARM

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Odox00
Flowcode v5 User
Posts: 24
Joined: Thu Aug 25, 2011 11:15 am

10bit duty cycle operates in 8bit FL4-ARM

Post 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?
Jeppe
Don't say oups!? Say Interesting!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 10bit duty cycle operates in 8bit FL4-ARM

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 10bit duty cycle operates in 8bit FL4-ARM

Post 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.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 10bit duty cycle operates in 8bit FL4-ARM

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 10bit duty cycle operates in 8bit FL4-ARM

Post 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.

Odox00
Flowcode v5 User
Posts: 24
Joined: Thu Aug 25, 2011 11:15 am

Re: 10bit duty cycle operates in 8bit FL4-ARM

Post 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?
Jeppe
Don't say oups!? Say Interesting!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: 10bit duty cycle operates in 8bit FL4-ARM

Post 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.

Post Reply