Help with HPWM on 18f6520


Closed Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Apr 2007
    Posts
    53

    Default Help with HPWM on 18f6520

    Hello,

    My first post here so don't be too hard on me!!

    I am currently playing with the HPWM command on the 18F6520. It works ok on CCP1 and CCP2 but I cannot get it to work on CCP 3,4 or 5.

    I have tried a few different setup configurations, however, at present I am stuck!

    Any help or ideas would be greatly apprciated.

    Andy

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Andy Wood View Post
    Hello,

    My first post here so don't be too hard on me!!

    I am currently playing with the HPWM command on the 18F6520. It works ok on CCP1 and CCP2 but I cannot get it to work on CCP 3,4 or 5.

    I have tried a few different setup configurations, however, at present I am stuck!

    Any help or ideas would be greatly apprciated.

    Andy
    Can't see no code, can't give no help.

  3. #3
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply Skimask.

    Here is a copy of the code:

    main:

    HPWM 1,127,245

    HPWM 2,127,245

    HPWM 3,127,245

    HPWM 4,127,245

    HPWM 5,127,245

    GOTO main

    When using a 5v supply, this produces 2.5v on CCP channels 1 and 2, and 0v on CCP channels 3,4 and 5 (which are on port G).

    I also tried adding TRISG = 0 at the start, to force CCP 3,4 & 5 to outputs but nothing changed.

    Andy

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Andy Wood View Post
    Thanks for the reply Skimask.
    Here is a copy of the code:
    main:
    HPWM 1,127,245:HPWM 2,127,245:HPWM 3,127,245:HPWM 4,127,245:HPWM 5,127,245:GOTO main
    When using a 5v supply, this produces 2.5v on CCP channels 1 and 2, and 0v on CCP channels 3,4 and 5 (which are on port G).
    I also tried adding TRISG = 0 at the start, to force CCP 3,4 & 5 to outputs but nothing changed.
    Andy
    That's it? No defines, don't know how fast the oscillator is runng, no registers set up, no nothing?
    Read the manual, try again...

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


    Did you find this post helpful? Yes | No

    Default

    HPWM only works with CCP1 & CCP2. Beyond that, you'll need to manually configure hardware PWM.
    Regards,

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

  6. #6
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    Hello Bruce,

    Thanks for the reply. I have read the manual and cannot find where it says HPWM is only for CCP1 and CCP2. Maybe this is an undocumented "feature"?

    Anyway, I do appreciate your response - I have been pulling my hair out! Thank you for your input.

    Andy

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Andy Wood View Post
    Hello Bruce, Thanks for the reply. I have read the manual and cannot find where it says HPWM is only for CCP1 and CCP2. Maybe this is an undocumented "feature"? Anyway, I do appreciate your response - I have been pulling my hair out! Thank you for your input.
    Andy
    I think this is one of those times where...it's not that you can't find where it says HPWM is only for CCP1 and CCP2, but...Where does it state in the manual that HPWM can be used on any available PWM module? And I guess the answer is...you don't...therefore, you can't. I never thought about it myself, but the facts are the facts.
    If PBP will compile HPWM 1 and HPWM 2 but not HPWM 3 - 5, then there ya go...

  8. #8
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    Hello Skimask,

    The confusing part is it compiled without listing any errors! it is just one of those things sent to try us I guess.....

    Anyway, I have learned some more and that is what it is all about. Thanks again for your input.

    Andy

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Andy Wood View Post
    Hello Skimask,

    The confusing part is it compiled without listing any errors! it is just one of those things sent to try us I guess.....

    Anyway, I have learned some more and that is what it is all about. Thanks again for your input.

    Andy
    I just looked at the pbppic18.lib file in the PBP directory and found this:

    ;************************************************* ***************
    ;* Default Hpwm values *
    ;************************************************* ***************

    ifndef CCP1_REG ; CCP1 pin port
    CCP1_REG EQU PORTC
    endif
    ifndef CCP1_BIT ; CCP1 pin bit
    CCP1_BIT EQU 2
    endif
    ifdef CCP2CON
    ifndef CCP2_REG ; CCP2 pin port
    CCP2_REG EQU PORTC
    endif
    ifndef CCP2_BIT ; CCP2 pin bit
    CCP2_BIT EQU 1
    endif
    endif

    I don't know if the compiler will accept it, but I'm wondering if adding:

    ifndef CCP3_REG ; CCP3 pin port
    CCP3_REG EQU PORTG
    endif
    ifndef CCP1_BIT ; CCP3 pin bit
    CCP3_BIT EQU 0
    endif.......................................

    and so on for channel 4 and 5 to that file...would enable the PWM modules for those channels.

    This is above me without a usable 6520 (or anything else in that family) to play with at the moment.

    DT, Mr_E? Any thoughts?

    Also, you might want to check the chip's revision. The early 6520/6620/6720/8520/8620/8720 chips didn't like to run above 4mhz under certain conditions relating to code (I had a few of those, run all day at 4mhz, didn't like to run at 6mhz). Might want to check the errata sheets and see if you've got one. Of course, if you've bought it recently, or the date code is less than a year or two old, I wouldn't worry about it.

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


    Did you find this post helpful? Yes | No

    Default

    You would also need to change the HPWM routine itself (also in the PBPPIC18.LIB file).

    Just took a quick look, doesn't look like it would be too hard.
    <br>
    DT

  11. #11
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    You would also need to change the HPWM routine itself (also in the PBPPIC18.LIB file).

    Just took a quick look, doesn't look like it would be too hard.
    <br>
    Sure does look easy enough. Only 9 lines of assembler and add a few more assembler directives to enable the other 3 channels on those PICs.
    And again, if I had a spare 65/66/67/85/86/87..20 laying around, I'd be all over that.
    Another mod to send into MeLabs for the next update.
    (Are the guys at MeLabs listening in on these last couple of great mods that DT/Mr_E have come up with in the last few weeks or so?)

  12. #12
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I have found that the HPWM function in PBP is fairly limiting - 32.767Khz is the maximum frequency.

    It is quite easy to set up the PWM registers directly. I use the following.
    With a 40Mhz oscillator. This gives 158Khz PWM frequency with 8 bits of
    resolution. You can get up to 10 bits of resolution at lower PWM frequencies.
    Although this is for channel 1, I have set up the other channels similarly.


    CCPR1L = %00010000
    CCPR1H = %00000000 ' Initialize to 0, PWM register

    T2CON = %00000100 ' Timer 2, Prescale 1
    CCP1CON= %00001100 ' Set up for PWM

    PR2 = $3F ' 8 bits of resolution at 158Khz


    CCPR1L = PWMVal >> 2 'Upper 6 bits (of the 8) go here
    CCP1CON.5=PWMVal.1 'Lower 2 here
    CCP1CON.4=PWMVal.0
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    (Are the guys at MeLabs listening in on these last couple of great mods that DT/Mr_E have come up with in the last few weeks or so?)
    I hope not!
    They already don't like me, now I'm messing with their compiler.

    But we already know they don't come here.

    And for the HPWM ...
    Not sure Andy's ready to start modifying system files yet, ... or not.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    And if using Charles' method.

    Be sure to download mister_e's PicMultiCalc.
    http://www.mister-e.org/pages/utilitiespag.html
    <br>
    DT

  15. #15
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I hope not!
    They already don't like me, now I'm messing with their compiler...
    Unless you 've put a bomb at their office, I can't understand why a brilliant programmer, that is using the PBP to its maximum, is not amiable to Melabs.

    If it is true, I will think a lot about next upgrade!

    Ioannis

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    But we already know they don't come here.
    <br>
    I was not aware of that. Pity...all this good info, gone to waste...ok, not really. You figure after awhile, some of us are going to end up with a sort of a next-gen PBP without MeLabs support.

    Quote Originally Posted by Ioannis View Post
    Unless you 've put a bomb at their office, I can't understand why a brilliant programmer, that is using the PBP to its maximum, is not amiable to Melabs.
    If it is true, I will think a lot about next upgrade!
    Ioannis
    That goes double here!

  17. #17
    Join Date
    Apr 2007
    Posts
    53


    Did you find this post helpful? Yes | No

    Default

    Hello Everybody,

    First of all, thank you for all the great responses. I now have PWM working great on all 5 channels by addressing the registers directly, as suggested by Charles. As an added bonus, the PWM resolution is 10bit.

    As Darrel said, it is probably a bit "advanced" for me to start modifying system/library files at this stage.

    The 18F6520 also has 12 analog inputs. Are there any "gotchas" or limits on the number of channels when using the ADCIN command?

    Andy

  18. #18
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Andy Wood View Post
    The 18F6520 also has 12 analog inputs. Are there any "gotchas" or limits on the number of channels when using the ADCIN command?
    Andy
    Check that same file I listed above pbppic18.lib
    I'm not at the house so I can't check it myself.
    Search thru the file for ADCIN. Even though you're not comfortable modifying the file, you might be able to get some clues as to how many channels ADCIN will handle. The PBP manual isn't specific enough.

Similar Threads

  1. need help on hpwm
    By helmut in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 15:49
  2. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:05
  3. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. HPWM usage with the 18F6520
    By slxrti in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th November 2005, 16:57

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