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:
I dont know how to translate CCP3CON.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
Help needed & appreciated.
Thanks
Pablo




Bookmarks