shift registers and sensors
lighting lady
Posts: 7
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
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
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?
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
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.
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?
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.
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.