I posted this to comp.arch.embedded, but the only suggestion I got was that timer 2 was not enabled, but that's why I put in the : BSF T2CON,TMR2ON near the end. Does anyone here have any thoughts please? ================================================================== I'm having problems with the PWM module on a PIC 16F627, and I wondered if anyone could help please.
The PIC is clocked at 4MHz, and I've got 6 LEDs on port B, including RB3/CCP1.
I can write simple light-chaser programs, but I'm trying to dim the LED on CCP1, but it is either on, or its off. My program looks like this:
RESET MOVLW B'00000111' ;Disable Comparator modules MOVWF CMCON
BSF STATUS,RP0 ;Switch to bank 1
;Disable pull-ups ;INT on rising edge ;TMR0 to CLKOUT ;TMR0 Incr low2high trans. ;Prescaler assign to Timer0 ;Prescaler rate is 1:256 MOVLW B'11010111' ;Set PIC options MOVWF OPTION_REG ;Write the OPTION register.
CLRF INTCON ;Disable interrupts MOVLW B'11000000' ;RB7 & RB6 are inputs. MOVWF TRISB ;RB5...RB0 are outputs.
MOVLW 0xFF ; all RA are inputs MOVWF TRISA
MOVLW 100 ; set period for PWM MOVWF PR2
BCF STATUS,RP0 ; Switch Back to Bank 0
MOVLW 5 ; set duty cycle (very low) MOVWF CCPR1L
CLRF T2CON ; Reset prescale and postscale to 1:1
MOVLW B'00001100' ; Set PWM mode MOVWF CCP1CON
BSF T2CON,TMR2ON ; enable TMR2
LOOP GOTO LOOP
Just lights the LED on RB3
Any thoughts anyone please?