First Memory Chip – stage 2

Having shown we can write to a memory chip using Arduino/Redboard we need to try to do the same without using a microcontroller.  Before I dismantle the Fibonacci circuit we might as well use it as a data source for testing this.

Writing the data shouldn’t be too difficult but is worth considering anyway.  As long as we don’t try to run it too quickly we should avoid timing problems such as the address being changed before a data value has been written.

So each of the 3 states we had before now does a little bit more work –

1 Add A to B, store in C Set address for memory
2 Copy B to A Set write/chip enable and store data (C) from I/O pins to memory
3 Copy C to B Disable chip/write access

If we set up a clock-controlled counter, as we have previously, the addressing for the memory is straightforward enough.  We can have the I/O pins permanently connected to the output from C as they will be ignored except when we’re writing.

Also note that our counter only going from 0 to 15 is not a problem as the Fibonnacci numbers have exceeded 255 before we get to the 16th term so we’ve run out of values to store.

So writing looks reasonably OK but how would we know we’ve managed to do it?  We need to be able to read the data as well and that throws up some additional problems.  It seemed sensible to me to modify our control circuit so it will write the values until C exceeds 255 at which point it switches to a different mode and reads data from memory.

That means we can use the carry out signal from the adder to control the mode.  We can AND that signal (or its inverse) with the output of the 4017 signal pins to  control what happens in each state.  Here’s a modified circuit with two lots of LEDs.

newfibcontrollerThe upper half is much the same as before with a 555 timer, a 4017 and a 4071.  The outputs now go to the pair of 4081 (quad AND gates) so whichever 4017 output is High will light one of the LEDs (remember the LEDs are just to help us see what’s going on).  The arrows indicate the feeds for the second input to each AND gate (one feed for the gates in one 4081 and one for the other).  In the picture we’re just testing so these feeds are connected to the power rails but later we’ll use the carry out signal and its inverse so only one of these feeds will be High.  That means either the yellow LEDs will light in sequence or the green ones will.  The outputs from the left hand 4081 will control the clock/enable for registers A, B and C as before so when the yellow LEDs are on we’re in write mode.

Note that when reading from memory we need to disconnect C from the I/O pins or we have potential confusion (and possible chip damage?) when we try to read the pins.  So we need to revisit the tri-state connections that we looked at earlier and use these to connect the outputs from C to the I/O pins of the memory chip.  In write mode the I/O pins are thus loaded with the value from C but in read mode the pins can be used as outputs.  In both cases the LEDs connected to the I/O pins let us see what is going on so we don’t need the LEDs for C any more.

(Incidentally, note that when I refer to states 1, 2 or 3 that has nothing to do with the tri-state connections but actually refers to the circuit states listed in the table at the top of this page.)

fibplusmem1The small board to the left is the 4-bit counter.  It is correctly connected to the address pins on the memory board (bottom) but is not receiving a clock signal from anywhere so is not doing anything yet.  The memory board is the same as for the initial test using the Redboard but the three enable pins are just hard wired at the moment.  The data for the I/O pins comes from the middle board which is the tri-state connections for the output from C.  The upper board is just the C-register board from the Fibonacci circuit but with the LEDs removed and board being viewed upside down compared to the image on that page!

In the middle board the common feed to the transistor bases is just wired to the +ve power rail at this test stage but will need to be controlled so it is only High when we’re in write mode state 2.  Essentially the signals from the eight C outputs will only reach the memory I/O pins if this common feed is High.  We can also use the inverted signal controlling state 2 to manage the write enable of the memory chip – write enable needs to be Low when we’re writing data.

At this test stage the LEDs on the memory board do show the values for C as the circuit does its work so everything is OK so far and we just need to sort out the changes for read mode.  However note that the LEDs are only on in state 2 since neither write nor output is enabled in states 1 or 3.  So far so good.

Adding Read Mode

As I’ve said we can use adder carry out to switch to read mode.  We have a reset button to go back to write mode if we wish to do so so we probably don’t need an automatic switch back to write mode, we just let read mode loop through the first 16 values (the last few of which may not be part of our series) until a reset.

In the read mode the three registers can be ignored; their work is done.

Reading is potentially simpler when all we’re doing is showing the value on the LEDs so we could actually read a value for each clock cycle but I decided to show each value for 3 clock cycles.  In later circuits we may have to do more work as we did for writing – eg controlling the output/chip enable while we’re changing addresses.

In any case, having dealt with the write enable pin we need to look at the other two.

The Output enable pin needs to be Low when we’re reading and High when writing but that just means it matches the control for read/write mode so is easy to add.

The Chip enable pin needs to be Low when we’re in read mode or we’re in state 2 in write mode but for our purposes can actually be low all the time without affecting anything.  That may not always be the case.

That just leaves adding a link from the zero output of the 4017 (ie state 1) to the counter so it steps through the values 0 to 15 for addressing the memory.  I didn’t worry about resetting the counter since we’re just looping round a small area of memory and I don’t really care where it starts.

So here’s a picture of the complete circuit.  The C-register board is now back the way it was and I’ve labelled each of the boards to show what they are.

fibmemfull

That’s it! It works and the calculated values are written to memory and then read back in a loop.  We’ve successfully gone from storing 3 one-byte values to storing around 13 values and could obviously store more.  There are some loose ends such as ensuring we start at the beginning of the memory and don’t lose any values at the start of our series but these could all be dealt with if required, I’m not going to bother as I want to move on.

Before doing so I substituted a different memory chip – the STMICROELECTRONICS M48Z02-70PC1 which is a NVRAM chip.  That means it is non-volatile memory so should be able to hold my sequence of values even when the power is removed.  It’s a bulkier chip and cost around 7 times as much as the CY7C199CN so I was wary about using it until I’d experimented with the cheaper version!  I ran the circuit once and modified it so it no longer was writing to memory and the chip did indeed hold the values – I tested several times over the next week and the values were held.  I’d already proved to myself that the CY7C199CN didn’t hold values for long without power.

Summary of changes to Fibonacci circuit

  • Switch to a 5V power supply to protect the memory chip
  • Modify control circuit to differentiate between read and write modes.
  • Create 8 tri-state switches to control when C can write to memory.
  • Remove LEDs from C and feed output instead to tri-state switches.
  • Connect tri-state switch outputs to I/O pins of memory.
  • Use write mode state 2 to control the tri-state switches.
  • Create 4-bit counter and connect to lowest 4 address pins of memory.
  • Use the carry from the adder to switch modes rather than reset the circuit.
  • Add the connections to the three enable pins on the memory chip.
  • Add the clock connection for the counter circuit.

Leave a comment