How can I stop HPWM and then manually set the pin level?


Closed Thread
Results 1 to 4 of 4
  1. #1

    Default How can I stop HPWM and then manually set the pin level?

    I have built a frequency generator with a 16F88 to fake a speed source when working on farm equipment.

    Originally I was manually calculating the period using 1000*1000, then DIV32 by my desired frequency to get my period in us and manually outputting the signal, but it takes too long at higher frequencies. I have since changed it to use my old output below 250Hz and HPWM above that. This works great when starting below 250Hz and transitioning up, but after it switches to HPWM and I come back down below 250Hz I can't control the pin manually anymore. I was stopping the output with HPWM 1,0,0 but the pin is stuck at 0 after that.

    The only work around I have come up with so far is allowing the controller to reset itself at this transition point so that it starts fresh without HPWM active; however, I don't like this method.

    Is there a way to completely stop the HPWM command, or am I going about this the wrong way?

    Regards,

    Gavin

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default Re: How can I stop HPWM and then manually set the pin level?

    I did similar using this technique many years ago

    HPWM 1,0,250
    oPWM = 0

    where oPWM is the hardware pin associated with the HPWM.

  3. #3
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: How can I stop HPWM and then manually set the pin level?

    You can set and reset pin using hpwm Ch,0,freq and hpwm Ch,255,freq.
    Or just set CCPxCON to 0 and use portx or latx register.

  4. #4


    Did you find this post helpful? Yes | No

    Post Re: How can I stop HPWM and then manually set the pin level?

    Quote Originally Posted by pedja089 View Post
    You can set and reset pin using hpwm Ch,0,freq and hpwm Ch,255,freq.
    Or just set CCPxCON to 0 and use portx or latx register.
    That was my initial thought, so I tried this:

    HPWM 1, 255, 250 'Output high
    PAUSEUS HPd 'for half the period
    HPWM 1, 0, 250 'Output low
    PAUSEUS (HPd-120) 'for other half, less ADCIN time

    But the results were less than ideal. If I recall correctly I couldn’t get more than 140 Hz using this method. Without changing anything else in my code other than this:

    PortB.0 = 1 'Output high
    pauseus HPd 'for half the period
    PortB.0 = 0 'Output low
    Pauseus (Hpd-120) 'for other half, less ADCIN time

    The output was smooth through the range.

    I’ll try CCP1CON = 0

    Thank you,

    Gavin

Similar Threads

  1. How do I stop HPWM
    By DonLuis in forum General
    Replies: 2
    Last Post: - 15th September 2012, 11:15
  2. Weird problem with logic level on pin.
    By HenrikOlsson in forum General
    Replies: 12
    Last Post: - 13th June 2011, 06:31
  3. How to set a pin high an keep it there?
    By ShortBus in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 1st October 2009, 16:01
  4. 16f628a Hpwm-stop??
    By Caddydan in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th April 2006, 17:28
  5. Debug in + Floating pin = stop program execution?
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th November 2005, 08:46

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