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
Questions about PWM and ICD
- Steve
- Matrix Staff
- Posts: 3433
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
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.
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.
- 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:
Hello Serstel
This code is for the 18F4455 but I think it should be compatible with the 4550
C Code Block
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.
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;
This should get your PWMs going and then you can play around with the values to obtain the correct frequency of oscillation.
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
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
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
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;
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;