Questions about PWM and ICD

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
serstel
Posts: 22
Joined: Thu Jan 25, 2007 1:34 am
Been thanked: 1 time
Contact:

Questions about PWM and ICD

Post by serstel »

Hello

I am using the C command ccpr2l = FCV_SPEED; to output PWM from the PIC. This command alone however does not specify the frequency of the PWM. The CCPRxl register dfines the duty cycle. The period is set by the PR2 register in conjunction with the timer prescaler. How can i set the frequency of the PWM? In addition must the FCV_SPEED variable be a byte or can it be an integer?
Also how can I do in circuit debuging? I have the EB-006 multiprogrammer. Can I do debuging within flowcode?

Serstel

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

No ICD from Flowcode yet, I'm afraid (it's on the list...).

In Flowcode, the variable should be called "Speed" and yes, it should be an integer.

To set the frequency of the PWM, you will need to write a couple of lines in a C icon that alter the values of the pr2 and t2con registers appropriately. You will need to calculate these values yourself as they are dependent on your clock frequency.

You will also need to turn the PWM on by writing to the ccp1con register. The datasheet for the PICmicro should have all the details you need.

serstel
Posts: 22
Joined: Thu Jan 25, 2007 1:34 am
Been thanked: 1 time
Contact:

Post by serstel »

I am using a pic 18F4550. I have used the C commands
ccp1con=0x12;
pr2 = 0xff;
t2con = 0x7;
This is to have timer prescaler 16 and the minimum PWM frequency.
I still can't output PWM from the two outputs ccpr1l and ccpr2l. What else must I do? :(

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:

Post by Benj »

Hello Serstel

This code is for the 18F4455 but I think it should be compatible with the 4550

C Code Block

Code: Select all

pr2 = 0xFF;
ccpr1l = FCV_DUTYR;
trisc = trisc & 0xF9;
t2con = 4;
ccp1con = 0x0C;
ccpr2l = FCV_DUTYL;
ccp2con = 0x0C;
Uses two flowcode variables for the duty cycle dutyr and dutyl.

This should get your PWMs going and then you can play around with the values to obtain the correct frequency of oscillation.

serstel
Posts: 22
Joined: Thu Jan 25, 2007 1:34 am
Been thanked: 1 time
Contact:

Post by serstel »

Hello
I put this C code into a C block between begin and end and I compile just that

pr2 = 0xFF;
ccpr1l = 32767;
trisc = trisc & 0xF9;
t2con = 4;
ccp1con = 0x0C;
ccpr2l = 32767;
ccp2con = 0x0C;

Pin RC2 which is ccp1 seems to work but pin RC1 which is ccp2 does not. Not even when I configure it for output instead of RB3 does not work.

Serstel

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

The values for ccpr1l and ccpr2l should be 8-bit values (i.e. between 0 and 255).

Also, there is a config setting for this chip that defines whether CCP2 is on RC1 or RB3.

serstel
Posts: 22
Joined: Thu Jan 25, 2007 1:34 am
Been thanked: 1 time
Contact:

Post by serstel »

Helo
I use the config setting so that the pwm goes to RC1 instead of RB3 and used 8 bit values.
The problem however persists. No output on RC1.
Basically the whole project is a C code block between begin and end with this code inside it:

pr2 = 0xFF;
ccpr1l = 255;
trisc = trisc & 0xF9;
t2con = 4;
ccp1con = 0x0C;
ccpr2l = 255;
ccp2con = 0x0C;

User avatar
Steve
Matrix Staff
Posts: 3424
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

I've just tested this code here on an 18F4455 and it works fine on both outputs, although the duty cycle is 99%.

Try setting ccpr1l and ccpr2l to 128 instead of 255 - that should give a 50% duty cycle.

If you still can't get the code working, then I can only assume the chip is broken.

Post Reply