![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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. Cheers Bryan
__________________ " The only way to avoid human error is to avoid the use of humans" | |
| |
| | #2 |
|
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
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
This might get you started. Mike. | |
| |
| | #3 |
|
You might try my PWM 'tutorial', basically a simple demonstration of how to set the PWM up on a 16F876 - the 16F88 will be almost identical.
| |
| |
|
| Tags |
| assembly, examples, pwm |
| Thread Tools | |
| Display Modes | |
| |