74HC165 - Random Errors on Initial Read. . .
everest
Posts: 141
Sorry to bother everyone *again*. . .but I've just spent the last 4 hours chasing a bug in my project, and after isolating all the components and doing a lot of experimentation I've just figured out the source of my problem. . .
Short story, I'm following the exact same schematic that's in StampWorks Experiment #24 and I'm using almost exactly the same code (just different debugging). I've attached the code and schematic for reference.
PROBLEM: The *first* time the Stamp2 reads the values from the 74HC165 I'm seeing the opposite values get reported. . .but this is immediately corrected after the first read. For example, I've closed the switch connected to pin 11 on the 74HC165. . .I should see a "1" reported for that pin, but the FIRST read comes back with a "0". . .the second correctly reports a "1" and things seem to work perfectly after that.
But this initially bad data is wreaking havoc with my application! I absolutely have to get reliable and 100% correct data out of this 74HC165. . .any ideas on what's going on here?? I've tried two separate 74HC165 units, and two Stamp2 units. . .the results are identical across all of them.
-Jeff
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates a simple method of turning three BASIC Stamp
' I/O pins into eight digital inputs with a 74HC165 shift register.
'
[noparse][[/noparse] I/O Definitions ]
Clock PIN 2 ' shift clock (74HC165.2)
SerData PIN 5 ' serial data (74HC165.7)
Load PIN 1 ' output latch (74HC165.1)
'
[noparse][[/noparse] Constants ]
DelayTime CON 100
'
[noparse][[/noparse] Variables ]
switches VAR Byte ' switch data
'
[noparse][[/noparse] Initialization ]
Reset:
HIGH Load ' make output and high
PAUSE 500
'
[noparse][[/noparse] Program Code ]
Main:
DO
GOSUB Get_165 ' get switch inputs
DEBUG CLS, "Roof_Open = ", DEC switches.BIT0, CR
DEBUG "Roof_Closed = ", DEC switches.BIT1, CR
DEBUG "Roof_Control = ", DEC switches.BIT2
PAUSE 100
LOOP
'
[noparse][[/noparse] Subroutines ]
Get_165:
PULSOUT Load, 5 ' load switch inputs
SHIFTIN SerData, Clock, MSBPRE, [noparse][[/noparse]switches] ' shift them in
RETURN
Short story, I'm following the exact same schematic that's in StampWorks Experiment #24 and I'm using almost exactly the same code (just different debugging). I've attached the code and schematic for reference.
PROBLEM: The *first* time the Stamp2 reads the values from the 74HC165 I'm seeing the opposite values get reported. . .but this is immediately corrected after the first read. For example, I've closed the switch connected to pin 11 on the 74HC165. . .I should see a "1" reported for that pin, but the FIRST read comes back with a "0". . .the second correctly reports a "1" and things seem to work perfectly after that.
But this initially bad data is wreaking havoc with my application! I absolutely have to get reliable and 100% correct data out of this 74HC165. . .any ideas on what's going on here?? I've tried two separate 74HC165 units, and two Stamp2 units. . .the results are identical across all of them.
-Jeff
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates a simple method of turning three BASIC Stamp
' I/O pins into eight digital inputs with a 74HC165 shift register.
'
[noparse][[/noparse] I/O Definitions ]
Clock PIN 2 ' shift clock (74HC165.2)
SerData PIN 5 ' serial data (74HC165.7)
Load PIN 1 ' output latch (74HC165.1)
'
[noparse][[/noparse] Constants ]
DelayTime CON 100
'
[noparse][[/noparse] Variables ]
switches VAR Byte ' switch data
'
[noparse][[/noparse] Initialization ]
Reset:
HIGH Load ' make output and high
PAUSE 500
'
[noparse][[/noparse] Program Code ]
Main:
DO
GOSUB Get_165 ' get switch inputs
DEBUG CLS, "Roof_Open = ", DEC switches.BIT0, CR
DEBUG "Roof_Closed = ", DEC switches.BIT1, CR
DEBUG "Roof_Control = ", DEC switches.BIT2
PAUSE 100
LOOP
'
[noparse][[/noparse] Subroutines ]
Get_165:
PULSOUT Load, 5 ' load switch inputs
SHIFTIN SerData, Clock, MSBPRE, [noparse][[/noparse]switches] ' shift them in
RETURN
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Don't worry. Be happy
That did it!!! WOW!! Seriously, have you ever encountered a Stamp2 related question that you couldn't answer? This is forum is like my "Mike Hotline". Thanks, I really appreciate all the help you've given me over the last few months. Learning is much easier with an occasional nudge in the right direction.
2) This group of forums is a support site for Parallax, a developer and manufacturer of microcontrollers and related products primarily for the educational and hobby robotics market. Their products, particularly the microcontrollers, are also used in industrial products. Their website (www.parallax.com) has several pages on the company, it's history, and a full product catalog.
3) This specific forum is for support of Parallax's Basic Stamp products. Here people discuss the Stamps and things that are used with Stamps. They discuss the software tools used with Stamps, problems with their own projects or simply "what's it good for?". I say discuss because some people are trying to learn the basics and some people are experts in various topics. Some people are trying to do simple things and some people have very ambitious projects. Some people are trying to learn whatever they can and some people enjoy helping others. Various employees of Parallax also participate here, some because it's part of their job and some because they happen to know a lot and like to help out.
Whatever you do, you do it well!! Thanks and keep it up!!
-Jeff