; FILE: coillpV1.asm
; AUTH: Keith Sevcik
; DATE: 5/2/03
; DESC: This program generates a PWM waveform to a voice coil.  The leads of the
;	coil should be hooked up to output pins B0 and B1.  At any one point
;	one pwm is generating a PWM signal while the other is kept at ground.  By
;	alternating which pin is ground and which is signal, a positive and negative
;	PWM signal can be achieved, thus getting the maximum deflection from the coil.
; NOTE: Tested on PIC16F84-04/P

;----------------------------------------------------------------------
;	cpu equates (memory map)

	list	p=16f84
	radix	hex

;----------------------------------------------------------------------

portb	equ	0x06		; port b equate
duty	equ	0x0c		; length of duty cycle
temp	equ	0x0d		; length of duty cycle

;---------------------------------------------------------------------

c	equ	0		; status bit to check after subtraction

;---------------------------------------------------------------------

	org	0x000

start	movlw	0x00		; load W with 0x00 make port B output
	tris	portb		; copy W tristate to port B outputs
	movlw	0x00		; fill w with zeroes
	movwf	portb		; set port b outputs to low
rstrt	movlw	d'0'
	movwf	portb
	movlw	d'255'
	movwf	duty
b0loop	movf	duty,w
	movwf	temp
	bsf	portb,0
pwm1a	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	temp	
	goto	pwm1a
	movlw	d'255'
	movwf	temp
	movf	duty,w
	subwf	temp,f
	bcf	portb,0
pwm1b	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	temp
	goto	pwm1b
	decfsz	duty	
	goto	b0loop
	movlw	d'0'
	movwf	portb
	movlw	d'0'
	movwf	duty
b1loop	movf	duty,w
	movwf	temp
	bsf	portb,1
pwm2a	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	temp
	goto	pwm2a
	movlw	d'255'
	movwf	temp
	movf	duty,w
	subwf	temp,f
	bcf	portb,1
pwm2b	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	temp
	goto	pwm2b
	incfsz	duty	
	goto	b1loop
	goto	rstrt

;----------------------------------------------------------------------

	end

;----------------------------------------------------------------------
; at burn time, select:
;	memory uprotected
;	watchdog timer disabled
;	standard crystal (4 MHz)
;	power-up timer on
