Would really appreciate some help on getting the 3rd PWM to work on my PIC16F777.
I'm using the three PWM's to control R G B led strips. My PortB.5 will not light!
The code I'm using - primarily from this forum is below. I know that the circuit is fine, as all three colours work when I manually switch the pins high and low.
I've stripped the code down - for simplicity - to just flash through the three colours... but alas only ever get two!
Many thanks in advance,Code:'-- Setup --------------------------------------------------------------------- @ DEVICE PIC16F777, INTRC_OSC_NOCLKOUT DEFINE OSC 8 OSCCON = %01110010 'see data sheet for INTRC speed setting ' Word vars for 10-bit value of each PWM duty cycle DutyR VAR WORD ' Channel #1 DutyG VAR WORD ' #2 DutyB VAR WORD ' #3 ' Set CCPx pins to outputs TRISC.2=0 ' CCP1 output TRISC.1=0 ' CCP2 output (could also be assigned to RB3) TRISB.5=0 ' CCP3 output ' 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 = $FF ' Set TMR2 up for 1:16 prescale & turn it on T2CON = %00000110 ' TMR2 ON 1:16 prescale '-- Program --------------------------------------------------------------------- MainRoutine: dutyR = 719 dutyg = 0 dutyb = 0 gosub colourset PAUSE 1000 dutyR = 0 dutyg = 719 dutyb = 0 gosub colourset PAUSE 1000 dutyR = 0 dutyg = 0 dutyb = 719 gosub colourset PAUSE 1000 goto MainRoutine '------------------------------------------------------------------------------- colourset: CCP1CON.4 = Dutyr.0 ' Setup 10-bit duty cycle as CCP1CON.5 = Dutyr.1 ' a 10-bit word CCPR1L = Dutyr >> 2 CCP2CON.4 = Dutyg.0 CCP2CON.5 = Dutyg.1 CCPR2L = Dutyg >> 2 CCP3CON.4 = Dutyb.0 CCP3CON.5 = Dutyb.1 CCPR3L = Dutyb >> 2 return
orjon.
Bookmarks