Swiching Mode Charger / PWM questions


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Sep 2013
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: Swiching Mode Charger / PWM questions

    Henrik,

    Thanks for the information and ideas. You confirmed several things I was thinking.

    I had an idea that I could up the oscillator speed and use PLL but wasn't sure. And in that regards, to enable my PLL, which of the following would I implement (or something else):

    PLLEN = ON

    or

    OSCTUNE = %11000000


    Secondly, I looked at my code again and I have the following line in my configuration section:

    OSCCON = %11100010

    Doesn't that indicate that my oscillator is already set to 8MHz? I was under the impression that I was configured for 4MHz, but again, I am the newbie at this.

    Lastly, please let me know if the following lines would get me in the ballpark of what I would like to do... or if I have any idea of what is going on yet....

    PR2 = 16 'pwm = 125000Hz (I changed my desired freq. PicCalc showed me that this freq would give me 256 steps to my pwm)
    CCPR2L = 128 'duty at approx 50% (PR2*0.50)
    TRISC.1 = 0 'make CCP2 output
    T2CON = %00000100 'start timer2
    CCP2CON = %00001100 'lowest duty bits and PWM on 2

    .... and then I would manipulate the CCPR2L register to change the duty cycle.... no??....

    Thanks again.
    Last edited by almarsh; - 23rd September 2013 at 16:11.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Swiching Mode Charger / PWM questions

    Hi,
    I don't think it'll recognise PLLEN directly so in order to enable the PLL (when using the internal oscillator) you'd do OSCTUNE.6 = 1 (set bit 6 of OSCTUNE).

    The compiler recognises all the names of all the registers but not the names of each individual bit in the registers. You can, however create an alias and use it:
    Code:
    PLLEN VAR OSCTUNE.6  ' Of course you could give it any name you like.
    PLLEN = 1
    Your OSCCON = %11100010 would result in 4MHz on the internal oscillator (it's controlled by bits 4 thru 6, which I've highlighted in red, in that register). Set those three bits to 111 to get 8MHz from the oscillator (resulting in 32MHz once the PLL is enabled).

    At 32MHz system clock and PR2=63 (not 16) you'll get 125kHz and 8 full bits (256 "steps"). But you need to "split" those 8bits so that the two lowest significant bits of your dutycycle value ends up in CCPxCON bits 4 and 5 (if you're using the second PWM module) and the upper 6 bits ends up the lower 8 bits of CCPRxL.

    So, the actual value to get 50% would be 127 or 128 but, using the CCP2 module, you do something like
    Code:
    Duty = 127
    CCP2CON.4 = Duty.0
    CCP2CON.5 = Duty.1
    CCPR2L = (Duty >> 2)
    /Henrik.

Similar Threads

  1. 18F4431 - Complementary mode PWM
    By AndrewC in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 15th December 2011, 11:23
  2. 18F2331 Advanced PWM Questions
    By JDM160 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th July 2010, 23:04
  3. 9V NiMH charger
    By bogdan in forum Schematics
    Replies: 0
    Last Post: - 10th September 2009, 03:43
  4. switch mode power supply with PWM
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 14th July 2009, 20:51
  5. Adcin charger
    By mitchf14 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 18th November 2008, 21:49

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