So here is the latest update in the IR receiver. I think the transmitter is good. It sends consistent signals almost 100% of the time. I checked it with the pickit analyzer. The receiver is wasting too much time reading the IR signal so I get a small pause in the pwm that causes the motor to pulse. The solution is to turn on the pins of all the PWM channels using TMR0 interrupt. Then throughout the program call a small subroutine that does an addwf of the TMR0 to the value of each channel and checks the flag. If the flag is tripped then turn that channel off. this allows me to constantly read the IR input signal with almost no interruption. It is working smoothly with leds, which I suppose will be even smoother with DC motors. This program is on a circuit with a pot and two leds, nothing more. So now I have to adapt this method to the actual IR receiver program and scrap my old receiver program.
Code:
;learning to do pwm with tmro 12f675
list P=12f675
#include <p12f675.inc>
__config _INTRC_OSC_NOCLKOUT & _BODEN_OFF & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CPD_OFF & _CP_OFF
ERRORLEVEL -302
cblock 20h
pwmcounter, channel1, channel2
endc
ORG 0000h
goto setup
ORG 0004h
movlw 0x03 ;interrupt turns on motors then
movwf GPIO ;call pwm keeps checking to see it's
BCF INTCON,2 ;time to shut them off
RETFIE ;reset interrupt
setup
bsf STATUS,RP0 ;bank 1
movlw 0x3c
movwf ANSEL
movlw 0x3c
movwf TRISIO ;set I/O
movlw 0xd0
movwf OPTION_REG ;set tmr0
bcf STATUS,RP0
movlw 0x07 ;turn off comparitors
movwf CMCON
movlw 0xa0
movwf INTCON ;set interrupt
start
movlw 0x09
movwf ADCON0
call pwm
call pwm
call pwm
call pwm
call pwm
call pwm
call pwm
bsf ADCON0,1
call pwm
waiting
btfsc ADCON0,1
goto waiting
call pwm
call pwm
call pwm
movf ADRESH,0
movwf channel1
movlw 0x0d ;change to read channel 2 potentiometer
movwf ADCON0
call pwm ;time for adc recharge
call pwm
call pwm
call pwm
call pwm
call pwm
call pwm
bsf ADCON0,1
waiting2
btfsc ADCON0,1 ;waiting for adc
goto waiting2
call pwm
call pwm
call pwm
movf ADRESH,0
movwf channel2
goto start
pwm
movf channel1,0
addwf TMR0,0
btfss STATUS,C ;test flag if set then turn off GPIO,0
bcf GPIO,0
movf channel2,0
addwf TMR0,0
btfss STATUS,C
bcf GPIO,1
return
end
edit: code updated