HPWM the hard way


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007
    Posts
    9

    Default HPWM the hard way

    I need to be able to use the 'Enhanced Capture/Compare/PWM' module in a 16F684 to drive a H bridge. I have, in the past, used the HPWM command to drive the PA1 output but now I need to be able to use the full-bridge outputs of the ECCP module. I am assuming this means that I need to write my own initialization routine. I started by simply trying to duplicate the HPWM command but I cannot get it to work. I am using the steps shown on page 84 of the 684 manual. Can someome point out the setp(s) that I'm missing?

    Thanks,
    Mark


    @ device pic16f684, INTRC_OSC_NOCLKOUT
    @ device pic16f684, WDT_ON
    @ device pic16f684, PWRT_ON
    @ device pic16f684, MCLR_OFF
    @ device pic16f684, BOD_ON
    @ device pic16F684, CPD_OFF
    @ device pic16f684, PROTECT_OFF

    define OSC 8

    TRISA = %00000000
    TRISC = %00000000
    CMCON0 = %00000111

    OSCCON = %01110000 '8 MHz internal osc
    ANSEL = %00000000 'All Digital
    ADCON0 = %00000000 'All Digital

    'Test to set the hardware PWM for an output
    'at 16 KHz and about 50% duty cycle
    'PR2 = 124.
    'Timer2 prescale = 1

    TRISC.5 = 1 'SET CCP1 AS INPUT
    PR2 = %01111100 'SET FREQ
    T2CON = %00000000 'Stop TIMER2 and SET PRESCALE to 1
    CCP1CON = %00001100 'set the CCP1CON
    CCPR1L = %10000000 'set to 50% duty cycle
    PIR1.2 = 0 'CLEAR THE TIMER2 INT FLAG
    T2CON.2 = 1 'START TIMER2
    TRISC.5 = 0 'Set CCP1 to output

    'Can't get the above to work but...
    ' This line works as expected if uncommented.
    ' HPWM 1,127,1000

    WHILE 1
    WEND

    END

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


    Did you find this post helpful? Yes | No

    Default

    Set CCP module to full-bridge mode...
    Code:
    CCP1CON = %01001100 'set the CCP1CON
    For 50% duty cycle, CCPR1L should be half of PR2
    Code:
    PR2 = 124   'SET FREQ 
    CCPR1L = 62 'set to 50% duty cycle
    Added: For Full-bridge mode, you'll probably need to change the PWM1CON value to limit transition currents.

    hth,
    Last edited by Darrel Taylor; - 6th February 2008 at 21:06. Reason: PWM1CON
    DT

Similar Threads

  1. Multiple HPWM question
    By Johan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th October 2007, 13:00
  2. need help on hpwm
    By helmut in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 15:49
  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. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43

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