Help with pic 12f629


Closed Thread
Results 1 to 40 of 53

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEFINE OSC 4
       @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
        CMCON=7 
        
        cnt VAR BYTE
        boton VAR GPIO.2
        mosfet VAR GPIO.1
    
        cnt = 0
       
        CHECK:
        IF boton = 0 THEN TEST
        LOW mosfet
        GOTO CHECK   
        
        TEST:
        IF cnt < 3 THEN OFF_MOSFET
        IF cnt => 3 THEN ON_MOSFET
        GOTO CHECK
        
        OFF_MOSFET:
        PAUSE 100
        IF boton = 0 THEN
        low mosfet
        cnt = cnt + 1
        ENDIF
        GOTO CHECK
        
        On_MOSFET:
        HIGH mosfet
        pause 1000
        low mosfet
        cnt = 0
        GOTO CHECK
        end
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Sep 2010
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Code:
    DEFINE OSC 4
       @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
        CMCON=7 
        
        cnt VAR BYTE
        boton VAR GPIO.2
        mosfet VAR GPIO.1
    
        cnt = 0
       
        CHECK:
        IF boton = 0 THEN TEST
        LOW mosfet
        GOTO CHECK   
        
        TEST:
        IF cnt < 3 THEN OFF_MOSFET
        IF cnt => 3 THEN ON_MOSFET
        GOTO CHECK
        
        OFF_MOSFET:
        PAUSE 100
        IF boton = 0 THEN
        low mosfet
        cnt = cnt + 1
        ENDIF
        GOTO CHECK
        
        On_MOSFET:
        HIGH mosfet
        pause 1000
        low mosfet
        cnt = 0
        GOTO CHECK
        end
    Hi guys, thanks again, your are wonderfull!!.

    Unfortunately, this code gives me error 118.

    Thanks.
    Best regards.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    If you are setting the configs in code space comment that line out.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Sep 2010
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    Hi Dave, yes thats it.

    When I delete the first 2 lines "define ocs" and "@...", both codes compile ok.

    Unfortunately, the behaviour is basicaly the same....they start with led off, and it should be on, more over, the counting is not regular, it depends in the speed of the click.
    Some times, it goes off at 3, others at 5...etc....

    I dont know....it is very over me.
    I have tried to cut here and there taking ideas from both codes, but it does not work either.

    I have to mention, that the clicks will be very fast, we could have posibly.......20 clicks per second, but we need to stop the mosfet after counting 3 clicks, hence the pause for 1 second.

    I am sorry, my spanish brain is too tyre and can not speak properly.

    Thanks for helping me guys.
    Much appreciated.

    Best regards.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You might not need the
    DEFINE OSC 4
    but it is a good idea to put it in. That is the line that tell PBP how fast the chip is running. I assume you are using the 4MHz internal.

    The state of the mosfet/led depends on how you have the hardware setup. Just change the LOW/HIGH around to do what you want.

    Like I said before. This will need a good denouncing routine to work correctly. Now that you say the button could be pressed at 20HZ even more so. What is going to press a button that fast?

    Here are a couple of threads that might help you.
    http://www.picbasic.co.uk/forum/showthread.php?t=13516
    http://www.picbasic.co.uk/forum/showthread.php?t=2180

    Read them all the way through.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2010
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    Hi dave,

    Thanks for your help, I will have a look at the links later.

    Yes you are right, I am using the internal oscillator at 4 mhz.

    The botton is pressed by a piston.
    So I need to stop the piston after 3 pulses.

    Thanks.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Is it really a button type switch or some other kind of sensor?

    I ask because a mechanical switch may not be the best at high speeds.

    And the way you have the code implies the button is pulled high and at button press goes to zero volts. This can cause arcing as the contacts open giving the chance of several "make/breaks" on each press.

    If the switch were wired pulled low and pressing it brought it high then the arcing is almost not a problem.

    Just thoughts....
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Exclamation

    Quote Originally Posted by gutisie View Post

    The botton is pressed by a piston.
    So I need to stop the piston after 3 pulses.

    Thanks.
    Some Hall effect sensor would be to consider, instead ...

    just me ...

    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 " !!!
    *****************************************

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