10 Bit HPWM?


Closed Thread
Results 1 to 5 of 5

Thread: 10 Bit HPWM?

  1. #1
    Desterline's Avatar
    Desterline Guest

    Default 10 Bit HPWM?

    Hello,
    According to the datasheet the PIC16f87x chips have 10 bit hardware PWM. But the manual for PBP (2.43) seems to only show 8 bit resolution.

    What's the best (read easiest) way to get 10 bit resolution out of them?

    Thanks
    -Denny

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Yes this is true. PBP only supports 8 bits with HPWM.

    You could do it the old and trusted way by setting the PIC's registers directly... this will get you started...

    Initialisation (at the start of your program)...

    PR2=$FF ' Timer2 Period Register
    T2CON=%00000100 ' Values for PWM period
    CCP1CON=%00001100 ' Set PWM Mode

    Now in your program... the WORD variable TempWord contains the 10-bit value to set...

    TempWord=TempWord<<6
    CCPR1L=TempWord.highbyte
    CCP1CON.5=TempWord.7
    CCP1CON.4=TempWord.6

    You'll notice I put 8 bits into CCPR1L in one hit and the remaining two bits into CCP1CON.

    Refer back to the PIC Datasheet to see what bits I've manipulated.

    There is an alternative you could try... that is set the 8-bits with HPWM, and load the remaining two bits into CCP1CON manually (always assuming you're running channel 1 with HPWM) - I've not tried this myself but you might be able to simply pull it off that way.

    Melanie

  3. #3
    Desterline's Avatar
    Desterline Guest


    Did you find this post helpful? Yes | No

    Default

    Thank you Melanie. You know one of these days were going to have to make good on our threats and actualy send you some flowers. :-)


    Clarify somthing else for me: The datasheet gives the max resolution of the HPM as a function of Fosc. Asuming a 4MHz resonator, is Fosc 4Mhz, or the internal divided by 4 - 1Mhz?


    As I read the formula:


    LOG(fosc/Fpwm)
    --------------------- = Resolution (in bits)
    LOG(2)

    That works out to be just under 4KHz (assuming Fosc is 4Mhz) for 10 bit resolution, is that right?

    Thanks
    -Denny
    Last edited by Desterline; - 15th December 2003 at 15:47.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The thing I like about computers is that thery're pretty idiot proof if you think about it - especially the mnemonics...

    FOSC = Frequency OSCillator

    Namely it's the frequency of your xtal/resonator - ie the Fequency of the Oscillator.

    Whereas Fosc/4 is the instruction speed.

    btw... I calculate 10 bits to be precisely 3906.25 at 4.000000MHz assuming you have a xtal that's spot on *smiles*...

  5. #5
    Desterline's Avatar
    Desterline Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks,
    That's what I thought, but I couldn't pin it down definitively.

    -Denny

Similar Threads

  1. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  2. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  3. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  4. Need help with 16f819 10 bit ADC
    By bannrikae in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 26th September 2005, 15:20
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

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