Alright, last question of the day, I promise!
This is the main loop code. It works fine holding the current limit by pulse skipping. The current limit is set by comparing the ADC reading to a value stored in fb, 205 in this case, or about 175mA for this application.
The problem comes when the down button is pressed. Instead of lowering fb by 1 it goes to 100% duty cycle, and my current goes as high as the current limit is set on my bench power supply and I have to yank the power.
I thought by lowering, or raising the value in fb, I would be able to control the current limit? What is going on?
Code:main: If PORTB.6 = 1 then fb = fb - 1 If fb => 205 then fb = fb endif endif adcin 1, temp If temp > fb then final_duty = final_duty - 1 IF final_duty = 0 then final_duty = final_duty endif endif If temp < fb Then final_duty = final_duty + 1 If final_duty = 44 then final_duty = final_duty endif endif CCP1CON = %00111100 PR2 = 44 high_duty=(final_duty>>2) 'high 6 bits in CCPR1L low_duty=(final_duty<<6) 'low two bits for CCP1CON low_duty=(low_duty>>2) 'shift back to CCP1CON<5:4> low_duty.3=1 'PWM configuration bit low_duty.2=1 'PWM configuration bit CCPR1L=high_duty CCP1CON = $0C T2CON = 4 goto main




Bookmarks