Hiya Guy's,
I'm on playing around with a 6 wire steppermotor and a 5804 translator/driver chip and this will be the first time I've used pwm. I'm thinking of using a 16f88 and after looking on the net for over 3 hours I'm still yet to find some examples in assembly to help me get started. I looked at the piclist but that site is so hard to find anything so if anyone has some routines to setup and run on a 16f chip I'll appreciate it as I'm a bit confused just using the datasheet.
I'm not sure if this is what you are looking for or not.
This is part of a PID servo on a 16F819.
The PWM setup is
Code:
; Set PWM Period by writing to PR2
; With 8MHz clock this will give a frequency of 31kHz
movlw 3fh
bsf STATUS,RP0
movwf PR2
bcf STATUS,RP0
; set PWM value to middle - 50/50 duty
movlw 1fh
movwf CCPR1L
; Enable timer 2 with prescaler 1
movlw B'00000100'
movwf T2CON
; Turn on PWM
movlw B'00001111'
movwf CCP1CON
The PWM value was set with the following.
Code:
movwf PWMVal
movlw B'00001111'
bcf STATUS,C
rrf PWMVal,F; Get lowest bit
btfsc STATUS,C
iorlw B'00010000'; Put in bit 4 of CCP1CON
bcf STATUS,C
rrf PWMVal,F; and bit 1 to bit 5
btfsc STATUS,C
iorlw B'00100000'
movwf CCP1CON
movfw PWMVal; remaining 6 bits to CCPR1L
movwf CCPR1L
The values above only give 8 bit resolution of the PWM. The lower bit are in CCP1CON and so mid point is 31 (1Fh).