Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16F628 PWM

Status
Not open for further replies.

Fletcher

New Member
Im trying to get the PWM module of this controller working, but im not getting any signal out of RB3.

Ive made sure RB3 is set as an output and ive put this into my setup routine:

Code:
MOVLW 0X3D
MOVWF PR2             ;set period
BANKSEL TMR2
CLRF TMR2              ;clear timer 2
MOVLW 0X06
MOVWF CCPR1L       ;set duty cycle
MOVLW 0X03
MOVWF CCP1CON    ;setup for PWM
MOVLW 0X07
MOVWF T2CON         ;set prescaler/postscaler and enable timer2

anything im missing?
 
Fletcher said:
Im trying to get the PWM module of this controller working, but im not getting any signal out of RB3.

Ive made sure RB3 is set as an output and ive put this into my setup routine:

Code:
MOVLW 0X3D
MOVWF PR2             ;set period
BANKSEL TMR2
CLRF TMR2              ;clear timer 2
MOVLW 0X06
MOVWF CCPR1L       ;set duty cycle
MOVLW 0X03
MOVWF CCP1CON    ;setup for PWM
MOVLW 0X07
MOVWF T2CON         ;set prescaler/postscaler and enable timer2

anything im missing?

Have at look at my PWM 'tutorial', it uses the 16F876, buts it's the same for the 16F628 - except you don't have two of them!.
 
Thanks, ive worked it out, i was setting ccp1con wrong.

Why do you use AND and OR commands to set values?[/code]
 
Fletcher said:
Thanks, ive worked it out, i was setting ccp1con wrong.

Why do you use AND and OR commands to set values?

Simply so it only changes the bits we want to, for the tutorial example it doesn't matter (as we're not using the other bits for anything) - but in a real world use some of the other bits might be used elsewhere, this way the code will still work without any changes. As you also probably noticed, I spaced the different sections apart - just to make it clearer to understand for the tutorial - by breaking it down into smaller sections you can easily look at each piece independently.
 
PWM max freq ?

Nigel,please tell me what is the max freq for full 10 bits resolution of PWM ?

Thanks

Don Mario
 
Re: PWM max freq ?

ciombe said:
Nigel,please tell me what is the max freq for full 10 bits resolution of PWM ?

It's all explained in the datasheet, in fact page 65, table 11-4 even gives a list of various frequencies under different conditions - including 10 bit PWM, where a 20MHz clock gives a maximum frequency of 19.53KHz.
 
Status
Not open for further replies.

Latest threads

Back
Top