Using Flowcode to run 3 PWM O/P's instead of usual 2

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Using Flowcode to run 3 PWM O/P's instead of usual 2

Post by medelec35 »

IMPORTANT NOTE: PLEASE LOOK AT POST DATED Fri Apr 30, 2010 10:29 pm FIRST.
THANK YOU.

Flowcode Attachment was created with flowcode 4.

This would be useful if you are already using both PWM components in Flowcode, and would like to set-up the third
If you are using 1 or more PWM channels with Flowcode then Both t2con and pr2 are not required.

Instructions: Just enter clock frequency , PWM frequency and Duty.

On flowchart Place a 0 output for each CCP in use. e.g if CCP3 is RB5, then use an output icon with B5 set at 0

Select prescaler to give highest Pr2.

Copy and paste cells containing required values into a flowcode C box after output icon e.g.
t2con = 0b0000101 ;
pr2 = 0b11111001 ;
ccpr1l = 0b01111101 ;
ccp1con = 0b00001100 ;

I have protected excel sheet to avoid entering data into wrong cells. There is no password if you would like to see how values are calculated.
za
Note example is using fosc=4MHz, fpwm=1KHz & Duty=50%

The code for pasting into C box will automatically change as you alter PWM frequencies, prescaler etc., removing all the hard work and saving time.

Also note that with older versions of excel (pre 2007 i believe), analysis toolpak will have to be added.
PWM C From excel.jpg
PWM C From excel.jpg (33.76 KiB) Viewed 11820 times
I am new to running pwm with this method, so please let me know if I have made any mistakes. Thank you
Attachments
PWM Calculations4.xls
(24 KiB) Downloaded 779 times
pwm C from excel1.fcf
(4 KiB) Downloaded 790 times
Last edited by medelec35 on Sun May 02, 2010 3:01 pm, edited 4 times in total.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Manually setting up PWM (CCP types only)

Post by medelec35 »

This Excel sheet is Decimal version, Ideal if you want to control the 3rd pwm module with variables.
I will be shortly posting a flowchart which three pots will independently control 3 pwm signals.
two of which will be set up using flowcodes dual pwm module and the third using excel + C box method.
Attachments
PWM Calculations DEC Version.xls
(24.5 KiB) Downloaded 661 times
Martin

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: Manually setting up PWM (CCP types only)

Post by Benj »

Great piece of work there Medelec many thanks for your input.

Im looking forward to having a play with this when I get some free time. :P

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Manually setting up PWM (CCP types only)

Post by medelec35 »

Thanks Ben. I have now completed excel sheet to produce a lookup table for duties from 0 to 100%. All is required is cells to be copied and paste into supplementary code box. Eg if duty of 34% is required, correct values (if I have got calculations right of course :P ) will be retrieved, and pwm3 will be set.
Just got to get flowchart to compile now :-)
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Manually setting up PWM (CCP types only)

Post by medelec35 »

I have modified the excel sheet to produce a formula that can be copied and paste directly into flowcode calculation box. Then the value of ADC2 = duty % of pwm3. This takes all the maths away form some one who wants to use a third PMW channel.
flowcode 3 pwn.jpg
flowcode 3 pwn.jpg (77.83 KiB) Viewed 11789 times
I have included a flowcode sample (Flowcode V4), which has 3 pots to produce 3 PWM with adjustable duties.
At this stage I can't guarantee accuracy of of third PWM.
I have posted for any one to test,I would be really grateful if any one could test and post some feed back please E.g does it work OK, and if not, what is the issue .

Thank you.
Attachments
Flowcode 3 CH PWM.fcf
(14.5 KiB) Downloaded 816 times
Last edited by medelec35 on Sat May 01, 2010 8:40 am, edited 1 time in total.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Using Flowcode to run 3 PWM O/P's instead of usual 2

Post by medelec35 »

Update: All three (or more if you have them) PWM channels are working, and appear to be spot on, after revising formula.
It has taken several attempts because the formula to calculate CCPxCON and CCPRxL using Fosc, PWM Freq was not easy to reduce enough for PICs to handle using 16bit signed maths. I have tested on 19.6MHz and 4MHz ,using PWM Freq of 2KHz and 1KHz respectively. independently Varying three pots produced correct PWM duty for all 3 channels.
Hopefully this will be useful if you want to run and control 3 or more PWM channels using Flowcode.
Let me know If you want a Flowcode V3 version, and I will post it.
Simulated 3 channel pwm.jpg
Simulated 3 channel pwm.jpg (63.43 KiB) Viewed 11776 times
Edit: Flowcode V3 is no longer supported.
Attachments
PWM Calculations DEC Version V2.xls
(54.5 KiB) Downloaded 621 times
Flowcode 3 CH PWM.fcf
(10.5 KiB) Downloaded 765 times
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Using Flowcode to run 3 PWM O/P's instead of usual 2

Post by medelec35 »

Screen shot of revised formula within excel (post above).
Revised Formula.jpg
Revised Formula.jpg (95.94 KiB) Viewed 11733 times
Martin

ikke
Posts: 13
Joined: Sat Dec 12, 2009 6:08 pm
Contact:

Re: Using Flowcode to run 3 PWM O/P's instead of usual 2

Post by ikke »

Hello,
I am trying to get a third PWM- output from my ATMEGA324p. Idid try all the previous steps but I think these are for PIC's only.Is there anyone ho can tell me what I have to do, so I can output 3 (or) more PWM signals.
I thank you allready
Ikke

Post Reply