PWM problem CCP2 port


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Hi. I'm using a 16F73 with 2 HPWM's and have had no problems. I didn't use any DEFINEs. I just set the 2 PWM ports as outputs and use:

    HPWM 1,LEFT,15000 'SEND 15KHZ WITH DUTY CYCLE VALUE IN VARIABLE LEFT
    HPWM 2,RIGHT,15000 'SEND 15KHZ WITH DUTY CYCLE IN VARIABLE RIGHT
    DO THIS AND THAT
    LET CCP1CON = 0 'TURN OFF LEFT PWM
    LET CCP2CON = 0 'TURN OFF RIGHT PWM
    Low PORTC.1 'CCP1 OUTPUT LOW
    Low PORTC.2 'CCP2 OUTPUT LOW

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


    Did you find this post helpful? Yes | No

    Default

    NL2TTL,

    Seems everyone is forgetting the analog ports these days.

    ADCON1 = $0F

    Added: It will probably be better to have subroutines that set the dutycycle of the CCP modules. Then call them only when needed.
    Continually setting the registers in the main loop may cause some problems, and isn't needed since the hardware will continue putting out the PWM while the main program is doing other things.

    Also, by using these statements Duty3 = Gval *2, it effectively reduces the PWM resolution to 9-bit since bit0 will always be 0.

    Added2: The RB3/CCP2 pin is the alternate CCP2 output. You'll need to change the CCPMX configuration fuse for it to work there.
    <br>
    Last edited by Darrel Taylor; - 18th September 2006 at 18:48. Reason: Coffee first, answers later :)
    DT

  3. #3


    Did you find this post helpful? Yes | No

    Default

    @Darrel Taylor

    Thank you for you replay, about adcon and the Rb3 i understand, but what exactly do you mean about:

    Also, by using these statements Duty3 = Gval *2, it effectively reduces the PWM resolution to 9-bit since bit0 will always be 0

    How can i fix that?

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


    Did you find this post helpful? Yes | No

    Default

    In the binary world, multiplying by 2 is the same as shift left 1 (<< 1).

    This will always leave a 0 it the bit0 location. So if you had a dutycycle of say 257 (100000001), * 2 would be 514 (1000000010).

    The easiest way to fix it is to just use bigger numbers. 10-bit numbers range from 0 to 1023. <br>
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    I've added:

    ADCON1 = $0F

    But still ccp2 doesn;t work (also on portc.2 it gives problems)

    The pin is always high.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    And correct me if i'm wrong but when i don't make a loop in the program i get no response on any pwm port

    So i need the Goto mainloop

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


    Did you find this post helpful? Yes | No

    Default

    Did you also change the CCPMX configuration fuse for RB3/CCP2 alternate?

    portc.2 is CCP1, are you saying that that one stopped working ?

    And yes, you need to have a mainloop. Otherwise it goes to the END statement and enters Sleep mode. But changing the CCP registers doesn't need to be in the mainloop.
    <br>
    DT

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  2. PWM Problem
    By cihhan in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th June 2008, 18:43
  3. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 07:24
  4. Problem with A port on 18F2550
    By NL2TTL in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 9th May 2007, 22:59
  5. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27

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