Poor little guy. :sad:
As for the proposed additions ...
You don't want to do that.
The idea is to minimize the glitches, not create more.
Leave the module in PWM mode and just change the dutycycle.
<br>
Poor little guy. :sad:
As for the proposed additions ...
You don't want to do that.
The idea is to minimize the glitches, not create more.
Leave the module in PWM mode and just change the dutycycle.
<br>
DT
Hmm, well it dosent work. It's all over the place and then goes high and stays high. I have to power down to reset because adjusting the CSET pot does nothing to gain a recovery. Also, adc value for CSET does very little to alter the duty cycle.
Is my thinking right here? Will this try to find the right duty cycle so CSEN = CSET?
Refresh your duty cycle only when it need to, unless you'll have problem.
try something like
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.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 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 19:31.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Does this work OK?
A low-pass filter on each A/D input would also help.Code:OSCCON = $70 DEFINE OSC 8 CSET VAR WORD 'CURRENT SET CSEN VAR WORD 'CURRENT SENCE DUTY VAR WORD 'PWM DUTY CYCLE O_Duty VAR WORD 'previous Duty-cycle MinDuty CON 2 'minimum duty cycle MaxDuty CON 40 'maximum duty cycle ADCON0 = %00011001 ADCON1 = %00001111 ADCON2 = %10111111 TRISA = %00000000 TRISB = %00110011 Define ADC_BITS 10 ' Set number of bits in result Define ADC_CLOCK 3 ' Set clock source (5=fosc/16) Define ADC_SAMPLEUS 10 ' Set sampling time in uS CSET = 0 CSEN = 0 DUTY = 20 ' duty value for 50% duty cycle PR2 = 9 ' T2CON = %00000100 ' timer2 on, prescale 1:1 CCPR1L = DUTY>>2 ' MSB of duty cycle value CCP1CON.4=DUTY.0 ' set PWM mode and store the CCP1CON.5=DUTY.1 ' 2 LSB of duty CCP1CON = %00001100 LOOP: ADCIN 6, CSET 'READ VALUE OF CURRENT SET POT ADCIN 4, CSEN 'READ VALUE OF CURRENT SENSE ' test for CSEN > CSET*2 IF CSEN > (CSET*2) THEN ' minimize short-cycling (increase as needed) IF DUTY > MinDuty THEN ' don't allow below minimum duty DUTY = DUTY - 1 ENDIF ENDIF IF CSEN < (CSET/2) THEN IF DUTY < MaxDuty THEN ' don't allow greater than max duty DUTY = DUTY + 1 ENDIF ENDIF IF O_Duty = DUTY THEN LOOP ' does duty-cycle need updating? O_Duty = DUTY ' yes. copy last duty value for next comparison CCP1CON.4=DUTY.0 ' set PWM mode and store the CCP1CON.5=DUTY.1 ' 2 LSB of duty CCPR1L = DUTY>>2 ' MSB of duty cycle value GOTO LOOP
At 200khz, you only get a Duty range of 0-40.
Not going to be a very precise regulator with that.
Your previous examples were at 32.767khz, which PicMultiCalc shows 0-244 duty range (better). But like mister_e said, you'll need to limit the range.
With a 20mhz crystal you can get 0-610 @32khz, or 0-100 @ 200khz.
<br>
DT
Guys thanks for the ideas and snippets. I have not been around today to work on this. I need to up the frequency to 300KHz now to reduce inductor size and value. I was going to use a 20mhz resonator but just wanted to get something up quick and dirty so I used the internal osc at 8mhz.
My schematic is a scribble on a piece of paper at the moment, but its essentially a classic buck converter design that could be found anywhere on the web. I think some of the problem is ripple voltge on the 5v line. This changes the internal vref of the adc.
I'll mill or get the boys in the shop to etch me a pcb in the morning so I can load up on the capacitance and cut down on the noise.
Oh, last night, I killed 12 Osram Dragon infra red led's that are not mine. Oops. I think they are something like $15 a piece![]()
Bookmarks