Redefining HPWM as output


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    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 16: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 " !!!
    *****************************************

  2. #2


    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

  3. #3
    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.

  4. #4
    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

  5. #5
    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 " !!!
    *****************************************

  6. #6


    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.

  7. #7


    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

  8. #8
    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

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce,

    Try it again, but this time leave the frequency at 2000 (only the duty cycle is 0). See if it toggles then.
    I'm curious (and no where near a PIC right now).

    Cheers!
    ---> picnaut

  10. #10


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce,

    Also, maybe put a 500ms delay right after the "WAITUP" label. Otherwise, if PIN goes low, it will immediately go high again and you won't catch it.


    Cheers!
    ---> picnaut

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, 20:50
  2. Multiple HPWM question
    By Johan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th October 2007, 14:00
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 04:46
  4. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 15:14
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 03: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