All 5 PWM CCP and ECCP channels program

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
opieflus
Posts: 7
Joined: Sun Dec 16, 2012 5:31 am
Been thanked: 6 times
Contact:

All 5 PWM CCP and ECCP channels program

Post by opieflus »

Chip used is 16F1937. All 5 PWM channels are used - CCP and ECCP. This program runs fine for me, it should work for you. I just finished it and it runs fine on my proto board to light 5 leds at different brightness. Adjust brightness by changing the value of PWM_x_DUTY_CYCLE from 0 to 255.

I am a newbie to PIC programming and Flowcode so I do not have a lot of information on this as of yet. Hopefully someone can build on this.

Merry Christmas!
Attachments
PWM - ECCP.fcf
(8 KiB) Downloaded 908 times

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: All 5 PWM CCP and ECCP channels program

Post by medelec35 »

Hi opieflus,
Merry Christmas to you too.

Thank you for sharing your Flowchart.
It's very handy for Flowcode users if learning ASM.

I have posted a couple of flowcharts that use components within flowchart to control all 5 CCP PWM channels.
Here:
http://www.matrixmultimedia.com/mmforum ... 26&t=11694

I have set PWM frequency at 5KHz

Hope it helps.

Martin
Martin

opieflus
Posts: 7
Joined: Sun Dec 16, 2012 5:31 am
Been thanked: 6 times
Contact:

Re: All 5 PWM CCP and ECCP channels program

Post by opieflus »

This is a more refined version of what I uploaded last night.

Notes from comment section in program -

This program is meant to be used as a template for using the 2 CCP
AND the 3 ECCP PWM channels simultaneously for the 16F1937 PIC chip.
Other chips may be used but you will have to consult the datasheet
for your chip for correct register values if this program does not work.

As far as I have read the 3 ECCP channels are not directly
accessible through Flowcode macros for this chip or any others.

This program does not use any of the built-in macros supplied
with Flowcode though they may be added for simulation
purposes.

If you use the PWM macros included with Flowcode with the 16F1937
chip and it does not work after compiling, disable all Flowcode
supplied macros for PWM and recompile.

Other notes included in program -

After the initial 2 macro calls, anytime you need to update
the PWM channels, change the PWM_x_DUTY_CYCLE variables and
call the Update_all_PWM_channels macro again.

The only way I have found that this way works is to not have
ANY of the Flowcode supplied macros for the internal PWM
functions enabled when compiling.

You can use them for simulation, but it will probably not work
for compiling due to all the codes Flowcode puts
in the output (there are A LOT!).
Attachments
PWM - CCP and ECCP.fcf
(14.17 KiB) Downloaded 805 times

blipton
Posts: 1
Joined: Sun Feb 10, 2013 12:40 am
Contact:

Re: All 5 PWM CCP and ECCP channels program

Post by blipton »

Are components the same thing as macros? I'm a bit new to this and not sure how custom user code* fits with what's generated by the tool..

For example, how can I change the frequency or period without macros? I see a PWM object in the panel window, and right clicking it I see an option for Custom(ize) (Componenet) Code, however this seems to modify only the macro name. It says Inbuilt & Private.. does this mean I'm not able to generate c-code, modify it, and use the modified version?

*

Code: Select all

option_reg = 0b11000000; //xxxxx000 - prescaler 1:2 - I think
pr2 = 0b11111111; //use timer 2 - I think
t2con = 0b00000100; //set timer 2 prescaler to 1:2 - I think
clear_bit(apfcon, 6); //use alt pin E0
clear_bit(apfcon, 0); //use alt pin C1
ccp1con = 0b00001100; //use standard PWM mode - page 234
ccp2con = 0b00001100; //use standard PWM mode - page 234
ccp3con = 0b00001100; //use standard PWM mode - page 234
ccp4con = 0b00001100; //use standard PWM mode - page 234
ccp5con = 0b00001100; //use standard PWM mode - page 234

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: All 5 PWM CCP and ECCP channels program

Post by dazz »

Hi
There are two types of macro, one type is the CALL component macro, these are used to control components and vary from a simple Led on or led off, to more complex one that enable components such as I2C or lcd, these take care of the timing and control code, ie Pwm SetDutyCycle10bit is 30 odd lines of code, using the call component macro, you select the component ,in this case pwm(0) select what you want it to do in this case SetDutyCycle10bit then call a variable for the values etc. in your flowchart you will see 1 call macro. All the hard coding has been done for you
The other type of macro is a user defined one, these are used for all sorts of things ie you have a repetitive task to do like say flash an led, in flowcode you would add 2 outputs and 2 delays(simplist form) this will add 4 i cons to your flowchart and if called 10 times then your flowchart will become quite large to read, where as if you put the flash routine in a user macro, you add one icon every time you want to call it, the advantage of user macros is if you had a specific task to do say read a temperature at defined intervals and set an output, this could be saved as a macro and reused in other programs as required, if you didnt use a macro you would have to add everything to each flowchart you make where you need that task doing.

in the customise component code window theres a ? at the bottom this will bring up the help file, search the forums as there are a few posts regarding the modifying of the custom code

Another option would be to use a C icon and add your custom code to that(have a look at the flowchart in the post above yours) this uses the C code icon.

Personally i would have a go with the call component macros as these work fine for 99% of code we need, then have a look at the component and cal c files to see how macros and c intereact( these can be found in your flowcode/v5 component and cal folders)
before opening the c files make a copy of the ones you want to look at on your desktop(never open them directly in your flowcode folders) as that way if you accidently make changes the originals will be preserved.

Can you also please sign up to the relevant forums, click on the link im my sig, as this will allow more help as differrent versions of flowcode have slightly differant ways of doing things, and you will benefit from more specific help

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: All 5 PWM CCP and ECCP channels program

Post by dazz »

Hi
I had a few spare hour today, and found this topic http://www.matrixmultimedia.com/mmforum ... 46&t=11871
open the flowchart Benj has posted then open a new one and add an lcd component, click on custom code for both and look at the differences , this should explain better than words
Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

Post Reply