Truncated match.
PICList
Thread
'Having trouble with getting pwm to work PIC16c74'
1996\08\10@012804
by
Greg Wallace
Neil wrote:
> I have just tried using the PWM module on the PIC 16c74.
>Unfortunately I haven't had any positive results. It seems
>straight forward, perhaps I am missing something.
>Here are the steps I took.
. . . . . . .
>But RC1 remains a standard I/O pin without any PWM output
Hi Neil,
Have you set CCP1 mode bits for PWM (in the CCP1CON register)?
Bits 2 and 3 should be set for PWM mode.
Also note that CCP1 module maps to RC2 and CCP2 maps to RC1.
You also mention not being able to utilise TMR2 if RC1 and RC2 are
standard I/O pins. I believe this is incorrect. TMR2 is only
associated with RC1/2 if CCPx module is in PWM mode. Similarly for
TMR1 and compare mode.
Hope this is useful,
Greg
1996\08\10@021259
by
Ray Gardiner
|
> I have just tried using the PWM module on the PIC 16c74.
> Unfortunately I haven't had any positive results.
-- See Sample code at end of message --
>
>Another quick question. Due to the internal hardware setup,
>it would seem to be that one cannot use Timer2 for another
>application if one wants to use RC1 and RC2 as standard I/O
>pins.
I think you can. Timer2 output can drive the SSP baud rate
generate interrupts etc, etc.
>By the way I am using the PWM to control a 12vdc fan speed.
>RC1 will feed a mosfet which switches the negative rail of
>the fan. If anyone is interested I can post the source code.
>
Don't forget the flywheel diode!
------------ Sample PWM Code for the 16c74 --------------
Here is the code that I have used in a couple of
recent applications, two routines here are InitPWM and PWMset.
FREQ equ 70
; This is written to PR2 to set frequency desired, TMR2
; increments until it reaches PR2 and then resets to 0
; Also need to set prescale bits in T2CON as required
; This divides the clock going into TMR2 so really sets
; the range over which PR2 will adjust the frequency.
; The resolution and frequency are variable over a wide
; range from 4.5bits to 10 bits and from 1Khz to 200Khz
; There is a table in the MicroChip DataBook that describes
; the options, the only thing not really clear from their
; notes is that PR2 can have other values other than FF,7F,5F
; Also if you use prescale other than 1, then the resolution
; drops. I have stuck with 10bit high resolution mode, which
; suits my application. Which required high resolution but
; limits duty cycle.
;
InitPWM
; Initialize the CCP1 counter/timer block to generate
; 10 bit pwm. for this code the actual PWMvalue is 8 bit
; this means maximum duty cycle will be 25%
;
movlw b'00000100' ; timer2 on prescale=1,postscale=1
movwf T2CON
movlw b'00001100' ; pwm MODE
movwf CCP1CON
bsf Status,Pagesel ; select page 1
movlw FREQ ;
movwf PR2 ; set up frequency
bcf Status,Pagesel ; back to page zero
movlw 0
movwf CCPR1L ; zero to start with
return
PWMset
; Takes the PWM value in PWMvalue and sets the PWM output
; Preserve PWMvalue, for control routines. So Use a temp
; location to rotate lsb bits out
movf PWMvalue,w
movwf PWMtemp
bcf Status,Carry ; PWM.8=0
bcf CCP1CON,4 ; default PWM.0 to 0
rrf PWMtemp,same ; rotate lsb to carry
btfsc Status,Carry ;
bsf CCP1CON,4 ; PWM.0=PWMvalue.0
bcf Status,Carry ; PWM.9=0
bcf CCP1CON,5 ; default PWM.1 to 0
rrf PWMtemp,same ; rotate lsb again
btfsc Status,Carry ;
bsf CCP1CON,5 ; PWM.1=PWMvalue.1
movf PWMtemp,w ; PWM.(9..2)
movwf CCPR1L ; set PWM output bits 2..9
; on the next cycle
return
Ray Gardiner, 104 Macintosh Street, Shepparton, Victoria 3630, Australia
spam_OUTrayTakeThisOuT
netspace.net.au
1996\08\10@024916
by
Neil Gandler
> Have you set CCP1 mode bits for PWM (in the CCP1CON register)?
> Bits 2 and 3 should be set for PWM mode.
> Also note that CCP1 module maps to RC2 and CCP2 maps to RC1.
>
Dooh! That was it. Thanks. Can't believe it was this simple!
Neil
More... (looser matching)
- Last day of these posts
- In 1996
, 1997 only
- Today
- New search...