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

    The code below will flash the LED but not create a pwm output. I'm guessing its because there are fractions and not integers to work with thus creating 0's and other odd results.
    The convert to voltage portion works fine - I changed it, but the rest needs work still.


    Code:
           temp=0      ADCIN 0, temp
          'write 40, temp
          
    'convert to voltage
          v_feedback=temp                                                 'put ADC in float
                                                                                   'v_supply=v_feedback/1024
          v_supply = 1024/v_feedback * 10                            'find supply % of vref
                                                                                   'v_supply=v_supply*supply_multiplier  'find supply volts
          v_supply = v_supply * supply_multiplier / 10
          write 60, v_supply
          
    'calculate rise time
          t_rise=L_Ipeak / v_supply                                       'find rise time @ supply volts for L/Ipeak
                                                                                   ' = 68/24 = 2.833uS (example = 24vin)
    'calculate CCPR1L:CCP1CON<5:4>
          SMPS_duty=t_rise*osc_freq                                    'find duty cycle value
                                           '2.833*48 = 136
          final_duty=SMPS_duty                                            'convert to byte
          
    'calculate period
          t_period=t_rise*133/100                                         'dutycycle = .75period
                                                                                    '2.833*133/100 =  3.767uS
    'calculate PR2
          SMPS_period=(t_period/period_multiplier)                   'find period value
                                                                                   '3.767/(4/48) = 45.2
          final_period=SMPS_period-1                                    'put in byte
                                                                             ' = 44.2
    'put in register masks
          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
    
    
    
    
    main:
    CCPR1L=high_duty       'flash LED to show alive
    CCP1CON=low_duty
    portc.0 = 1
    pause 100
    portc.0 = 0
    pause 100
    GOTO main

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,175


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    I see an error on your PBP program

    Code:
    define OSC 48temp VAR word
    should be

    Code:
    DEFINE OSC 48
    temp VAR word
    though I had no time to check all of your code.

    Ioannis

  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

    Oops - thats a copy/paste error!!

    Basically, I need help setting up a CCP for PWM operation - I have never done it.

    Searching for examples...

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


    Did you find this post helpful? Yes | No

    Default Re: MikroBasic to PBP Pro: Boost mode SMPS

    This is for 16F1827 chip I use:

    Code:
      CCP1CON = %00111100          'Control of CCPx modules
      CCP2CON = %00000000
      CCP3CON = %00000000
      CCP4CON = %00000000
      CM1CON0.7=0
      CM2CON0.7=0
      
      CPSCON0 = 0
      CPSCON1 = 0 
      
      DEFINE CCP1_REG PORTB
      DEFINE CCP1_BIT 3    
      ccptmrs=0
      pr2=249
      ccp1con=$0C
      t2con=%00000110
    
    DACCON0 = 0
    HTH,
    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 didnt know you needed to add defines. I assume CCP1_BIT 3 = PORTB.3 in your example?
    Is DACC0N0 = 0 the same command as CMCON = 7? (turn off all comparators) or is it turn off all ADC's?

  6. #6
    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

    Ok, I understand everything up until this:

    ccp1con=$0C

    The pwm is already turned on as per the CCP1CON line.
    Last edited by jmgelba; - 25th October 2011 at 18:37.

  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

    Frustrated. Not sure what I am missing now. The CCP1 pin is always high, LED flashes correctly.

    Code:
    DEFINE OSC 48
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    DEFINE CCP1_REG PORTC
    DEFINE CCP1_BIT 2   
    
    
    final_period var byte
    final_duty var byte
    high_duty var byte
    low_duty var byte
    
    
    ADCON1 = 00001011
    ADCON2 = 00000011
    
    
    TRISA = 00001111
    TRISB = 01110000
    TRISC = 00000000
    CMCON = 7
    
    
    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
    
    
    main:
    PORTC.0 = 1
    pause 500
    PORTC.0 = 0
    Pause 500
    goto main
    Last edited by jmgelba; - 25th October 2011 at 19:39.

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