Newbie - 16F628A and switch latching


Closed Thread
Results 1 to 40 of 46

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Hee hee - fancy seeing you here

    Yes I have downloaded the manual, and had it open last night whilst I was developing the program, and as manuals go its really good to get newbies like myself up and running.

    Must admit, that I'm having more fun (and luck) with PBP than I did with JAL. PBP seems more logical in its commands and the structure of using them.

    Alain, let me into a secret, is that Melanie in her avitar... brains as well as beauty - wow !!

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


    Did you find this post helpful? Yes | No

    Wink The Forum' Highest secret ...

    Quote Originally Posted by malc-c
    Hee hee - fancy seeing you here

    Alain, let me into a secret, is that Melanie in her avitar... brains as well as beauty - wow !!
    In fact, Mel is some like Charly in the "Charly's girls" TV series ... I do not think anyone on this forum knows her real appearance ...

    We only know she says she likes to wear leather clothes at night, and is a bit bored about charming guys hoping to get something from her brain ...

    May be she'd love to find a bunch of red roses and some Champagne at her door rather than the New up to date Compiler ....

    Talk to her gently, and she'll give you the best from her ...

    That's part of what I understood here ... not to break the magic.

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

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


    Did you find this post helpful? Yes | No

    Default

    There are those that have sent boxes of red roses...

    ...and there are those that have sent boxes of chocolates...

    ...boxes of diamonds are a little slower in coming - but I'm working on it...

    ...and there are those that have seen a little more of me than others (I seldom refuse an invite to dinner - especially if you're buying - but can you afford a genuine up-town girl?) *smiles*

    ...and Yes, that's really me in the avatar... if you're real nice I just might change it for a while to something more sophisticated - but I'm always worried that I'll distract you from your work (or play)...

  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 Melanie
    ... if you're real nice I just might change it for a while to something more sophisticated -
    I have a feeling of what it could be Maybe i'm in the 3rd category ... LOL easy to start some rumor here

    BTW Melanie, if you change your Avatar to 'something more sophisticated', i feel that some end-of-class student here could be shocked OR spam your PM! May i bet on the second one
    Last edited by mister_e; - 15th May 2006 at 03:34.
    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,358


    Did you find this post helpful? Yes | No

    Default

    My PM is already spammed...

    Dear Miss Whiplash... Thank you for last nights session... I won't be able to sit down for a week, but it was worth every minute... PS My PIC still doesn't work.

    Now, now Steve... people might get the wrong idea on how you ended up in hospital...

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default lets get this back on topic before I need a cold shower !

    I'm hoping that you guys and Miss whippy, sorry Mel can tell me why the following code won't work correctly.

    Having managed to sort out the delay for the debounce I had each LED bing turned on, latched and turned off by activation of the corresponding reed switch - Great !

    However I now want to evolve the code so that the following happens. The siding has the buffer at the left, and trains enter from the right. A reed switch (sw1) is placed at the start of the siding (on the right), a train enters the siding and activated sw1 and LED1 is lit. The train continues to the end of the siding where it activates the second reed switch (sw2) and thus LED2 is lit, and the operator shuts off the power. So far so good.

    Now the operator can re-arrange the train and place the loco at the other end ready to go back on the main layout. When it does sw1 is then activated again, but this time I need it to clear both LED1 and LED2. Ok I thought, lets simply have a new varible (swset5) that is toggled only when swset1 and swset2 are high.. but it won't work. activating sw1, then sw2, then sw1 again just turns off LED1, LED2 remains lit

    Here is my code (I've yet to try the BUTTON command, but maybe that will happen when I come to tidy up the code ??)

    Code:
    @INTRC_OSC_NOCLKOUT
    @WDT_ON
    @PWRT_ON
    @MCLR_OFF
    @BOD_ON
    @LVP_OFF
    @CPD_OFF
    @PROTECT_OFF
    
    CMCON=7
    TRISB=%00000011         'set RB0 & 1 as input and the rest output
    
    SW1 var PORTB.0          'switch input pin 6 (RB0)
    SW2 var PORTB.1          'switch input pin 7 (RB1)
    
    
    LED1 var  PORTB.4       'LED1 on pin 10 (RB4)
    LED2 var  PORTB.5       'LED1 on pin 11 (RB5)
    
    Swset1 var bit
    Swset2 var bit
    
    Swset5 var bit
    
    low led1
    low led2 
                    
    Swset1=0 
    Swset2=0
    
    swset5=0                'Var swset is set low
    
    Main:
    if SW1=0 then            'If switch is LOW (Grounded) then
    Toggle Swset1            'change swset1 from 0 to 1
    pause 500                'debounce delay
    endif
    
    if SW2=0 then            'If switch is LOW (Grounded) then
    Toggle Swset2            'change swset2 from 0 to 1
    pause 500                'debounce delay
    endif
    
    If Swset1=1 then         'if swset1 is 1
    high led1                'then turn on RB4 (and hence the LED)
    else
    low led1                 'else, LED is off
    endif
    
    If Swset2=1 then         'if swset2 is 1
    high led2                'then turn on RB5 (and hence the LED)
    else
    low led2                 'else, LED is off
    endif
    
    If swset1=1 and swset2=1 then
    toggle swset5
    endif
    if swset5=1 and sw1=0 then
    low led1
    low led2
    else 
    high led1
    high led2
    endif
    
    End
    I have even tried removing the "else" part at the end of the code so it reads
    Code:
    If swset1=1 and swset2=1 then
    toggle swset5
    endif
    if swset5=1 and sw1=0 then
    low led1
    low led2
    endif
    But that still fails to work correctly.

    Any advice guys and gals ??
    Last edited by malc-c; - 15th May 2006 at 13:35.

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


    Did you find this post helpful? Yes | No

    Wink Wrong scenario ...

    Hi, Malc

    as SWset5 is tested AFTER the swset1 ... your condition never can happend, or during so little time, it can't work properly.

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie
    ... I won't be able to sit down for a week, but it was worth every minute...

    Now, now Steve... people might get the wrong idea on how you ended up in hospital...
    How dare you post our private stuff in public

    LOL! yeah maybe you're right... but damn you should be really strong to break my arms, legs and spinal cord. Guys, be aware of that!

    LOL Melanie, at least i wish it could be true

    Ok let's stop it here.. there's somebody who need help here, but Alain give some great tips.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Talking One little last ...for the trip.

    Ok let's stop it here ...

    Thanks to Luciano, ve've a good idea of uptown girls at night ...

    cool, Malc ... cool !!!

    Alain
    Attached Images Attached Images  
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    There is another way of thinking here Alain...

    Once a switch has closed (as detected by the first IF/THEN) then the assumption is that whatever event caused it to close (or open) is not a False Alarm and the event intended to happen (eg a User pressing a button). You therefore need no futher IF/THEN's to see if the contacts are still closed after the debounce time period expries.

    All you have to do is delay looking at that switch again for a period of time greater than any possible contact bounce to ensure you don't register that event a second time (as would happen if you used interrupts for example).

    Now the delay time is really down to the application. I tend to use 100mS for Keyboard Buttons, because that gives an 'auto-repeat' of 10cps which is quite nice when viewed on a display. Naturally, if you're timing something that happens a lot quicker, then you need to reduce the bounce delay time, but if you get it too short, you'll run into the multiple contact closure problem.

    It's difficult to guage and is done mainly by look/see and a bit of experience because different switches (be they contacts on a Switch, Relay or a Reed) all exhibit different closure properties and have different bounce periods. Best method I've found is to overkill the delay as much as possible.

    The best method for registering an event, but discarding any False Alarms, is to see how long a switch remains closed over a period of time. That then will require multiple IF/THEN's both at the beginning and at the end of the debounce period.

Similar Threads

  1. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  2. Addressing with Dip Switch or ???
    By tazntex in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th September 2008, 12:19
  3. 16f628a wont wake up
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th August 2008, 14:22
  4. SLEEP mode 16F628A
    By Michael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 25th April 2006, 17:26
  5. 16F628A using PORTA.4, and it works, but...
    By zx81 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th August 2005, 08:45

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