Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 30th December 2005, 01:43 AM   #1
Default PWM examples in Assembly

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"
bryan1 is offline  
Old 30th December 2005, 03:01 AM   #2
Default

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).

This might get you started.

Mike.
Pommie is online now  
Old 30th December 2005, 09:28 AM   #3
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Reply

Tags
assembly, examples, pwm

Thread Tools
Display Modes




All times are GMT. The time now is 11:38 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker