Shop OBEX P1 Docs P2 Docs Learn Events
& gate operation plus — Parallax Forums

& gate operation plus

stbrnrdstbrnrd Posts: 35
edited 2005-10-02 15:57 in BASIC Stamp
Hello smart people smile.gif

I was wondering if there are any programs to make the bsx2 behave like an 'and' gate for five different signals...i have 5 signals that are coming from 5 different items, and these signals turn on module (A), what i need is an indicator of the signal being present (an led for each signal) but the combination of the 5 to give single a 5vdc out that would be used to overide the other signals to make this module turn on. (there are some faults that have happened because of loss of one or more of the signals with the remaining ones on) but if i centralize them, and only if they're present would this 5vdc signal be generated. i might be asking for a lot, but annnny help would be greatly appreciated.
if anything a better direction would also be greatly appreciated.

thanks in advanced for the input


J.A.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-01 18:53
    Hello,

    ·· By connecting all your inputs to the same port grouping, they can all be read at the same time.· Say your 5 inputs are connected to P0-P4.· Just do:

    IF (INL & %00011111) = %11111 THEN
      HIGH 8
    ELSE
      LOW 8
    ENDIF 
    

    This will make P8 HIGH only when all 5 inputs (P0-P4) are HIGH.· If you need LEDs for each input that would be easy to implement too.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 10/1/2005 6:59:22 PM GMT
  • stbrnrdstbrnrd Posts: 35
    edited 2005-10-01 21:03
    would this be completely out of the ball park?


    it is obvious i need help, but how far off am I?
    your reply will be appreciated.

    ' IF-THEN-ELSE.BS2
    ' The program below generates a ompilation of signals from 5 different inputs,
    ' then turns one pin high; in turn if any of the pins fail, the output of
    ' that designated pin is low.


    ' {$STAMP BS2}
    ' {$PBASIC 2.5} ' version 2.5 required




    Main:
    DO
    IF (INL & %00011111) = %11111 THEN
    HIGH 8
    ELSE
    LOW 8
    ENDIF


    GOSUB Pin_Compilation001 NEXT
    GOSUB Pin_Compilation002 NEXT
    GOSUB Pin_Compilation003 NEXT
    GOSUB Pin_Compilation004 NEXT
    GOSUB Pin_Compilation005 NEXT
    LOOP UNTIL LOW 12 ' off pin command

    END ' end program


    Pin_Compilation001: ' freq pin between 10-100 khz
    COUNT (PIN number)freqGen
    DEBUG feq ? freqGen
    IF >=10khz & =< 100khz THEN
    HIGH 8
    ELSE
    LOW 8
    RETURN ' go back to 1st instruction

    Pin_Compilation002: 'ground pin
    IF (PIN number) <= (PIN number)THEN
    HIGH 8
    ELSE
    LOW 8
    RETURN

    Pin_Compilation003: ' voltage pin
    IF (PIN number) < (PIN number) THEN
    LOW 8
    IF (PIN number) => (PIN number) THEN
    HIGH 8
    RETURN

    Pin_Compilation004: ' off pin
    IF (PIN number) LOW THEN
    LOW 8
    RETURN

    Pin_Compilation005: ' on pin
    IF (PIN number) HIGH THEN
    DO
    RETURN
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-01 21:10
    I didn't try it, but I'm not sure that will compile properly.· You are using the NEXT keyword without a FOR.· That's a big no-no.· Depending on the input into the BASIC Stamp, it is possible to run the LEDs at the input.· Or, to simplify things, you can make P6 the output, and copy the inputs at INL to OUTH and have the LEDs connected to P8 - P12.· One line of code would do that.
    OUTH = (INL & %00011111)
    IF (INL & %00011111) = %11111 THEN
      HIGH 6
    ELSE
      LOW 6
    ENDIF 
    
    


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • stbrnrdstbrnrd Posts: 35
    edited 2005-10-02 01:27
    you were right, it doesn't work... :-( i'll give your samples a try, but how will the stamp know that there are different kinds of inputs (voltage, ground, 10-100Khz)? that's where my problem started with.
    thanks
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-02 03:48
    Hello,

    ·· This is where clarity in posts really helps out.· No mention was made of this in your original message, or any replies up to now.· So everything you've gotten was based on 5 high/low inputs generating a high/low output.· Your original message specified that the BS2sx act like an AND gate, and that's what the code does that I provided.· But if you're introducing other type of signals, that complicates things.· I get the impression an AND gate isn't really what you need.· Perhaps you should provide more details about what the 5 input signals look like?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • stbrnrdstbrnrd Posts: 35
    edited 2005-10-02 06:40
    I apologize for my lack of information, but i figured that if i posted what i thought the code should look like, it would reveal the signals that are being used to get the single output pin.
    I appreciated the codes you have provided. maybe you are right and i should look at something else instead of the stamp;
    I just thought that a single program could be written on one component instead of having 3-9 other components on a board to make things more complicated.
    thanks again for your efforts and sorry for the confusion.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-10-02 07:31
    stbrnrd -

    I'm not sure where you're getting the impression that the Stamp can't read your inputs, apply some decision logic to those inputs, and set one or more outputs accordingly. In fact, that's one of the functions that any microcontroller can do best.

    What IS being said is that the provided code, while still correct in its logical analysis of the signals being presented, must work on conditioned inputs, and not directly on the input pins themselves. One must obtain each separate (possibly hardware conditioned) input, based on its type (analog, digital, pulse, etc) then apply any necessary software filters to it (range, high-low limit, etc) and then set one BIT as the output indicator for that particular input. The input either meets, or doesn't meet the conditioning criteria. If it does, the assigned input status BIT is set ON. If not, the input status BIT is set OFF.

    This process continues until all inputs are fielded (with the appropriate software commands) and all 8 BITS (more or fewer as the case may be) have been either set ON or set OFF. Unused BITs in the input status BYTE are classically are set to the OFF condition, but that may vary with the specific logic applied to it. At the end of this process, you now have a conditioned BYTE (or multiple BYTEs) which represents the met or unmet critera (as tested) for each of the fielded signals, regardless of their type. All input signals now have a common modality and status, all contained in that one (or more) input status BYTE .

    That input status BYTE can now be processed successfully by the prior logic provided, although it must be modified to inspect this "conditions" BYTE as opposed to viewing the raw input from the pin ports.

    I hope that all makes sense. It's not nearly as complicated programatically as it is to describe the process smile.gif

    Regards,

    Bruce Bates
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-10-02 15:57
    Hello,

    ·· Again the point was that not enough information was given to decide how best to proceed, but you still haven't provided that information so anyone could help you.· I never said the BASIC Stamp wouldn't work, just that more information was needed, because you indicated the code given wouldn't work.· I don't know what signals will be present to determine that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.