Refresh your duty cycle only when it need to, unless you'll have problem.
try something like
Code:
START:
ADCIN 6, CSET 'READ VALUE OF CURRENT SET POT
ADCIN 4, CSEN 'READ VALUE OF CURRENT SENCE
IF CSEN > CSET Then LET DUTY = DUTY - 1
IF CSEN < CSET THEN LET DUTY = DUTY + 1
if DUTY != OldDuty then
OldDuty = Duty
GOSUB NewDuty
ENDIF
GOTO Start
NewDuty:
TMR2IF = 0
while !TMR2IF : wend ; let current cycle complete
CCP1CON = 0
CCPR1L = Duty >>2
CCP1CON.5 = Duty.1
CCP1CON.4 = Duty.0
RETURN
You'll probably need to allow an error margin in your IF-THEN, remember you have a 7 bits or so PWM resolution but 10Bit ADC results. Reduce your ADC resolution to 8 bit may help.
You also want to make sure you don't overflow the Duty value...
Seeing your schematic would be nice.
Last edited by mister_e; - 12th May 2009 at 18:31.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks