Page 1 of 1
AVR Fast PWM programming
Posted: Wed Jul 20, 2016 11:32 am
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
Re: AVR Fast PWM programming
Posted: Wed Jul 20, 2016 11:41 am
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.
Re: AVR Fast PWM programming
Posted: Wed Jul 20, 2016 12:37 pm
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
Re: AVR Fast PWM programming
Posted: Wed Jul 20, 2016 1:35 pm
by Benj
Hi Matt,
Aha I see now, here is something you can try.
Enable the high speed PLL by using the C code.
Then wait for the PLL to lock with the following C code.
Finally switch on the asynchronous PWM mode with the following C code.
Then hopefully just use the PWM as you would normally and the hardware should output using the high frequency PWM.
Re: AVR Fast PWM programming
Posted: Wed Oct 05, 2016 10:35 am
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
Re: AVR Fast PWM programming
Posted: Wed Oct 05, 2016 12:06 pm
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.