74HC165, and set of 8 dip switches
knightofoldcode
Posts: 233
Group,
I'm having a hard time understanding what I'm doing wrong here. I have the code I'm working on, posted below.
I get results of 255 everytime it's ran, regardless of the actual dip switch settings.
All of the input pins on the device are pulled high, and the dip switch when in the on position will force the line to ground. I'm following the example in Nuts and Volts #62.
I stripped out almost everything except what's below. Maybe there was something, somewhere else in the code that made it do differently? Anyways, I don't need to debounce these keys, as they are going to be used as a device address for that particular device on a BS network.
On the hardware aspect, as previously stated my parallel inputs have been pulled high with a 10K resistor. The dip switch when in the on position will force that line to ground. Pin 1 of the 74HC165 is set to P0 of the BS2. Pin 2 of the 74HC165 is set to P1 of the BS2. Pin 7 of the 74HC165 is set to P2 of the BS2. Pin 8 of the 74HC165 is set to Ground, the same ground as the BS2, so we aren't having grounding issues. Pin 9 and 10 of the 74HC165 are not connected. Pin 15 (Clock Inhibit) of the 74HC165 is set to ground. And finally pin 16 of the 74HC165 is set to 5V+, again the same 5v+ that is driving the BS2.
The power supply used is a hacked PC power supply, and the BS2 is ran directly off the 5V+ line, so I've got at least 20 Amps, and not using the onboard regulator of the BS2, so I'm not overloading anything. All the hardware connections are the same as the diagram in the N&V's issue #62.
Can anyone tell me what I'm doing wrong here? I'm thinking it's software, but I'm not certain. I'm more comfortable with hardware, and not so hot on the software of the BS2. [noparse]:)[/noparse]
MUCH TIA,
Knight.
I'm having a hard time understanding what I'm doing wrong here. I have the code I'm working on, posted below.
I get results of 255 everytime it's ran, regardless of the actual dip switch settings.
All of the input pins on the device are pulled high, and the dip switch when in the on position will force the line to ground. I'm following the example in Nuts and Volts #62.
I stripped out almost everything except what's below. Maybe there was something, somewhere else in the code that made it do differently? Anyways, I don't need to debounce these keys, as they are going to be used as a device address for that particular device on a BS network.
On the hardware aspect, as previously stated my parallel inputs have been pulled high with a 10K resistor. The dip switch when in the on position will force that line to ground. Pin 1 of the 74HC165 is set to P0 of the BS2. Pin 2 of the 74HC165 is set to P1 of the BS2. Pin 7 of the 74HC165 is set to P2 of the BS2. Pin 8 of the 74HC165 is set to Ground, the same ground as the BS2, so we aren't having grounding issues. Pin 9 and 10 of the 74HC165 are not connected. Pin 15 (Clock Inhibit) of the 74HC165 is set to ground. And finally pin 16 of the 74HC165 is set to 5V+, again the same 5v+ that is driving the BS2.
The power supply used is a hacked PC power supply, and the BS2 is ran directly off the 5V+ line, so I've got at least 20 Amps, and not using the onboard regulator of the BS2, so I'm not overloading anything. All the hardware connections are the same as the diagram in the N&V's issue #62.
Can anyone tell me what I'm doing wrong here? I'm thinking it's software, but I'm not certain. I'm more comfortable with hardware, and not so hot on the software of the BS2. [noparse]:)[/noparse]
'{$STAMP BS2} ' ----[noparse][[/noparse] I/O Definitions ]------------------------------------------------- ' Clock CON 0 ' shared clock line SL_165 CON 1 ' shift/load of 74HC165 DI_165 CON 2 ' serial data from 74HC165 ' ----[noparse][[/noparse] Variables ]------------------------------------------------------- ' byteAddress VAR Byte ' ----[noparse][[/noparse] Init ]------------------------------------------------------------ ' 'HIGH SL_165 ' ----[noparse][[/noparse] Program ]--------------------------------------------------------- ' Main: GOSUB GetAddress DEBUG ? byteAddress GOTO EndlessLoop ' ----[noparse][[/noparse] Sub Routines ]---------------------------------------------------- ' EndlessLoop: GOTO EndlessLoop GetAddress: byteAddress = %00000000 LOW SL_165 PAUSE 1 HIGH SL_165 SHIFTIN DI_165, CLOCK, MSBPRE, [noparse][[/noparse]byteAddress\8] RETURN ' ----[noparse][[/noparse] EOF ]------------------------------------------------------------- '
MUCH TIA,
Knight.
Comments
I've attached a working schematic and code.· Not that you can simplify the code a bit by initializing the Load line HIGH and then using PULSOUT when you want to load the new inputs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
After I did the hardware modifications, my software still didn't do the results I was expecting, however once I plugged in your software, it worked perfect. So, I'll have to figure out what's wrong with my software.
BTW, I followed the schematic to the letter on the Nuts and Volts issue #62. So I think it might be wrong?
MUCH thanx!
Knight.
No biggie, and it works perfect now. [noparse]:)[/noparse] Much, Much thanx.
Knight.
I'm curious, in my setup, I left out the 220 resistors. I realize that they are protection resistors, but that's all I know, I'm not sure why they are needed? The 74HC165 is set to input all the time by it's very nature (obviously, unlike the BS2, in case someone else is reading), so it can't be messed up to act as a output and be grounded, shorting things.
Knight.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Ah! Okay. Thank you!
Knight.