pwm


Closed Thread
Results 1 to 4 of 4

Thread: pwm

  1. #1
    pic beginner's Avatar
    pic beginner Guest

    Post pwm

    Hi anyone
    my question about pwm
    I know that pic16f877 has 10 bit resolution pwm module.
    Suppose that we have a word variable for example: Y
    maximum value of Y is 1023. We want put Y in pwm module and convert digital
    value of Y to analog with RC netwok.(PWM as DAC)
    pwm freq is 1500.
    How write this program with PBP.
    Please help me
    Thanks alot.

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


    Did you find this post helpful? Yes | No

    Default

    A fine example of 8-bit PWM is in the manual, if you show us an attempt at getting that to run using your variable Y, then we can show you how to get the remaining two Least Significant Bits activated to turn PBP's 8-bit into a full 10-bit operation.

  3. #3
    pic beginner's Avatar
    pic beginner Guest


    Did you find this post helpful? Yes | No

    Exclamation again 4 u

    Hi Melanie
    I thank you for reading and answering my question.
    I think taht below program shows 8-bit hardware PWM in pbp :
    Y VAR WORD
    HPWM 1,Y,1000
    This program produces pwm that y specifies duty cucle . The frequency of pwm is 1khz.
    For example for Y=127 duty cycle is 50%
    But HPWM command only considers low byte of Y.
    I want to know about 10 bit pwm in pbp
    thanks alot.

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


    Did you find this post helpful? Yes | No

    Default

    That's a start, but as you correctly say PBP will only look at the Lower 8-bits... so your example will lose the upper two, which are far more important.

    First, let's grab the UPPER eight bits (variable TempA is a BYTE)...

    TempA=Y >> 2

    Now let's set the 8-bit PWM with the eight most significant bits...

    HPWM 1,Temp,1000

    For the two least significant bits, if you looked in the 'Capture/Compare/PWM' section of your PIC's Datasheet you would have found that bits 5 and 4 of the CCP1CON Register handle those... so, simply just load them...

    CCP1CON.5=Y.1
    CCP1CON.4=Y.0

    That's all there is to it... simple? Sure it is... like I keep telling everyone - Read the Datasheet. Actually, it's so simple to fire up the PWM module, you can dispense with PBP's HPWM and manipulate the registers yourself (detailed instructions in Datasheet)... ends up using heaps less program code.

    Lastly, don't forget to set TRIS appropriately for output on the HPWM channel you are using. For a 16F628 this will be TRISB.3=0, For a 16F877 this would be TRISC.2=0.

    Melanie

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 22:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. PWM: Vernacular/Function (Newbee)
    By TerryN in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd July 2008, 16:58
  4. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 00:26

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