Shop OBEX P1 Docs P2 Docs Learn Events
74HC165 - Random Errors on Initial Read. . . — Parallax Forums

74HC165 - Random Errors on Initial Read. . .

everesteverest Posts: 141
edited 2009-09-09 19:09 in BASIC Stamp
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
881 x 545 - 97K

Comments

  • dev/nulldev/null Posts: 381
    edited 2009-09-09 10:50
    Don't know if it wil help, but it can't hurt to put a 10k pulldown resistor on the SER pin (pin 10).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-09 13:52
    Try doing a "LOW Clock" during your initialization. The Clock pin is initially an input and the 74HC165 could see that as anything. Alternatively, you could put a pulldown on the clock pin.
  • everesteverest Posts: 141
    edited 2009-09-09 15:58
    Mike,

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-09 16:16
    A lot of these answers don't come "off the top of my head". I look at the datasheets for devices involved. I may look at the manual (like for the Stamp and SHIFTOUT). I think about what could cause the problem that's seen. I start with the notion that it's often something simple, some assumption that's not really met. In this case, your comment about the initial bit being wrong got me thinking about initial conditions. I learned early on in programming that you have to be very careful about initializing everything or be deliberately positive that it isn't necessary in some cases. The same thing holds true for hardware. You need pullups or pulldowns or some other way to establish initial conditions for logic signals or your logic has to deliberately not depend on initial conditions.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-09-09 17:08
    1) Please be careful about posting duplicate messages. You can delete a message you've posted by clicking on the "X" icon in the upper righthand corner of the message box.

    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.
  • everesteverest Posts: 141
    edited 2009-09-09 19:09
    Mike,

    Whatever you do, you do it well!! Thanks and keep it up!!

    -Jeff
Sign In or Register to comment.