Especially our visitors from Savage///Circuits and Parallax!!!
Please take a look our new forums, we hope you register and become an active user.
The ZappBots forums are being run on phpBB 3.1.4 software which is different then the vBulletin used on the Savage///Circuits and Parallax forums.
Therefore, things look and work a little different, especially creating posts and uploading images / attachments.
The important thing is we have a place toTalk, Learn and Showcase our projects.
- Posts: 403
- Joined: Tue May 12, 2015 2:43 pm
- Location: Palmyra, NY
March 1st, 2014, 04:59 PM
by Chris Savage
Before using this code you should read and understand this topic and this topic. This example combines those into a single example where the 74HC165 inputs are read and then sent out to a 74HC595. However this example shows how to reduce the number of I/O lines required by the microcontroller from 6 down to 4 by sharing the CLK and Data lines. In order to realize this please look at the attached schematic diagram. Note that the CLK lines are shared by both shift registers and connected to the same I/O pin on the Propeller chip. The data lines are shared too, but because they operate in different directions the data pin from the 74HC165 has a series 1K resistor. The LATCH and LOAD lines still require their own I/O pin but the total count is 4 instead of 6 and you could easily have 32 inputs and 32 outputs using these same 4 I/O pins. As you can see in the photo below I had to move a few wires on the PPDB and add the 1K resistor.
In the previous combined example / demo no pins changes so the code was pretty easy to combine, however by sharing lines there is a consideration that requires us to make a simple code change to avoid conflicts on the I/O pins. The data lines connect to the Propeller chip P1, which needs to be an input to read from the 74HC165 but needs to be an output to write data to the 74HC595. So looking at the new code you'll notice the PRI methods for each shift register have one additional line of code added.
In the writeHC595 method line 58 adds code to change the DATA pin to an output while in the readHC165 method line 73 adds code to change the DATA pin to an input. With these changes and the resistor on the 74HC165 data pin we can share the DATA line without any conflicts. If you're wondering the reason why the resistor on on the 74HC165 data line and not the 74HC595 it's because the 74HC595 data pin is an input, so there would never be a conflict with that pin no matter which direction the Propeller chip P1 pin in set to. The 74HC165 data pin is an output, so when the Propeller chip is writing data to the 74HC595 it would be fighting against the 74HC165 data pin. The resistor allows the 74HC165 to get data into the Propeller chip P1 when P1 is an input and is not affected by the 74HC595, while at the same time preventing contention when P1 is an output. Since P1 connects directly to the 74HC595 input pin the state of the 74HC165 pin won't interfere. I hope you find this useful.
Oh, I wanted to add one thing...while the data changes depending on the state of the inputs, I did want to show you what one cycle of the CLK, LOAD and LATCH pins looks like. As you can see below the LOAD line starts the cycle by copying the data from the inputs into the 74HC165 internal shift register. The 8 clock pulses send this data serially into the Propeller DATA pin and then the data is sent serially out to the 74HC595 as indicated by the small delay and the next 8 clock pulses (remember, in this example both devices share the CLK and DATA lines). At this point the LATCH line is brought high storing the 8 bits from the 74HC595 shift register to the 8-bit parallel outputs, completing the cycle.
- (12.68 KiB) Downloaded 318 times
I'm only responsible for what I say, not what you understand.
Users browsing this forum: No registered users and 1 guest