MikroBasic to PBP Pro: Boost mode SMPS


Closed Thread
Results 1 to 29 of 29

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    I used it once for logging and removed it. I did compensate for the write period. I actually slowed it down a lot so I could see what was happening at individual increments.

    I tried i = fb and incrementing the i byte and not the fb byte and it works. I get a smooth up and down output now. It will current limit at each brightness setting.

    So, there is the last problem to resolve:

    When ramping up I am using duty cycle to increase brightness from zero to full on regardless of where the current limit is set at. The problems are that when I save the new current limit during the main loop, I get flashing as the output goes off during the write command and the pause 10 after the write command. Therefore, I can either write to EEPROM and ramp up to the newly set current limit, or have no flashing and ramp up to full output, go to the main loop and drop straight back to the new current limit. Both options dont look very good.

    I am not sure how to write to EEPROM and stop it from flashing.

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    I think you may need some logic in there to check for button release. As it looks now, it will run the fb = fb - 1 VERY fast, and every time through the loop when you press the button. Chances are you will not release the button before lots of main loop runs.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

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


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    That is very true. I added a pause of 50mS in each button press if-endif routine.

    The problem with that is the LED's flicker each time the button is pressed. Not sure why the pause should effect the PWM. I thought that the PWM was continuous unless you turned it off with CCP1CON = 0. That was my basic understanding anyway and the theory behind the idea. Run pwm continuously and vary the duty cycle based on a target current limit and the actual feedback results. Add or subtract by one the duty cycle number until the current limit is achieved.
    Also the LED's flicker when ever there is a WRITE command so I created a counter that only writes the value every 25000 cycles.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,171


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    Even with 25000 cycles EEPROM will wear out relative soon.

    About the button,maybe you can try to wait for the button release before proceed.

    Also the the idea of add or subtract one to the duty cycle in theory it will work, practically will have a lot of jitter. Here PID control may help (more complicate though).

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    I'd be willing to learn about PID's. It's something I wanted to do anyway. Have you worked with them Ioannis?

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,171


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    For something similar to what you try, but not succesfully. It just oscilated and could not fix it.

    I will try again, but am busy right now.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    After some tweaking I have this pretty much working now. I can get it to ramp up slowly to full brightness, maintain a set level, be adjusted up and down, have the new value write to EEPROM and next time it is powered up it will ramp up to the last saved level. All I want to add now is ramp down at power off. Not a problem.

    I'd like to reduce code size though. I have a lot of IF THEN's and a lot of FOR NEXT's. They are used to increment and decrement a byte value based on which level output is set.

    Code:
     rampup:l = 0
    for l = 0 to led
    if L = 0 then 
    fb = 0
    CCP1CON = 0
    ramp = 0
    portc.2 = 0
    endif
    
    
    IF L = 1 then
    fb = 10
    endif
    
    
    if L = 2 then
    fb = 45
    endif
    
    
    if L = 3 then
    pause 25
    fb = 90
    endif
    
    
    if L = 4 then
    pause 40
    fb = 130
    endif
    
    
    IF L = 5 then
    pause 50
    fb = 170
    endif
    
    
    if L = 6 then
    pause 75
    fb = 280
    endif
    
    
    if L = 7 then
    pause 100
    fb = 450
    endif
    
    
    adcin 1, temp
    If temp > fb and L > 0 then
    ramp = ramp - 1
    IF ramp <= 0 then
    CCP1CON = 0
    ramp = 0
    portc.2 = 0
    endif
    endif
    If temp < fb Then
    ramp = ramp + 1
    If ramp >= 40 then 
    ramp = 40
    endif
    endif
    If ramp > 41 then
    ramp = 0
    endif
    
    
    CCP1CON = 111100
    PR2 = 44
    high_duty=(ramp>>2)        'high 6 bits in CCPR1L
          low_duty=(ramp<<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
    
    
    pause 100
    next l
    goto main
    This is the ramp up routine that seems to work well. The ramp down is similar. Any way to reduce this block of code in size?

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