Newbie PWM problem with PIC 16F627
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
Newbie PWM problem with PIC 16F627

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> Embedded System
Author Message
Deep Reset
Guest





Posted: Mon Jan 03, 2005 9:18 pm    Post subject: Newbie PWM problem with PIC 16F627 Reply with quote

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?

--
Deep Reset
Back to top
Wolfgang Mahringer
Guest





Posted: Wed Jan 05, 2005 12:14 am    Post subject: Re: Newbie PWM problem with PIC 16F627 Reply with quote

Dear Deepy,

Deep Reset wrote:

Quote:
I'm having problems with the PWM module on a PIC 16F627, and I wondered if
anyone could help please.

[ sample code snipped ]

Any thoughts anyone please?

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

HTH
Wolfgang


--
From-address is Spam trap
Use: wolfgang (dot) mahringer (at) sbg (dot) at
Back to top
Deep Reset
Guest





Posted: Thu Jan 06, 2005 5:42 pm    Post subject: Re: Newbie PWM problem with PIC 16F627 Reply with quote

Wolfgang Mahringer wrote:
Quote:
Dear Deepy,

Deep Reset wrote:

I'm having problems with the PWM module on a PIC 16F627, and I
wondered if
anyone could help please.

[ sample code snipped ]

Any thoughts anyone please?

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

HTH
Wolfgang


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

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.

TIA
Deep.
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> Embedded System All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB