PDA

View Full Version : Code from PIC18F8722 to PIC18F4550



peu
- 16th January 2006, 22:25
Hi,

Important Im using 4550 because is what I have at hand, but any pic with 3 simultaneous PWM work for me

I'm experimenting with RGB leds and to test my program I used a 18f8722 VSM because I dont have the model for the 18f4550

I have the code working, mostly by following advice from Bruce (rentron) in different posts across this forum.

I dont know how to translate the 3rd PWM port I use in the 18f8722, here is my code:



DEFINE OSC 4
' Word vars for 10-bit value of each PWM duty cycle
Duty1 VAR WORD ' Channel #1
Duty2 VAR WORD ' #2
Duty3 VAR WORD ' #3
Rval var word
Gval var word
Bval var word

' Set CCPx pins to outputs
TRISC.2=0 ' CCP1 output
TRISC.1=0 ' CCP2 output (could also be assigned to RB3)
TRISG=0 ' CCP3 output
trisa=%00000111

' Set CCP modules to PWM mode
CCP1CON = %00001100 ' Mode select = PWM
CCP2CON = %00001100 ' Mode select = PWM
CCP3CON = %00001100 ' Mode select = PWM

' Set period up for 1.22kHz PWM freq
PR2 = $7F

' Set TMR2 up for 1:16 prescale & turn it on
T2CON = %00000110 ' TMR2 ON 1:16 prescale

mainloop:


Adcin 0, Bval
serout porta.3,2,[#Bval,"."]
Adcin 1, Rval
serout porta.3,2,[#Rval,"."]
Adcin 2, Gval
serout porta.3,2,[#Gval,"."]


serout porta.3,2,[10,13]

Duty1 = Bval *2
CCP1CON.4 = Duty1.0 ' Setup 10-bit duty cycle as
CCP1CON.5 = Duty1.1 ' a 10-bit word
CCPR1L = Duty1 >> 2

Duty2 = Rval *2
CCP2CON.4 = Duty2.0
CCP2CON.5 = Duty2.1
CCPR2L = Duty2 >> 2

Duty3 = Gval *2
CCP3CON.4 = Duty3.0
CCP3CON.5 = Duty3.1
CCPR3L = Duty3 >> 2

Goto mainloop
End


I dont know how to translate CCP3CON.

Help needed & appreciated.

Thanks


Pablo

peu
- 17th January 2006, 13:48
please help

Bruce
- 17th January 2006, 16:36
I dont know how to translate CCP3CON
There is no CCP3CON register on the 18F4550. CCP1CON configures PWM for CCP1. CCP2CON configures PWM for CCP2

You can have up to two standard PWM outputs. CCP2 on RC1 or RB3 depending on config fuse settings for CCP2MX in CONFIG3H, and CCP1 on RC2.

Or you can use the ECCP module with P1A, P1B, P1C and P1D for motor control driving an H-bridge.

Take your time and read through 18F4550 data sheet for PWM setup. It's really not that hard. A little time reading & experimenting with your 18F4550 is all you need to figure it out.