Quick n dirty HPWM out of phase


Closed Thread
Results 1 to 15 of 15
  1. #1
    Join Date
    Jul 2006
    Posts
    36

    Default Quick n dirty HPWM out of phase

    Assuming a PIC with at least 2 PWM channels, can someone suggest a quick way to output two PWMs exactly 180 degrees out of phase with each other?

    I can do it by turning alternating pins on and off but there's no CPU left to do anything else without messing up the waveform.

    Trying not to recreate the wheel...or maybe it's so obvious I can't see the answer.

    Thanks

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ChrisHelvey View Post
    Assuming a PIC with at least 2 PWM channels, can someone suggest a quick way to output two PWMs exactly 180 degrees out of phase with each other?

    I can do it by turning alternating pins on and off but there's no CPU left to do anything else without messing up the waveform.

    Trying not to recreate the wheel...or maybe it's so obvious I can't see the answer.

    Thanks
    Hardware ways, flip flop, inverter, transistor . . . since you do not want to burden PIC.
    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
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Use a PIC with an ECCP (ENHANCED CAPTURE/COMPARE/PWM MODULE)
    16F690 is one.

    Put it in Enhanced Half-Bridge mode.
    Outputs will be on P1A and P1B pins.
    <br>
    DT

  4. #4
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ChrisHelvey View Post
    Assuming a PIC with at least 2 PWM channels, can someone suggest a quick way to output two PWMs exactly 180 degrees out of phase with each other?
    How about a PIC with a Comparator. Feed the PWM into comparator and use the comparator output to give your out of phase signal.

    Advantages...

    No external components
    no software overhead other than setting up comparator

    Disadvantages...

    You lose one comparator and a few pins on your PIC
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Thumbs up

    oooo, I Like it Keith.
    <br>
    DT

  6. #6
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    oooo, I Like it Keith.
    <br>

    Sadly I cant take the credit.

    The idea was originally suggested by Melanie but it stuck in my mind because I have an device that uses the HPWM to generate an IR carrier which I then gate with a transistor. Too late to change my existing design but I will use the comparator to do the gating in a later revision of the board.

    Not only does it save a transistor and a couple of resistors but has a better voltage swing as well!
    Keith

    www.diyha.co.uk
    www.kat5.tv

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


    Did you find this post helpful? Yes | No

    Default

    Darn Melanie. She's just too smart for her own "Britches".

    Which is why I tend to envision her without them.

    Oh wait, I'd have done that anyways.

    At least you applied it to the right problem.
    <br>
    DT

  8. #8
    Join Date
    Jul 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    That is a very elegant solution - just what I was looking for.
    Thanks, I will look in to this. The link to Melanie's post is very helpful. Since 0 Volts is "low voltage" it should work exactly the same - when the pulse goes low, the comparator output goes high.
    Brilliance is always in the simplicity...

  9. #9
    Join Date
    Jul 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Thumbs up

    Just for the record. I followed through on this and the above idea (using the comparator) works great on a 16f877A with a 20Mhz crystal.
    I just tied the output of the HPWM pin to the Comparator input. I struggled with setting the registers properly because that part is still a bit greek to me (read - I had to experiment until I got what I wanted and then look at the data sheet to figure out WHY it did what it did.)
    The wave form is very sturdy and quite square all the way up to 15Khz. I even managed to figure out how to use one of the two ADC inputs the comparator shares on PortA.

    I'm learning. As an old dog, SLOWLY, but I'm learning....

    Thanks everyone,

    Chris Helvey

  10. #10
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ChrisHelvey View Post
    Just for the record. I followed through on this and the above idea (using the comparator) works great on a 16f877A with a 20Mhz crystal.
    I just tied the output of the HPWM pin to the Comparator input.
    Glad you got it working.

    I struggled with setting the registers properly because that part is still a bit greek to me
    Tip! - Download the English version of the Datasheet
    Keith

    www.diyha.co.uk
    www.kat5.tv

  11. #11
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Darrel really! In exchange for a really big bag of negotiable money all in nicely used notes etc etc (pics, noddy currency and vapourware doesn't count), I'll send you a signed naughty photo... *smiles*

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


    Did you find this post helpful? Yes | No

    Default

    <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="400" HEIGHT="400" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0"><PARAM NAME="MOVIE" VALUE="http://www.pbpgroup.com/files/MelanieMoney.swf"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="true"><PARAM NAME="WMODE" VALUE="opaque"><PARAM NAME="QUALITY" VALUE="high"><EMBED SRC="http://www.pbpgroup.com/files/MelanieMoney.swf" WIDTH="400" HEIGHT="400" PLAY="true" LOOP="true" WMODE="opaque" QUALITY="high" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>
    DT

  13. #13
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Ohhh... temptations...

    Must say you are a wizzard constructing web pages though... Harry Potter would be proud...

    As a 'big bag' full of loot, it's a bit lightweight... (new job obviously's paying well I see...) flight over to California for a trip to the cinema... ooohhh... bargain can't wait... let me rain-check that... *smiles*

    Just curiosity, are you counting the hits on the Yes and No buttons?

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


    Did you find this post helpful? Yes | No

    Default

    Awwww, Jilted again.

    Good thing I'm a nerd. I'm used to it.

    > As a 'big bag' full of loot, it's a bit lightweight...

    Yup, should have used $1 bills. Would've filled a good sized duffle bag.
    But you're right, the Jobs going good.

    No, not keeping track of the clicks or anything.
    After the fiasco with the Javascript LCD and Firefox. I'm trying to learn Flash to see if I can do the same kind of stuff, that'll work in any browser.

    Of course, that means you all have to put up with my silly creations along the way.
    <br>
    DT

  15. #15
    Join Date
    Aug 2011
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Re: Quick n dirty HPWM out of phase

    The following is how I do it. works well and is super easy. I see this is an old post, but hey, it might help someone!
    Use the tilda ~ before the variable! I use this on a 16F873A and a 16F1503 and the 1824, works great.


    '*********** Define ADCIN parameters *************************************

    DEFINE OSC 4
    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 15 ' Set sampling time in uS

    XADCVAR VAR WORD ' X ADC Result
    PWMOUT1 var byte ' PWM CH1
    PWMOUT2 VAR BYTE ' PWM CH2

    '*********** SET PORTS ************************************************

    TRISA = %000001 ' Set PORTA
    TRISB = %00000000 ' Set PORTB
    TRISC = %00000000 ' Set PORTC
    ADCON0 = 0 ' Set up ADCON1

    BEGIN:

    '*********** CHECK ADC VALUE ******************************************

    MAIN:
    ADCIN 0, XadcVar ' convert ADC value to a byte value:
    PWMOUT1 = XadcVar ' X Axis
    PWMOUT2 = ~XadcVar ' Y Axis

    Hpwm 1,PWMOUT1,1600
    Hpwm 2,PWMOUT2,1600
    Goto BEGIN

    end
    Last edited by scasale; - 17th August 2014 at 05:31.

Similar Threads

  1. 3 phase supply detector challenge
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 15th May 2009, 07:54
  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. 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 : 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