Shop OBEX P1 Docs P2 Docs Learn Events
Need help using input switches and other stuff (For theater set at school) - Page 2 — Parallax Forums

Need help using input switches and other stuff (For theater set at school)

2»

Comments

  • Tech-ManTech-Man Posts: 100
    edited 2007-11-09 22:28
    Have i made the corect changes to the code

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    Clear:
    LET B3 = 0



    Again:

    POT 3, 115, B6
    IF B6 >= 231 THEN clear
    GOTO ID_sw
    Display:
    value = B7 <<<<<<<<<<<<<<<<<<<<< Right here it says "Label is missing"
    GOSUB send

    ID_sw:
    IF B3 > 8 THEN skip
    B3 = B3+1
    GOTO again
    Skip:
    FOR B7 = 0 TO 7
    LOOKUP B7,(7,41,75,108,141,172,201,229),B8
    IF B6 <= B8 THEN done
    NEXT

    done: GOTO Display

    So now how do i stick them together.

    I wish i knew all this stuff you know. I need to order the book so i can just set down and read it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-09 22:39
    The symbol declarations in the "send" routine go at the beginning of your program, after the STAMP and PBASIC directives.
    These have the definitions, including for "value". That's why you got the error. You have to combine these two pieces.

    The section in the "send" stuff for initialization go before your Clear label.

    The subroutine itself goes at the end of your program.

    It's not as satisfying as thumbing through a book, but you can download the PBasic manual as well as all the other Parallax manuals.

    I think you made the changes properly to the input routine except for the GOTO Clear which is now missing.
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-09 22:53
    This is what i wound up with don't know if its curect but maybe you could take a look

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    SYMBOL data = 1 ' 74HC595 pin 14 wired to BS1 pin 1
    SYMBOL dataPin = PIN1 ' same thing in different form
    SYMBOL clock = 0 ' 74HC595 pin 11 wired to BS1 pin 0
    SYMBOL latch = 2 ' 74HC595 pin 12 wired to BS1 pin 2

    SYMBOL temp = W0 ' a temporary word variable
    SYMBOL temp15 = BIT15 ' most significant bit of w0
    SYMBOL i = B2 ' another temporary used as a counter
    SYMBOL value = W2 ' just a word variable
    ' part of your initialization routine
    LOW clock ' initialize clock line to output low
    LOW latch ' initialize latch line to output low
    LOW data ' initialize data line to output low
    ' subroutine to transfer a word from "value" to the register
    send:
    LET temp = value ' make a temporary copy of value
    FOR i = 1 TO 16 ' 16 bits to transfer
    LET dataPin = temp15 ' put most significant bit on data line
    LET temp = temp * 2 ' shift to next bit in temporary value
    PULSOUT clock,1 ' put out clock pulse
    NEXT i
    PULSOUT latch,1 ' put out latch pulse to copy to output register
    RETURN


    Clear:
    LET B3 = 0



    Again:

    POT 3, 115, B6
    IF B6 >= 231 THEN clear
    GOTO ID_sw
    Display:
    value = B7
    GOSUB send
    GOTO clear:

    ID_sw:
    IF B3 > 8 THEN skip
    B3 = B3+1
    GOTO again
    Skip:
    FOR B7 = 0 TO 7
    LOOKUP B7,(7,41,75,108,141,172,201,229),B8
    IF B6 <= B8 THEN done
    NEXT

    done: GOTO Display

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-09 23:06
    The send subroutine (from send: through the RETURN) needs to be moved to the end of the program (after done: GOTO Display).
    Try compiling it and see what happens. Don't have the high power stuff connected until the program is working. You can use a
    voltmeter or an LED with its series resistor on the outputs of the 74HC595 to see what's going on. The LED substitutes for the
    LED in the optocouplers.
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-09 23:18
    Ok i made the changes so this is what it looks like

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    SYMBOL data = 1 ' 74HC595 pin 14 wired to BS1 pin 1
    SYMBOL dataPin = PIN1 ' same thing in different form
    SYMBOL clock = 0 ' 74HC595 pin 11 wired to BS1 pin 0
    SYMBOL latch = 2 ' 74HC595 pin 12 wired to BS1 pin 2

    SYMBOL temp = W0 ' a temporary word variable
    SYMBOL temp15 = BIT15 ' most significant bit of w0
    SYMBOL i = B2 ' another temporary used as a counter
    SYMBOL value = W2 ' just a word variable
    ' part of your initialization routine
    LOW clock ' initialize clock line to output low
    LOW latch ' initialize latch line to output low
    LOW data ' initialize data line to output low
    ' subroutine to transfer a word from "value" to the register



    Clear:
    LET B3 = 0



    Again:

    POT 3, 115, B6
    IF B6 >= 231 THEN clear
    GOTO ID_sw
    Display:
    value = B7
    GOSUB send
    GOTO clear:

    ID_sw:
    IF B3 > 8 THEN skip
    B3 = B3+1
    GOTO again
    Skip:
    FOR B7 = 0 TO 7
    LOOKUP B7,(7,41,75,108,141,172,201,229),B8
    IF B6 <= B8 THEN done
    NEXT

    done: GOTO Display

    send:
    LET temp = value ' make a temporary copy of value
    FOR i = 1 TO 16 ' 16 bits to transfer
    LET dataPin = temp15 ' put most significant bit on data line
    LET temp = temp * 2 ' shift to next bit in temporary value
    PULSOUT clock,1 ' put out clock pulse
    NEXT i
    PULSOUT latch,1 ' put out latch pulse to copy to output register
    RETURN


    I uploaded it to the stamp and nothing when i press the butons nothing happens.

    ill check the wireing but i don't think thats the proglum.

    any ideas.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-09 23:59
    when i bypass the resistors from 5v to pins 10 it turns on lights but there the rong ones. and·9-16 are one even when no swich is pressed. But get this when i press a switch its binary value shows up in the LEDs that is weird.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.

    Post Edited (Tech-Man) : 11/10/2007 12:04:17 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-10 00:23
    Pin 10 is the Master Reset pin. When it's connected to ground, the shift register is cleared to zero. Connecting it to +5V prevents this.
    The shift register is transferred to the output pins only when "latch" is pulsed. If you have the optocouplers connected backwards, it
    could reverse the on/off sense for the lights. The optocouplers should have their cathodes connected to ground and their anodes connected
    through a resistor (like 330 or 470 ohm) connected to the I/O pins. Another option would be to reverse the bits sent to the 74HC595s. You
    could do this by changing the "value = b7" to "value = b7 ^ $FFFF".
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-10 04:57
    Well 9-16 dont come on now for random resions. but do you get what i mean when i say the LEDs display the swich value in binary

    there are eight LEDs hucked up to chip one this is what they display when the switches are pressed.

    sw0 00000000
    sw1 00000001
    sw2 00000010
    sw3 00000011
    sw4 00000100
    sw5 00000101
    sw6 00000110
    sw7 00000111

    it should be like this right

    sw0 00000001
    sw1 00000010
    sw2 00000100
    sw3 00001000
    sw4 00010000
    sw5 00100000
    sw6 01000000
    sw7 10000000




    its working but deffinitly not curectly.

    What would make it count binary to its self.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.

    Post Edited (Tech-Man) : 11/10/2007 5:09:30 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-10 05:04
    Ah! Where you've got "value = b7" substitute "LOOKUP B7,(1,2,4,8,16,32,64,128,256,512,1024,2048),value"
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-10 05:47
    Ok so i really wish i knew what that means but it works. You are a life saver, really you are thanks. so now when i press the switches the corisponding lights light up like it is suposed to. So if i add the rest of the switches 9-16 will they also light the LEDs on chip two, like 1-8 did on chip one. Or must i add more numbers to what you just gave me like keep going 2048 to 4090 to 8180 and so on. And when i huck up the switches like this using the POT command will it mater if some of the resistors arnt the same value, im out of 1k resistors but got a bunch of others.

    Also what must i add so that when i fist turn it on no lights are on. Becuse right now if i turn off the BS1 then turn it back on all the lights will be on at first till a button is presed. And that is not good since this platform is wheeled out during a blackout then the the lights do there thing as the kid wlaks down them and back up.

    I have a few more questions that i know you could help me with but i think i have ask enuff for one day and its getting late, I have another work day all day up at the school tomaro. Ill install the high power lights under each steps then maybe try this code out on it just to see what we got so fare. But ill have to bring it back to work on it some more since id love to figure out how to add some stuff to it, maybe with your help.

    Im in a digital electronics class at school we have a bunch of them Boe Bots but we havent got to them yet. Were working with gates right now like the 7400 or 7032 AND OR NOR that stuff. I love that class since most the time im teaching myself that stuff at home just for fun. It always comes to me better when its explaned though.

    Thanks a bunch for helping me figure this out so fare. Its about 90% done now since now that the inputs can output id like to add some sequences in betwen. But ill have to see tomaro how i can do that i dont know yet how and when he walks up the steps, but tomaro is a full cast rehersal so ill be watching. I love being a stage tech.

    thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-10 06:05
    Put "value = 0", then "GOSUB send" just before the Clear: label. That will clear the output register during the initialization.

    The LOOKUP statement I gave you will handle up to 12 bits, but your input routine will only produce values from 0 to 7.
    You'll need values from 0 to 11 to activate all the 12 bits.

    Rather than trying to add 4 more resistor values which is a bit more finicky than a total of 8 values, I'd suggest a completely
    different way to read switch inputs (using a pair of 74HC165 input shift registers). Given that the setup works with the 8
    switches, I'd suggest that you use what you've got. When the show is over, have a look at the StampWorks manual,
    Experiment #24. This shows how to do the multiple inputs with a BS2. You can do the same thing with a BS1, just like
    with the 74HC595. Ask again after the show is struck and you have some time to do some experimenting.
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-10 07:03
    Ya i dont think i specified that one of my goles was to drive a total of 11 steps. It was not in the original plan but it has 11 steps so.... Well ill check back tomaro night after the work day tell you how it all went. Last wekend we were there from 9:00 to 6:00 in the evning. That makes for a long day.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-10 17:24
    Probably the easiest thing to do since you have 4 extra pins is to connect a resistor (say 4.7K) from 3 of
    the extra I/O pins (I/O 4, I/O 5, and I/O 6) to +5V (Vdd) and a switch from each of the 3 I/O pins to ground.
    That will make the I/O pin high normally and low if the switch is closed. Since you only need 11 switches,
    you'll have one extra I/O pin.

    Right before the "LOOKUP B7,(1,2,4,8,16,32,64,128,256,512,1024,2048),value", put the following
    if in4 = 1 then skip4 ' if the switch is open, skip next statement
    b7 = 8                     ' the LOOKUP will turn on bit 8
    skip4:
    if in5 = 1 then skip5
    b7 = 9                     ' the LOOKUP will turn on bit 9
    skip5:
    if in6 = 1 then skip6
    b7 = 10                   ' the LOOKUP will turn on bit 10
    skip6:
    

    Post Edited (Mike Green) : 11/10/2007 5:29:05 PM GMT
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-11 03:12
    So that was a long day 9:00 to 8:00. Got the steps all wired there alsome loking with just the switches and SSRs but would be even better with the use of the BS1 so once more im going to try and figure that out. So the way i read what you have above is, use the pot comand for 8 switches then the rest use an I/O pin that is left over. im going to try this out if i can find some 4.7K resistors.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-11 03:48
    I huked it up and it did not work it made everything dimm like a short.

    This is what i got from what you said above


    5v
    |
    4.7K | Sw
    pin
    /\/\/\
    @
    |_/|
    |> ground

    But this must be rong, i dont understand what you are saying

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2007-11-11 05:22
    Tech-Man,
    Reverse the connections to your·pin and 5V connection so that it looks like this....· Neat project by the way!
    ·
                           pin
                            |
                 4.7K       |          Sw
    5v ---------/\/\/\------@---------|_/|-----------|> ground
    



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Tech-ManTech-Man Posts: 100
    edited 2007-11-11 16:14
    Ill try that real quick but iv got to get going for another full day of set building.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
Sign In or Register to comment.