jeremygaughan
New Member
My project is to build an infrared RC system for indoor airplanes. Many have done it before that I could copy, but I want to learn to program. What I'm did first was learn to create PWM in software using a simple circuit. Then I put a potentiometer into the circuit to adjust the speed of the motor/force of a coil "BIRD" actuator. Later I will learn how to send the information over IR. The issue that I have is that the motor is not changing speeds when I adjust the potentiometer. I suspect that I am using the addlw improperly. The idea is to subtract the value read from the capacitor discharge time from 255 and get the bit high and bit low times of my bit-bang style PWM. I have included a drawing of the circuit and my code.
Code:
;PWM project
list P=12f629
#include <p12f629.inc>
__config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF
ERRORLEVEL -302
cblock 20h
AV,BH,BL,DELAY
endc
ORG 0000h ;start here on powerup
goto START ;skip interrupt location
ORG 0004h ;interrupt location
goto AVinterrupt ;duh
bcf INTCON,2 ;reset interrupt flag to 0
RETFIE
START
movlw 0x07 ;turn off comparitors
movwf CMCON
bsf INTCON,7 ;global interrupt enabled
bsf INTCON,5 ;set timer interrupt
bsf STATUS,RP0 ;switch to bank 1
movlw 0x02 ;set prescaler
movwf OPTION_REG ;put in option register
movlw 0x00 ;set pins I/O
movwf TRISIO ;put value in tris
bcf STATUS,RP0 ;switch back to bank 0
PWM
addlw 0xFF-AV ;determine time to keep bit high
movwf BH
movlw 0x07 ;set output bit high
movwf GPIO
loop1
decfsz BH,f ;keep output bit high
goto loop1
movlw 0x04 ;set output bit low
movwf GPIO
loop2
decfsz AV,f ;keep output bit low for the rest of the 256
goto loop2
goto PWM
AVinterrupt
bsf STATUS,RP0 ;set pin to input
movlw 0x04
movwf TRISIO
bcf STATUS,RP0
clrf AV ;clear
AVloop
incf AV,1 ;add one for every time the following test results in pin still high
btfsc GPIO,2 ;test if pin still high
goto AVloop
bsf STATUS,RP0 ;set all to output
movlw 0x00
movwf TRISIO
bcf STATUS,RP0
return
end