PWM setting PIC16F887


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2005
    Location
    The Netherlands
    Posts
    39

    Default PWM setting PIC16F887

    Hello,

    I work on a application and need two hardware PWM outputs. One PWM (CCP1) to
    control a DC motordriver LMD18200 (10 Khz) and one PWM (CCP2) for IR comm (38KHz)
    The motor is still running, but runs on 1 KHZ. (I need 10KHz or maybe the same 38KHz as the IR Comm.)

    Questions:

    - Runs CCP1 and CCP2 with the same Timer2 Prescale settings ?
    - So, can I set different frequences on the two PWM channels ?

    Thanks for replays,
    Regards, Gevo


    The setting in my program:

    ' PIC16F887

    DEFINE OSC 4 ' Inform PBP PIC Speed
    OSCCON = %01100111 ' Internal Clock set to 4MHZ

    INTCON.7 = 0 ' Disable interrupts.
    CM1CON0 = 0 ' Comparators off
    CM2CON0 = 0 ' Comparators off

    ' Motor PWM settings
    TRISC.2 = 0 ' Set PORTC.2 (CCP1) to output
    CCP1CON = %00001100 ' Set CCP1 to PWM, ACTIVE HIGH
    T2CON = %00000101 ' Timer2 ON, Prescale 1:4
    PR2 = 249 ' Set PWM Periode to 1 KHz

    ' IR COMM PWM settings
    TRISC.1 = 0 ' Set PORTC.1 (CCP2) to output
    CCP2CON = %00001100 ' Set CCP2 to PWM, active high
    T2CON = %00000100 ' Timer2 ON, Prescale 1:1
    CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
    PR2 = 25 ' Set PWM Periode to 38 KHz

    ---

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Gevo View Post
    Hello,
    I work on a application and need two hardware PWM outputs. One PWM (CCP1) to
    control a DC motordriver LMD18200 (10 Khz) and one PWM (CCP2) for IR comm (38KHz)
    The motor is still running, but runs on 1 KHZ. (I need 10KHz or maybe the same 38KHz as the IR Comm.)
    ---
    Might help you out...
    http://www.mister-e.org/pages/utilitiespag.html

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


    Did you find this post helpful? Yes | No

    Default

    You can have different duty-cycles, but the frequency will be the same on both CCP1 & CCP2 since they both use the PR2 register of TIMER2 for the PWM period.
    Regards,

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

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    You can have different duty-cycles, but the frequency will be the same on both CCP1 & CCP2 since they both use the PR2 register of TIMER2 for the PWM period.
    Hey...good point...Duh on my part...
    Set up a 555 timer for a 50% 38Khz square and turn it on/off with a PIC pin, or use a 2nd PIC set up for the same thing as the 555. An 8-pin PIC makes a helluva useful 555 timer....with a load of options...

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


    Did you find this post helpful? Yes | No

    Default

    Regards,

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

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    891


    Did you find this post helpful? Yes | No

    Default contact

    Hi Gevo,

    What is your email adress? I can't reply to your pm.
    Roger

  7. #7
    Join Date
    Jul 2005
    Location
    The Netherlands
    Posts
    39


    Did you find this post helpful? Yes | No

    Default Email address Gevo

    Hi Roger,

    Thnx for your replay.

    My direct Email adress: [email protected]

    Beste Regards,
    Gerben Voort

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. PICKit2 - warning about configuration words
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 4th August 2009, 14:01
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  4. PWM 'channels ...what's that all about then!
    By HankMcSpank in forum General
    Replies: 5
    Last Post: - 23rd April 2009, 16:49
  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