Half-bridge PWM with a 16F684 ?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323

    Default Half-bridge PWM with a 16F684 ?

    I'm trying to set up the half-bridge PWM outputs on a 16F684. Not having much luck...

    I've read section 11 of the data sheet (41202F) about a million times now. The individual words make sense to me... but I still can't seem to grasp the concept of how to make this thing work.

    I *think* I've done the setup according to these instructions in the data sheet, but now I don't know what to do next to make it get up and run.

    Here's the setup instructions from Data Sheet:
    11.3.7 SETUP FOR PWM OPERATION

    The following steps should be taken when configuring
    the CCP module for PWM operation:

    1. Disable the PWM pin (CCP1) output driver by
    setting the associated TRIS bit.

    2. Set the PWM period by loading the PR2 register.

    3. Configure the CCP module for the PWM mode
    by loading the CCP1CON register with the
    appropriate values.

    4. Set the PWM duty cycle by loading the CCPR1L
    register and CCP1 bits of the CCP1CON register.

    5. Configure and start Timer2:
    • Clear the TMR2IF interrupt flag bit of the
    PIR1 register.

    • Set the Timer2 prescale value by loading the
    T2CKPS bits of the T2CON register.

    • Enable Timer2 by setting the TMR2ON bit of
    the T2CON register.

    6. Enable PWM output after a new PWM cycle has
    started:

    • Wait until Timer2 overflows (TMR2IF bit of
    the PIR1 register is set).

    • Enable the CCP1 pin output driver by clearing
    the associated TRIS bit.


    Here's the little bit of setup code I've got so far. Not sure what to do next.
    Could one of you good folks please help point me in the right direction?

    Code:
    </i></font><b>INCLUDE </b><font color="#FF0000">&quot;MODEDEFS.BAS&quot;   </font><font color="#000080"><i>'Include Shiftin/out modes
    </i></font><b>DEFINE </b>OSC 8             <font color="#000080"><i>'8MHz clock
    
    </i></font>TRISA= %00000000   <font color="#000080"><i>'Set 'em all to outputs 
    </i></font>TRISC= %00000000   <font color="#000080"><i>'Set 'em all to outputs 
    </i></font>ANSEL = %00000000  <font color="#000080"><i>'Turn off that analog crap
    </i></font>OSCCON = %01110001  <font color="#000080"><i>'8MHz
    
    
    
    
    </i></font>TRISC.5 = 1 <font color="#000080"><i>'disable CCP1
    </i></font>PR2 = $65  <font color="#000080"><i>'load a value into PR2
    </i></font>CCP1CON= %10001100 <font color="#000080"><i>'half bridge, all PWM outputs active high 
    </i></font>CCPR1L= %11111111 <font color="#000080"><i>'set the PWM duty cycle
    </i></font>PIR1.1 = 0 <font color="#000080"><i>'clear the TMR2IF interrupt flag
    </i></font>T2CON.0 = 0 <font color="#000080"><i>'set prescaler to 1...
    </i></font>T2CON.1 = 0 <font color="#000080"><i>'...set prescaler to 1
    </i></font>T2CON.2 = 1 <font color="#000080"><i>'turn timer 2 on
    </i></font>TRISC.5 = 0 <font color="#000080"><i>'enable CCP1
    
     'Now what?
    
    
    </i></font><b>END
    </b></code></pre><!--EndFragment--></body>
    </html>
    Any help would sure be appreciated..

    Thanks!

    steve

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Steve, Darrel has some goodies here:
    http://www.pbpgroup.com/modules/wfse...php?category=2
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Thanks Joe,
    Darrels stuff is always cool. But I don't see what I'm looking for there.

    I'm trying to make the 16F684's internal "Half-Bridge" mode work, with it's adjustable dead-band.

    steve

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Hmm. That still doesn't get me there. What I'm after is to output 2 waveforms that are 180 degrees out of phase and have a delay or "dead band" where neither is on.
    Looks like this:




    steve
    Last edited by Byte_Butcher; - 17th January 2010 at 21:09. Reason: wrong photo

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    What you have should work once you reduce CCPR1L < PR2. 51 in CCPR1L should give you
    ~50% duty cycle.
    Regards,

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

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


    Did you find this post helpful? Yes | No

    Default

    Give this a shot;
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF
    
    DEFINE OSC 8             '8MHz clock
    
    SYMBOL TMR2IF = PIR1.1 ' TMR1IF flag bit
    TRISA = %00000000   ' Set 'em all to outputs
    PORTC = 0 
    TRISC = %00110000   ' RC4 and RC5 left as inputs until ready 
    ANSEL = %00000000  ' Turn off that analog crap
    CMCON0 = 7
    OSCCON = %01110000 ' 8MHz internal
    
    PR2 = 101          ' load a value into PR2 for ~19.6kHz
    CCP1CON = %10001100 ' half bridge, all PWM outputs active high 
    CCPR1L = 50         ' set the PWM duty cycle ~50%
    PWM1CON = %10000011' set auto restart & deadband
    TMR2IF = 0
    T2CON = %00000100  'set prescaler to 1, prescaler to 1, timer 2 on
    
    WHILE TMR2IF = 0   ' wait for TMR2IF flag bit to set
    WEND
    TRISC = %11001111  ' now set RC4 & RC5 as outputs
    
    Main:
      GOTO Main
      
      END
    Attached Images Attached Images  
    Regards,

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

  8. #8
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default THANK YOU BRUCE ! It works!

    Ah! Of course... CCPR1L must be < PR2 or it ain't gonna run.

    Sometimes I just need someone to spin me around 2 or 3 times and pull the blindfold off my head.

    It works great now. Thank you SO much!


    steve

Similar Threads

  1. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 07:03
  2. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 08:24
  3. Help with 16F684 PWM
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th November 2007, 03:20
  4. 18F4620 HPWM Half Bridge Mod problem
    By showtime in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 2nd November 2007, 13:55
  5. Using HPWM in half bridge mode on 16f690
    By Chris Barron in forum mel PIC BASIC
    Replies: 0
    Last Post: - 29th December 2006, 12:18

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