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.
I am new to running pwm with this method, so please let me know if I have made any mistakes. Thank you
Using Flowcode to run 3 PWM O/P's instead of usual 2
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Using Flowcode to run 3 PWM O/P's instead of usual 2
- Attachments
-
- PWM Calculations4.xls
- (24 KiB) Downloaded 812 times
-
- pwm C from excel1.fcf
- (4 KiB) Downloaded 822 times
Last edited by medelec35 on Sun May 02, 2010 3:01 pm, edited 4 times in total.
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Manually setting up PWM (CCP types only)
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.
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 692 times
Martin
- 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)
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.
Im looking forward to having a play with this when I get some free time.

Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Manually setting up PWM (CCP types only)
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
) will be retrieved, and pwm3 will be set.
Just got to get flowchart to compile now

Just got to get flowchart to compile now

Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Manually setting up PWM (CCP types only)
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.
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.
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 850 times
Last edited by medelec35 on Sat May 01, 2010 8:40 am, edited 1 time in total.
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Using Flowcode to run 3 PWM O/P's instead of usual 2
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. Edit: Flowcode V3 is no longer supported.
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. Edit: Flowcode V3 is no longer supported.
- Attachments
-
- PWM Calculations DEC Version V2.xls
- (54.5 KiB) Downloaded 659 times
-
- Flowcode 3 CH PWM.fcf
- (10.5 KiB) Downloaded 795 times
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Using Flowcode to run 3 PWM O/P's instead of usual 2
Screen shot of revised formula within excel (post above).
Martin
Re: Using Flowcode to run 3 PWM O/P's instead of usual 2
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
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