HPWM on PIC18F125K22


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2006
    Posts
    70

    Default HPWM on PIC18F125K22

    I've got an existing/working device on which I need to implement a simple temporary pulse series using the hardware PWM. I'm trying to use the HPWM command to no avail. The device is a 28-pin PIC18F25K22, and I need to have the pulse on either PORTB.2 or PORTB.3. According to the datasheet, PWM should be possible on both of these pins, but there is so much multiplexing and enhancing on this device, that I think my problem lies in setting registers correctly for HPWM to work.

    Here's the relevant code that does not work.

    Code:
    ....
    define CCP1_REG PORTB
    define CCP1_BIT 2
    
    ....
    
    HPWM 1,200,2
    PAUSE 5000
    CCP1CON = %00000000 'turns off PWM
    
    High PORTB.2 'Test port connection with LED
    pause 50
    low PORTB.2
    'pause 50

    The last bit flashes an LED on PORTB.2 as it should. But I see nothing resulting from the HPWM command. Anybody got a clue for the registers on this pic? By the way, I've tried various permutations to do the pulses manually:

    'TRISB = %00000000
    'CCPTMRS0 = %00000000
    'PR1 = %00000111
    'CCP2CON = %00001100 'define lsb of duty cycle. make PWM move high PxA and high PxB
    'CCPR1L = %00011111 'duty cycle MSB
    'T2CON = %00000101 'set prescaler and turn on PWM
    'TRISB = %00000000

    Can't get this to work either. I just don't get this datasheet I'm afraid. Thanks for any help.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: HPWM on PIC18F125K22

    Hi,
    The device is a 28-pin PIC18F25K22, and I need to have the pulse on either PORTB.2 or PORTB.3.
    As far as I can see there's no CCP module connected to PortB.2 so that one is out.

    PortB.3 on the other hand can have the CCP2 module connected to it but by default it's connected to PortC.1. You select which pin (either PortB.3 or PortC.1) the CCP2-module should be connected to with the CCP2MX bit in the CONFIG3H configuration word. The purpose of the DEFINE is to let the compliler know how you've configured the device - at least that's how I understand it.

    Then, since it's the CCP2 module you need to use HPWM 2, 200, 10000.

    Finally, in your code you're trying to get an output frequency of 2Hz, that's not going to work.

    /Henrik.

  3. #3
    Join Date
    Nov 2006
    Posts
    70


    Did you find this post helpful? Yes | No

    Default Re: HPWM on PIC18F125K22

    Thanks Henrik. Following your suggestions, I got it to work on PORTB.3. The crucial thing I was missing was the CCP2MX bit.

Similar Threads

  1. Replies: 3
    Last Post: - 23rd October 2011, 12:53
  2. VFD and HPWM
    By shawn in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 12th January 2009, 02:12
  3. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:05
  4. HPWM & PIN P1A
    By Uffe in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 7th September 2005, 21:20
  5. 10 Bit HPWM?
    By Desterline in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th December 2003, 19:13

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