Shop OBEX P1 Docs P2 Docs Learn Events
shift registers and sensors — Parallax Forums

shift registers and sensors

lighting ladylighting lady Posts: 7
edited 2009-12-30 17:35 in General Discussion
in the past I created a project that used four shift registers, a memsic sensor, basic stamp. I have now created the same project using three shift registers and cannot get the code to work properly. Can anyone please please help me get this working with three shift registers?
Thanks. Only 8 pins are used


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

Clock PIN 0
SerData PIN 1
Latch PIN 2
Clock2 PIN 3
SerData2 PIN 4
Latch2 PIN 5
Clock3 PIN 6
SerData3 PIN 7
Latch3 PIN 8
Clock4 PIN 9
SerData4 PIN 10
Latch4 PIN 11

Delaytime CON 100

pattern VAR BYTE


x VAR WORD

y VAR WORD


Reset:
LOW Latch
pattern = %00000001

Main:
DO
GOSUB Out_595
PAUSE DelayTime
pattern = pattern << 1
LOOP UNTIL (pattern = %10000000)
DO
GOSUB Out_595
PAUSE Delaytime
pattern = pattern >> 1
LOOP UNTIL (pattern = %00000001)

GOTO main

Out_595:
SHIFTOUT SerData, Clock, MSBFIRST, [noparse][[/noparse]pattern]
SHIFTOUT SerData2, Clock2, MSBFIRST, [noparse][[/noparse]pattern]
SHIFTOUT SerData3, Clock3, MSBFIRST, [noparse][[/noparse]pattern]
SHIFTOUT SerData4, Clock4, MSBFIRST, [noparse][[/noparse]pattern]
PULSIN 14, 1, x
PULSIN 15, 1, y
IF x < 2300 THEN PULSOUT Latch, 5
IF x > 2800 THEN PULSOUT Latch2, 5
IF y < 2300 THEN PULSOUT Latch3, 5
IF Y > 2800 THEN PULSOUT Latch4, 5
RETURN

END

Comments

  • kwinnkwinn Posts: 8,697
    edited 2009-12-29 06:35
    3 shift registers x 3 pins each would require 9 pins would it not? Or do you mean only pins 0 to 8 are used?

    Also I would suggest removing code related to the unneeded fourth shift register.

    The code looks like it should work but what do the PULSIN commands measure? Could that input be between 2300 and 2800, which would mean no latch pulse is produced?
  • lighting ladylighting lady Posts: 7
    edited 2009-12-29 22:02
    Hi,
    Yes the pins are 0 to 8.
    I did delete the code for the unneeded fourth shift register.
    how do I measure the PULSIN commands. And when I deleted latch 4, what get replaced by that? "y" as you know works for the memsic sensor and so if I delete the y component what happens then?
    Thanks,
    ml
  • kwinnkwinn Posts: 8,697
    edited 2009-12-29 23:23
    The PULSOUT commands transfer the data from the serial shift registers to the output registers in the '595's so if you remove the shift register you no longer need the associated latch command or pulsout command. In other words if you removed 595 number 4 you no longer need the

    SHIFTOUT SerData4, Clock4, MSBFIRST, [noparse][[/noparse]pattern]
    or
    IF x < 2300 THEN PULSOUT Latch4, 5

    If the PULSIN 14 and 15 are from the memsic sensor and both read between 2300 and 2800 no PULSOUT command will be executed so no data will be shifted to the output register of any of the remaining 3 '595's.
  • lighting ladylighting lady Posts: 7
    edited 2009-12-30 05:44
    okay, some of that makes sense. so how would it code read after the
    Out_595:
    SHIFTOUT SerData, Clock, MSBFIRST, [noparse][[/noparse]pattern]
    SHIFTOUT SerData2, Clock2, MSBFIRST, [noparse][[/noparse]pattern]
    SHIFTOUT SerData3, Clock3, MSBFIRST, [noparse][[/noparse]pattern]
    SHIFTOUT SerData4, Clock4, MSBFIRST, [noparse][[/noparse]pattern] get ride of this line in code
    PULSIN 14, 1, x
    PULSIN 15, 1, y
    IF x < 2300 THEN PULSOUT Latch, 5 do i delete this and all that follows?
    IF x > 2800 THEN PULSOUT Latch2, 5
    IF y < 2300 THEN PULSOUT Latch3, 5
    IF Y > 2800 THEN PULSOUT Latch4, 5
    RETURN

    END

    so, if i understand correctly, nothing goes beyond the first shift register. yes?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-12-30 06:12
    You delete "SHIFTOUT SerData4,Clock4,MSBFIRST,[noparse][[/noparse]pattern]" and "IF Y > 2800 THEN PULSOUT Latch4, 5"

    What do you mean by "nothing goes beyond the first shift register"?

    I suggest you download the "StampWorks Manual" here:
    www.parallax.com/StoreSearchResults/tabid/768/txtSearch/stampworks/List/0/SortField/4/ProductID/144/Default.aspx

    and look at Experiment #23 which discusses how the 74HC595 works and how to use it with the Stamp.
  • kwinnkwinn Posts: 8,697
    edited 2009-12-30 17:35
    RE "IF x < 2300 THEN PULSOUT Latch, 5 do i delete this and all that follows?"

    No, you only get rid of the "IF Y > 2800 THEN PULSOUT Latch4, 5" line. The first three lines stay. If you do not send the PULSOUT signal to the '595 after sending the data out on the serial line the data will not be written to the output latch of the '595 and whatever it is connected to will not see the data.

    If the PULSIN 14 and 15 are from the memsic sensor and both are between 2300 and 2800 none of the PULSOUT commands will be executed so no data will be shifted to the output register of any of the remaining 3 '595's. If this is not the problem then you may have a hardware fault.
Sign In or Register to comment.