AVR Fast PWM programming

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
nmjb18
Posts: 5
Joined: Tue Jul 19, 2016 4:40 pm
Been thanked: 1 time

AVR Fast PWM programming

Post by nmjb18 »

Hi All, my first post!

I am trying to work out how to implement the 'fast PWM' mode available on a number of the AVR devices. Is there functionality in FC 7 to do this with a macro or will it have to be done through a 'C' block? I have found the following application note http://www.atmel.com/Images/Atmel-2542- ... AVR131.pdf on the subject but as I rely on Flowcode to do the hard stuff I am struggling to work out what I would have to do to implement fast PWM within my project.

Can any one help me figure it out?

Many Thanks,

Matt

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: AVR Fast PWM programming

Post by Benj »

Hi Matt,

There is a PWM component under the Outputs component category that should be able to generate the high frequency PWM you need. Changing the Prescaler property to a low value should give you a fast PWM period.

Let us know how your getting on.

nmjb18
Posts: 5
Joined: Tue Jul 19, 2016 4:40 pm
Been thanked: 1 time

Re: AVR Fast PWM programming

Post by nmjb18 »

Hi Ben, thanks for your reply.

The AVR's have two types of PWM, the standard seems to be available using the FC PWM component but the fast/high speed PWM does not. From the application note I gather the timer for the fast PWM can be set to a higher frequency than the CPU clock, up to 64MHz if properly configured.

How can I reconfigure the PWM timer to give me a base frequency in excess of the CPU clock frequency?

Cheers,

Matt

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: AVR Fast PWM programming

Post by Benj »

Hi Matt,

Aha I see now, here is something you can try.

Enable the high speed PLL by using the C code.

Code: Select all

PLLCSR = 0x02;
Then wait for the PLL to lock with the following C code.

Code: Select all

while ((PLLCSR & 1) != 1);
Finally switch on the asynchronous PWM mode with the following C code.

Code: Select all

PLLCSR = 0x06;
Then hopefully just use the PWM as you would normally and the hardware should output using the high frequency PWM.

nmjb18
Posts: 5
Joined: Tue Jul 19, 2016 4:40 pm
Been thanked: 1 time

Re: AVR Fast PWM programming

Post by nmjb18 »

Hi Ben,

Thank you for the code, it has taken me a very long time to get round to trying it (I have been distracted with other projects).

I have given it a go and the complier has come back with an error ('PLLCSR' undeclared). I assume a library has to be included??

I have found another step by step example of someone using the 'fast PWM', but I am lost as how to convert this information into something usable for Flowcode.

http://www.re-innovation.co.uk/web12/in ... n-attiny85

Any help would be much appreciated.

Regards,

Matt

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: AVR Fast PWM programming

Post by Benj »

Hi Matt,

Is it the ATTiny85 device you're using?

PLLSCR is a register name so it sounds like it either doesn't exist on your device or has a different name.

Post Reply