Hey guys, will this work?


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    Well the little guy is sick and I got about 4 hours sleep last night.

    Havent tried this yet but I came up with this alternative and included Darrels changes.

    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
    GOSUB NewDuty                '
    PAUSE 1                         
    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
            CCPCON.7 = 0
            CCPCON.6 = 0
            CCPCON.3 = 1
            CCPCON.2 = 1
            CCPCON.1 = 0
            CCPCON.0 = 0              
            RETURN

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    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?

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Does this work OK?
    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
    A low-pass filter on each A/D input would also help.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    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

Similar Threads

  1. PortA Doesn't Work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 11
    Last Post: - 8th September 2015, 18:41
  2. pls help me verify my code not work, why???
    By chai98a in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th January 2010, 09:19
  3. Can't get POT work on P12f675 - Newbie
    By berslan in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th March 2008, 21:22
  4. How to set ICD-2 clone to work with PBP?
    By G-R-C in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th October 2006, 02:50
  5. Pin RA4 doesn't work
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 12:03

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts