Page 1 of 1

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

Posted: Mon Apr 26, 2010 2:37 pm
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 12366 times
I am new to running pwm with this method, so please let me know if I have made any mistakes. Thank you

Re: Manually setting up PWM (CCP types only)

Posted: Mon Apr 26, 2010 9:39 pm
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.

Re: Manually setting up PWM (CCP types only)

Posted: Tue Apr 27, 2010 9:51 am
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

Re: Manually setting up PWM (CCP types only)

Posted: Tue Apr 27, 2010 2:31 pm
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 :-)

Re: Manually setting up PWM (CCP types only)

Posted: Thu Apr 29, 2010 11:45 pm
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 12335 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.

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

Posted: Fri Apr 30, 2010 9:29 pm
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 12322 times
Edit: Flowcode V3 is no longer supported.

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

Posted: Wed May 05, 2010 6:13 am
by medelec35
Screen shot of revised formula within excel (post above).
Revised Formula.jpg
Revised Formula.jpg (95.94 KiB) Viewed 12279 times

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

Posted: Sat Dec 18, 2010 7:54 am
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