Newbie PWM problem with PIC 16F627

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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

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


Just lights the LED on RB3

Any thoughts anyone please?

Deep Reset

Re: Newbie PWM problem with PIC 16F627
Dear Deepy,

Quoted text here. Click to load it
Quoted text here. Click to load it

Since the PWM module relys on timer 2,
you should also turn that timer on (TMR2ON in T2CON).


From-address is Spam trap
Use: wolfgang (dot) mahringer (at) sbg (dot) at

Re: Newbie PWM problem with PIC 16F627

Quoted text here. Click to load it
wondered if

Thanks for the reply, but that is what (I think) the "BSF T2CON,TMR2ON"
just before the final loop is supposed to do. I'm pretty sure I checked
all the bit assignments. I think I need to borrow a scope, though I'm
pretty sure the LED is not PWM'ing - I lit the adjacent LED, and the
brightness looks the same.

Does anyone know if the PIC simulators allow inspection of the timer
registers? I'm not using one at the moment, just taking a
suck-it-and-see approach by blowing the code to the controller after
each code change.


Site Timeline