manual hardware PWM setup on 16F1824


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Good luck operating it at 6.58 bits

    Name:  10bits.PNG
Views: 1421
Size:  20.4 KB

    That's its maximum resolution at that PWM frequency. It's still a 10 bit pwm.

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


    Did you find this post helpful? Yes | No

    Default

    You've never used 6.58 bits? The trick is what to do with the little bit (1.42) left over all the time
    -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 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by cncmachineguy View Post
    You've never used 6.58 bits? The trick is what to do with the little bit (1.42) left over all the time
    That's easy, I just sweep them under the rug.

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


    Did you find this post helpful? Yes | No

    Default

    I would try that but my 2.3 kids will eat them
    -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!

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    but still, why does the datasheet, even the one for the 18F4550 'indicates' a variable bit resolution...
    It's not variable in the sense that you can change it, it changes as function, or relation, between the clock frequency and PWM frequency.

    If you had a 1MHz clock (Fosc/4=1Mhz) and wanted a 1Mhz PWM frequency you'd get two different dutycycles, 0% and 100% -1 bit resolution (not very useful). If you lower the PWM frequency to 100kHz you'd have 10 different dutycycles available. How many bits does the value 10 occupy? Well, you can't fit it in 3 bits and 4 is more than you actually need. Using the formula in the datasheet tells us that it's 3.32 bits. Obviosuly there are no such thing as partial bits and you'd need 4 bits to actually be able to use all 10 dutycycles but writing anything "above" 10 to these four bits will result in a dutycycle of 100%.

    Now, if the PWM module gives you a higher resolution than you want you can obviously "scale up" your low resolution value to fit whatever number of bits of resolution there is, as have been shown earlier.

    /Henrik.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    right...

    So, if TMR6 is setup to feed the PWM's... and 'overflows' @ 80KHz...
    If the PWM's were 8 bit then i'd expect a cycle frequency of 312.5Hz...
    If the PWM's were 10bit then i'd expect a cycle frequency of 78.125Hz...

    Where on earth are these stupid decimals coming from?
    Who on earth made a PWM system so complicated?
    and which idiot approved their design?

    If the hardware is static 10bit... why the hell would the datasheet even suggest any other resolution? I don't even understand how you couldn't use 10bit resolution on hardware PWM...

    I really don't understand how these PWMs work... They are backward and alien to me...

    So, can someone please explain in English how to setup the PWMs (ie how the hell you get a different bit resolution)?

    Thanks
    Last edited by comwarrior; - 30th January 2011 at 21:56.

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


    Did you find this post helpful? Yes | No

    Default

    Look at the related registers... it's timer based, then look which feature are in Timer... YUP you got it... prescaller OSC/2,4,8,16... hence the decimals.

    Use the PICMulticalc, set a low PWM frequency see the resolution... set it way higher... see the resolution.

    Conclusion?
    Steve

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

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    comwarrior,
    Henrik and others are trying to help you understand. There is no need to get upset.

    I am asking you to keep an eye on your language. This is a "family" type forum.
    Dave
    Always wear safety glasses while programming.

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