Hey guys, will this work?


Closed Thread
Results 1 to 27 of 27

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    HPWM limit is as stated in your manual. To reach higher frequency, you need to write the PWM register manually. Use PICMultiCalc to find PR2 and Timer Prescaller value, then plug the DutyCycle values in CCP1CON and CCPR1L registers... double check your datasheet to confirm.

    For Buck converter, usually the higher the better for reducing coil and capacitors size.

    Make sure your ADCONx setting don't interfer with PBP ADCINs defines. You may want to place your define after those ADCONx lines, or get rid of ADCIN. Once again PICMultiCalc may give you some hints about min acquisition time and faster clock conversion source.... which is probably a must for buck converter. Don't forget to check the Resolution for the frequency you choosed. @8Mhz & 200KHz, you should have something like 7 bit of resolution.. 40 dutycycle steps... not bad, not good, depending how fancy you want it.

    In some case it's not a so good idea to use a PIC for that, just for the reaction time and what your PIC will also need to do apart the voltage regulation.
    Last edited by mister_e; - 11th May 2009 at 20:32.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Hmm, eventually I have to get this running over 100kHz, so I will need to learn how to manually write to the registers and preload timers etc. I have never done this.
    All the links I've come across for the multicalc are dead. I had it once but lost it at some point.
    There is not much else going on with the pic really. If a pin goes high, it turns on a FET and runs the converter. Pin the goes low, it switches off. Thats it really.

    I've swapped the location of the DEFINE's.
    Other than that, at 32.767kHz, will that code do what I think it should do?

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


    Did you find this post helpful? Yes | No

    Default

    In theory it should work. Theory is always theory

    PicMultiCalc download
    http://www.picbasic.co.uk/forum/atta...7&d=1225550328

    Probably you can get some inspiration of the following
    http://www.picbasic.co.uk/forum/show...0&postcount=10
    Last edited by mister_e; - 11th May 2009 at 20:42.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Ok, so using the calc I get PR2 = 9, duty register = 20 and with a 1:1 prescaler.

    Is this about right?:

    Code:
    OSCCON = $70
    define osc 8
    
    CSET   VAR WORD 'CURRENT SET
    CSEN   VAR WORD 'CURRENT SENCE  
    DUTY   VAR wORD 'HPWM 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 (3=rc)
    Define  ADC_SAMPLEUS    10    	' Set sampling time in uS
    
    
    'DUTY = 30 'SET INITIAL OUTPUT CURRENT HIGH TO ENABLE FAST STARTUP 
    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=%00001100 | (dUTY<<5)       ' set PWM mode and store the 
                                        '   2 LSB of duty
    
    
    
    
    LOOP:
    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
    CCPR1L = duty>>2                    ' MSB of duty cycle value
    CCP1CON=%00001100 | (dUTY<<5)       ' set PWM mode and store the 
                                        '   2 LSB of duty
    
    'HPWM 1,DUTY,32767 'OUTPUTS THE DUTYCYCLE AT 32.767KhZ
    GOTO LOOP

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


    Did you find this post helpful? Yes | No

    Default

    Almost... but no cigar. Check CCP1CON for YOUR particular PIC. CCP1CON is a bit different on this one (and I think my example was false anyway ... dooh) as usual, MicroChip can't be consistent between all their PIC model. Good idea to release a datasheet for each and every different model though

    Code:
    CCP1CON=%00001100 | (Duty<<4)
    Last edited by mister_e; - 11th May 2009 at 21:38.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    I did, it looks the same to me. I must have missed something.

    bit 7 and 6 are 00 = Single output; P1A modulated; P1B, P1C, P1D assigned as port pins

    bit 5 and 4 are the two LSbs of the PWM duty cycle. The eight MSbs are found in CCPR1L. I guess I do not know what to put in here or how to find out what should go in here. I thought duty>>2 took care of this.

    and 3 - 0 are 1100 = PWM mode; P1A, P1C active-high; P1B, P1D active-high

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


    Did you find this post helpful? Yes | No

    Default

    The change is above... <<4 instead of <<5... but as i said... <<5 was wrong anyway... not sure why, but wrong anyways... few years after... no one complaint

    It is more code efficient... and obviously safer to use
    CCPR1L = duty>>2
    CCP1CON.4=Duty.0
    CCP1CON.5=Duty.1

    unless you'll screw up the CCP module on that 18F (think about the bit <7:6> of CCP1CON when duty value change). This was my major point here.
    Last edited by mister_e; - 11th May 2009 at 22:01.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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