Go Down

Topic: Shift In Register bug (Read 2555 times) previous topic - next topic

cyberrave

I copy pasted the code from the hello world shift register example from http://arduino.cc/en/Tutorial/ShftIn11 and when I test it, I get funny results: my problem is that when I press the 8th bit (2^7 position), I sometimes get 11111111 instead of 10000000(expected result). When this happens, the other buttons connected to my shift in stop working. A hypothesis I have is that my pull-up resistors are of 100 ohm, not the suggested 10k, but This was never a problem before today (using the same chip). I have checked and double checked my wiring and I have tried swapping the register for a new one, but no luck.

Like I said, this sometimes happens, then, for some reason I don't understand, it starts working properly again, and when I least expect it, it stops working (gives 11111111 if the 8th bit is pressed or nothing if any other bit is pressed).

I am using: arduino Uno r3, CD4021BE shift register

Thanks in advance for the help

MarkT

There's something fishy about that code, it uses:

Code: [Select]
delayMicroseconds(0.2);

but delayMicroseconds doesn't know about floats.

shiftIn() is the function you want I think.  You can have a look at its source,
its much more readable - its in wiring_shift.c in <install-dir>/hardware/arduino/cores/arduino/
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Grumpy_Mike

The other thing is have you got decoupling capacitors on the shift register?
http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

cyberrave

Great guys! Thanks a lot! I was not using de coupling capacitors, and after reading the article about it,i think this should also help a whole lot with some stability issues i'm having with my RTC thats on the same project! As fr the shift in function, thanks, I had no clue this existed!

Go Up