Redefining HPWM as output


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    what about if you place a LOW PORTB.2 after the last HPWM line???

    EDIT: i think i need to sleep.. See Alain solution...
    Last edited by mister_e; - 19th September 2005 at 15:48.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink stop HPWM

    Hi, Peterdeco

    Melabs says : to stop HPWM : HPWM 1, 0, xxxx ( duty cycle to zero ! )

    That's all !!!

    Now, if you can decently explain what PBP does when you ask for 0 Hz freq ...

    you could also disable the CCP1 module ... but why ???

    Alain
    Last edited by Acetronics2; - 19th September 2005 at 15:33.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi,

    Do you have to change the frequency to zero?
    I wouldn't.
    Anything below the minimum allowed frequency can cause strange results with the HPWM command.
    I think if you simply issue the command at the frequency you've been using, but at a 0% duty cycle, it will be solid OFF. If you issue the command with a 100% duty cycle (255 if 8-bit) it will be solid ON.

    Does anybody see any problem with this approach?

    Regards,
    ---> picnaut

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Picnaut
    Does anybody see any problem with this approach?
    Can't say... i never use HPWM. Still prefer to write directly to the internal register. BUT, as Alain said and AS per the book
    Quote Originally Posted by TFM
    Dutycycle specifies the on/off (high/low) ratio of the signal. It ranges from 0 to 255, where 0 is off (low all the time) and 255 is on (high) all the time.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    If you want to turn OFF hardware PWM & have a solid logic output on the CCP pin, don't rely on using the HPWM command with a zero duty-cycle. Just use CCP1CON = 0 to disable the PWM module, then set/clear the pin as required.

    After clearing CCP1CON, you can simply issue the HPWM command again, and PBP will automatically configure CCP1CON for PWM mode.

    Some I/O-pins are multiplexed with peripherals. When these peripherals are enabled, they may "override" the TRIS bit for a pin. Even though the HPWM command does leave the TRIS bit set to output, and it leaves a zero in the output latch, if the PWM module is still enabled, and not outputting a PWM signal, you'll see a high impedance on the CCP output pin.
    Regards,

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

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by picnaut
    Hi,

    I think if you simply issue the command at the frequency you've been using, but at a 0% duty cycle, it will be solid OFF. If you issue the command with a 100% duty cycle (255 if 8-bit) it will be solid ON.

    Does anybody see any problem with this approach?

    Regards,
    Hi, Picnaut

    this approach runs perfectly well, and it is recommended by Melabs itself ...as I use HPWM for R/C E-motors , I just clear CCP1CON when I'm not really really sure a glitch could give a false value to duty cycle. ( never saw it ...but i'm sure !!! )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Thank you Everybody. Bruce, I did the CCP1CON = 0 thing in place of my "zero frequency" command and it works like a charm.

  8. #8


    Did you find this post helpful? Yes | No

    Talking

    Bruce's approach sounds better to me.
    It probably uses less code than issuing the HPWM command again also.

    Cheers.
    ---> picnaut

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


    Did you find this post helpful? Yes | No

    Default

    Here's a simple test to show the effects of disabling the hardware PWM module, or using a zero duty-cycle or freq with HPWM.

    Hook an LED up to your CCP out pin.

    CCP output pin ---|>|----/\/\/\/\----GND
    Code:
    SYMBOL PIN = PORTC.2 ' Define whatever pin on your PIC is CCP out here
    
        HPWM 1,127,2000
        PAUSE 8000
        CCP1CON = 0 ' Test once with this, then comment it out
        'HPWM 1,0,0  ' Now test with this un-commented
        
    WAITUP: 
        HIGH PIN
        PAUSE 500
        LOW PIN
        PAUSE 500
        GOTO WAITUP
    On a 16F876A, the LED never toggles with HPWM 1,0,0. It does once the hardware PWM module is disabled with CCP1CON = 0. I'm curious if it works either way on other PIC's.
    Regards,

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

Similar Threads

  1. Bit Banging input to output on PIC16F876A
    By Bronurstomp in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th June 2008, 19:50
  2. Multiple HPWM question
    By Johan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th October 2007, 13:00
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  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