jeremygaughan
New Member
I'm using TMR0 to make PWM. I read the ADC then put a value in a folder. I then turn the output bits on with every interrupt then check throughout the program to see if the timer has exceeded the values from the adc. If I add the timer and the value from the adc together and they trip the flag then I turn them off. The problem I'm having is that the PWM only works for about half of the pot. I have 5k pots on both sides of the 10k to fine tune and I also get good adc resolution using other programs with this same circuit. So I believe the problem to be in my program. I have included the program and a few webshots of what the pickit analyzer is seeing on the output pins. I get what I'm seeing, but I have no idea how my program is doing that. It's like the ADC is affected by the TMR0. Any ideas?
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 0xd8
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
bsf ADCON0,1
call pwm
waiting
btfsc ADCON0,1
goto waiting
call pwm
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
bsf ADCON0,1
waiting2
btfsc ADCON0,1 ;waiting for adc
goto waiting2
call pwm
call pwm
call pwm
call pwm
movf ADRESH,0
movwf channel2
call pwm
call pwm
call pwm
call pwm
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