DIY 8-bit computer, Episode A: Arduino-based EEPROM programmer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] okay so welcome to episode 10 in this episode I'll talk about how to build an Arduino based a EEPROM programmer and I'll cover a little bit why you might want to do this we'll talk about interfacing an EEPROM basically how you can make a CPU or in this case a microcontroller talk to the e EEPROM in order to read data from it but more importantly to store data in it we'll cover the hardware design and also the firmware implementation we'll talk about how to construct this circuit including a sort of permanent version of the circuit like I have here we'll talk about the development of the host software that allows you to actually sort of run on your PC a utility that allows you to burn data into an EEPROM device and then we'll talk about whether or not this is a good idea okay let's get started alright so why do we care about a eeproms well very simply we need firmware in our 8-bit computer that's the built-in code that executes when the system boots up definitely need that the EEPROM devices are a very good way to build that in a EEPROM devices unlike other types of programmable memory devices can be programmed without using special programming voltages so if you have a UV erasable EEPROM like this thing they typically require a weird voltages like 12 volts or 21 volts they're a bit harder to generate a eeproms can be programmed using 5-volt logic just normal logic so that makes them pretty easy to work with and in general they're you know they're not very expensive they're easy to find you can probably get get them for like a couple of bucks each so they're good choice the real question here is why would you want to build your own programmer and the main thing you have to think about is that a dedicated device programmer you know like this mini pro TL 866 they are both cheap so you can get it for like you know 50 60 bucks they're also amazingly useful they can program all kinds of different devices they're easy to work with they're just generally useful to have so from a purely economic standpoint you know building your own program they can only program you know these like any prom devices might not make a whole lot of sense however um building things is fun you know we'll learn some stuff by doing this and one economic argument potentially is that if you can build your IEP prom program or using pop parts that you already have you know that you can pull from your jump box you know you might be able to do this for only a few bucks so let's talk about how he promised work and how we interface women and here is a very simplified block diagram showing a to 8 C 2 5 6 et prom device and then a system that is interfaced with it which could be either our 8-bit computer but in this case it's going to be our dedicated EE prom programmer so the idea is that the system sends addresses to the EPROM device to tell it which byte of memory the system wants to access and for a 32k EEPROM there going to be 15 address lines 8 0 through a 14 there is a an 8-bit bi-directional data bus that allows the system to send values to the EEPROM when it wants to write data and then of course is also used for the EEPROM to send data back to the system when a byte is read and then there are control signals there is the C II signal that is the chip enable signal when the system asserts that and note that it is an active low signal to assert so to assert an active low signal the system drives it low when C E is asserted that sort of wakes up the EEPROM and tells the EEPROM that the the system wants to talk to it there is the OE output enable signal and when the system is searched this signal the EEPROM will send the data of the bite that is being accessed as specified by the address lines back to the system so that's how the system reads data from the EEPROM device and then the w/e signal right enable when that is asserted that tells the the e EEPROM that the system wants to write data to it so whatever byte of data is being written by the system on to the data bus is then latched into the internal storage within the EEPROM device and when these control signals are gen there are certain timing characteristics that have to be followed so let's talk about those alright so here we are looking at the data sheet for the Atmel 28 C 256 and here these are the characteristics for reading data and the waveforms for how to read a byte of data from the device and the idea is pretty straightforward and this is pretty characteristic of these parallel memory devices that these old 8-bit systems use that basically what the host system should do if it wants to read is first assert the address that of the data that it wants to access and then assert the chip enable and output enable signals and then some period of time later the memory device in this case the EEPROM will output the requested data on the data bus and the most important timing characteristic here is the access time which is the amount of time between when the address is asserted and when the data actually appears and depending on the speed grade of the device you know for a fast device that could be 150 nanoseconds you know for a more typical device that might be 200 nanoseconds that is plenty fast for these old 8-bit systems where you know you could probably even wait you know 500 nanoseconds and you'd still meet the the timing deadline for the host CPU all right so next let's talk about writing data to an EEPROM and before we talk about the specific control signals and timing requirements required to to write data to the EEPROM there's one important thing we need to mention about how rights to e eproms work which is that after the appropriate control signals have been generated to request that day to be written it takes some time for the e EEPROM device to actually commit that data to the EE prompt internal storage and until that internal write cycle completes we can't actually do any other useful reads or writes and that's you know through attempted here in the datasheet once the end of a write cycle has been detected a new access for a read or write can begin so in other words if we wanted to do a series of writes writing to a number of locations and of course this is typically what we want to do when we program an EEPROM we want to basically write to all the internal storage to the device the this.right cycle timing is going to limit the potentially limit the throughput of the data kind of how fast we can write data to the device and what's important is that it takes a good amount of time for that internal write cycle to complete the datasheet here says 10 milliseconds and 10 milliseconds doesn't sound like a ton but as we'll see if we do if we write one bite at a time that's actually quite slow so to see why this write cycle time is potentially a problem let's think about what would happen if we wrote to every single storage location in a 32 k a prom device one byte at a time so in a 32 k EEPROM there are two to the 15 bite-sized storage locations 32,768 and if we consider that each one of these storage locations would take 10 milliseconds to write - that's more than 320 seven seconds or in other words about five and a half minutes to write to every single location in that EEPROM device so the good news is that there is a way that we could avoid incurring this this delay for every single byte so next let's talk about the specific programming waveforms we need to generate to write data to an EEPROM device all right so let's talk about how to write 1 by 2 beta to an EEPROM and it's sort of what you might expect the idea is that the host CPU or microcontroller asserts the address of the data that it wants to write it asserts the chip enable signal to wake the EE pump up and then the write itself is controlled by the write enable signal when that is asserted by being sent low that essentially tells the EEPROM that the write has been initiated the data you know needs to be asserted on to the data bus you know during during this time when the write enable signal is low when the write enable signal is D asserted being brought high that is essentially the point where the e EEPROM understands that okay the the data has been and whatever data was read from the data bus should be committed to the internal storage there's a couple of timing characteristics that we have to satisfy here there's the Twp characteristic which is the right pulse right pulse width that needs to be at least 100 nanosecond so we have to make sure that we hold the the right enable signal low for at least 100 nanoseconds the other one is this TW pH that is the right pulse width high which needs to be at least 50 nanoseconds and essentially what that means is that after the right enable signal is D asserted we have to wait at least that long meaning at least 50 nanoseconds before we attempt to write more data by sending the right enable signal low again alright so now that we know how to do one byte rights now next let's look at how to do page mode writes and page mode is essentially the bulk data transfer mechanism that allows us to write large quantities of data quickly because we won't have to incur that internal write cycle timer for every single byte of data that we write and the good news is that page mode writes are actually quite similar to single byte right you know we assert an address we assert the chip enable we assert the right enable you know we meet the minimum right pulse width we make sure that the right enable signal is D asserted for at least the right pulse high time that's all the same as before we you know sort of assert and D assert the chip enable as appropriate for each byte of data so what makes a page mode write a page mode right is that we leave on the right and able D asserted for at most this timing characteristic called TBL C byte load cycle time and that is 150 microseconds so is the way to look at it is as long as write number 2a happens no more than 150 microseconds after write number one they are both considered to be part of the same page mode right and we can do up to 64 rights as part of a single block of page mode rights there is restriction they all have to be in the same block of addresses starting on a multiple of 64 you can only write to the bytes within a single page of the eeproms storage that's why it's called the page mode right but as long as all of those rights occur in the same page and that they're all no more than 150 microseconds apart they all get written essentially as a block and you only incur that internal write timer once so that means that you know aside from the amount of time it takes to actually sort of do all of the rights in a page which is relatively quick because we're talking about you know nanoseconds microseconds here we only incurred that longer 10 millisecond delay one time per page all right so now that we've talked about how to interface with an EPROM device let's talk about what we need in our hardware for our programmer and we are going to make the brains of the operation and Arduino Nano so you almost certainly have heard of Arduino as they are just an amazing microcontroller family that are designed to be easy to use and just really really fun and just productive I would say is maybe the way to look at them we are specifically going to use the Arduino Nano these are based on the 18 mega 3:28 or potentially 18 mega 168th chips what's really awesome about Arduino Nano is that they're really really cheap you can get them for like two or three dollars like that these blue ones are you know maybe 250 I got these red ones that are based on the 168 for less than two dollars each it's incredible they appear to the host PC as a USB serial device because they have a USB serial converter chip on them meaning you can have your host pc talk to your firmware program running on the arduino via essentially as a USB serial port and so that's how our host software for the EE prom programmer is going to talk to the microcontroller over USB serial so that's fantastically useful Arduino nanos have 15 digital i/o pins basically pins that can send arbitrary digital output signals or read arbitrary arbitrary digital input they have eight analog inputs if you and these are based on analog to digital converters six of the analog inputs can actually be digital i/o pins so that means you've got a total of essentially twenty-one digital i/o pins available so you can interface to all kinds of stuff it's really awesome and what's really really great about Arduino zhh is that there is an incredible ecosystem of libraries for easily interfacing your Arduino firmware to all kinds of useful peripheral devices like this is the real magic of the Arduino ecosystem all right so to control our EEPROM device we need to be able to generate 15 addressed signals we need to be able to read and write eight digital data lines and then we also need to generate outputs for the three control signals that feed into the EEPROM and so if you're counting that's 26 digital i/o pins that we would need our Arduino Nano only has 21 okay so how are we going to make that work all right so the way we are going to get around the limited number of i/o pins we have available on our Arduino is to use shift registers and essentially what shift registers do is allow you to take a small number of i/o pins on your microcontroller 3 or 4 is typical and use them to control multiple outputs or read from multiple inputs and the specific shift registers that we're going to be using are the 7 4hc 595 that is a output shift register it has a single serial input and so if we send it serial data it will decode that and generate 8 digital outputs we will also be using the 7 for ECT 165 which is an input shift register so it has eight digital inputs that it will then encode onto a single serial output which we can then read and essentially read the encoded form of the data values read on those 8 digital inputs and one additional feature of shift registers that you can advantages that due to the way they work they can be typically can be daisy chained together in order to create larger shift registers so for example we're going to combine two seven four you see five nine five shift registers to generate the address outputs to control to basically tell the EE prom the address of the data values that we want to access okay so in our hardware design we're going to use two five nine five shift registers for generating addresses we're gonna use one five nine five shift register for writing data values to the data bus that they eat you prom will then read you know when we're writing data to the EE prom and then we'll use one 165 shift register for reading data basically when the EPROM device outputs data to the data bus we can use that one six five shift register to read it okay and this is not gonna be a tutorial on how to use shift registers this you know video is gonna be long enough anyway so you know read up on them there they are really really useful in cases where you need to expand the digital i/o capacities of your system or perhaps a microcontroller alright so here is our hardware schematic so here's the Arduino Nano basically we're just connecting the digital i/o pins to the control pins on our ship registered that's you know pretty much how we've interfaced the Arduino to the system a couple of the digital i/o pins are used to control some LEDs that indicate what the data Direction is basically whether if the programmer is reading data or writing data we have two cascaded five nine five shift registers here that generate addresses so you will send 16-bit addresses to these two shift registers and they output the signals that are then fed into the address lines on the EEPROM this particular five nine five shift register is used to generate data so we send it eight bits and it can output those that 8 bit quantity onto the data lines that feed into the EEPROM one very important thing we have to do for this shift registers make sure that we are sending a control signal to the shift registers output enable input because base we need to be able to DISA disable the output of this shift register when we aren't writing data because if the if we are reading data in the EE prom device is trying to output to the data bus we definitely don't want this shift register trying to also output to the data bus let's see so this is our input shift register of the 742 TT 165 - the date bus and when we tell give the instruction to the shift register to read that data it then allows us to sort of read out the data that was observed on the date of bus and send it back to the the microcontroller via a serial input and then this is the actual EEPROM device itself which typically will be 28 C 256 EEPROM but could be prompt but could be a 28 c 64 EEPROM that's an 8k device essentially that has the same pin out as the 28 C 2 5 6 it just ignores the two highest address lines you know meaning as long as you're only writing 8k of data you can basically treat that device exactly the same way as the larger device alright so here is our circuit on the breadboard the Arduino the two shift registers that generate addresses the shift register that writes state values to the e EEPROM and the input shift register that allows us to read data values from the EEPROM and we have a zip socket that allows insertion and removal of the EEPROM device that's certainly something that you'll want to have in your in your programmer not a lot to say about you know this particular version of the circuit other than that it is exactly the same as what's in the schematic and this is how I developed my firmware is by burning the firmware on to the Arduino and then testing things to see if they worked all right so here is the production version of the circuit if you will I built it on a proto board one of these and the kind of pro 2 boards I think make a lot of sense if you're building a permanent version of a circuit are the ones that essentially have sort of a breadboard type arrangement of pads on the bottom you can see there are these groups of or holes that are connected by a common copper pad and so if you basically you know put wires into holes that are part of the same group then you've created an electrical connection between them you know it's essentially the same arrangement as in a solderless breadboard and so if you look at the back of my constructed circuit here you can see that all of these you know wires and components you know that are on the top of the board and you know and have you just rode wires going between them I have you know you know soldered all of those pins and wires in the appropriate locations on the back and it you know essentially it's the same idea as you know constructing the circuit on a breadboard it's just that you are permanently soldering the ends of the wires and the pins you know into the circuit I have used sockets for all of the shift registers I think that's a good idea just because you know if you fry a chip you can just pop it out and put another one in um as I was constructing the circuit I spent a lot of time with the multimeter in continuity mode checking connections and making sure that they exactly match the schematics and you know as you can see there's a lot of wires it took a little bit of doing to kind of figure out a good way to run all of the wires so that there would be enough space to access the components and stuff but it did all work out I do have these if socket soldered in here the pins on the ZIF socket are actually too big to fit through the holes in the proto board so I soldered header pins on to them that were smaller and then those did fit in so it is permanently attached I have also very amateurishly cut some lexan to serve as kind of a kind of a rigid enclosure and you can see the there's two sheets of lexan and then some some standoffs and you know just to kind of protect the electronic components all right so now let's talk about the firmware so on this is the essentially the the firmware program running on the Arduino microcontroller and of course is the brains of the operation it basically has two responsibilities one is to generate the control signals that are sent to the EEPROM device via the shift registers in order to write data and read data and then of course the other responsibility is to interact with the host system either sort of directly interactively or via our specialized host program utility that I'll show you a little bit later so let's start by looking at the setup function and so the setup function in an Arduino program essentially just does the one time Hardware initialization to get the system into an appropriate initial state so it sets the data direction for the various i/o pins that are being used and then performs other important Hardware initialization and then the loop function runs again and again and essentially forms the basis of the program's main control loop what the EEPROM programmer firmware does in its loop function is to print or prompt and then wait for a command and then it carries out the command by a calling the appropriate command function so let me demonstrate on how we interact with the firmware when you are developing Arduino firmware that uses the the serial connection to you know interact with a user or interact with some other piece of software one of the really cool things about the Arduino IDE is it includes this built in serial monitor that allows you to just interactively send data to the Arduino and it will print out the data that is sent back and as long as you use kind of a text-based protocol for interacting with the device this is a great way to sort of interactively you know develop and debug your your firmware program okay so let's see so I'll send a questionmark command that just causes the the firmware to pronounce version information and it also reports what the current address that the firmware is accessing is okay so let's set the address to one zero zero zero in hex that is represents the decimal value 4096 okay and now if I read sixteen bytes so the our command is for reading data and 1 0 is the hexadecimal representation of 16 it's gonna show me the exact 16 bytes of data that are at that address ok so now let's try to write some some data so I'm gonna set our address back to 1 0 0 0 hex and I'm gonna write I'm gonna write the the the data value c6 this is just a one byte write on and so in theory that should change the data at address 1 0 0 0 to c6 so let's see if that actually worked so I'm gonna set the address back and then read 16 bytes and what we notice is that on the the byte of data that that address didn't actually change and the reason it didn't change is that a EEPROM devices actually have a hardware write-protect feature and if that write-protect feature is enabled you can't actually write data to the e EEPROM so I have implemented support for both enabling and also disabling the hardware write protection so the the firmware is D command disables write protection and write protection is turned on and off by sending a you know particular sequence of data rights to a particular sequence of addresses you can read about it in the in the datasheet alright so now that write protection is disabled I'm going to go back to address 1 0 0 0 and let's try to write the the value c6 at that address again and then see if that right actually took effect this time and there it is so we have written one byte of data to our iiep hram right so as we saw on writing one byte of data at a time is slow due to the write cycle timer so what we want to do is use the page mode right up to 64 bytes at a time and the firmware does support page writes via the P command and the the format of the command is that it's P and then it's the count of how much data you're sending I'm gonna send 8 bytes of data and I'm just going to write the bytes 1 1 two 2 three 3 four 4 five 5 six 6 7 7 8 8 as the hexadecimal values other going to be written I'm writing those at address 1 0 0 0 again so now if we read some data from from that address again I'll read 16 bytes right we now see those exact bytes of data at that location in memory and because this page right allows us to write 64 bytes at a time but only incur the the right cycle time or delay one time for all the 64 bytes that gives us a reasonable amount of throughput in and this is very important when we are for example writing you know the entire contents of the e EEPROM alright so in general developing the firmware was reasonably straightforward you know I was able to kind of interactively you know update the firmware and test it and you know verify that things were working and I was able to you know read bytes of data and write single bytes of data all that was fine um the one problem I ran into is when I tried to implement support for disabling the hardware write protection feature I found that even if I wrote the correct special sequence of data values to the special sequence of addresses you know as described in the datasheet I just couldn't get the right protection to actually turn off and what I found eventually is that the timing requirements for that special sequence of data rights needed to conform to the same timing characteristics as for page mode rights and specifically the the problem I was running into was that I was not meaning the byte load cycle time requirement that the rights that were part of the same sequence couldn't be more than 150 microseconds from each other the reason I wasn't able to meet that timing deadline was that the the code that I wrote to communicate with the output shift registers in order to kind of get the data sent to the EEPROM I was using the arduino z-- digital write function you know which essentially just says given a certain pin set it to a certain value you high or low the digital write function for Arduino is very easy to use but it is quite slow and in fact it is so slow that I just wasn't able to you know get get all of the signals sent in 150 microseconds and so the way I fixed the problem was to change my code to directly access the underlying hardware registers that the the AVR 80 mega 328 microcontroller uses to directly control those i/o pins and once I you know made those changes I was able to meet the the timing requirements so that's something to be aware of with Arduino is that some of the convenience features like the digital write function you know may not perform well enough if you are having to meet very precise timing requirements but once once I made that code modification I was able to you know enable and disable write protection with no problem and then that also allowed me to easily implement the page mode write feature and so at that point things were good alright so now let's talk about the host program so this is the program that runs on the host PC that allows you to you know burn data to the EEPROM or read data from an EEPROM and you know disable write protection enable write protection that kind of stuff and there's not a whole lot to say about it you know in the sense that essentially all it's doing is just automating the process of sending commands to the e EEPROM programmer and then reading the responses back such as data read from the e EEPROM and just kind of driving whatever it is that the that the user wants to do and you know there's the main routine you know it just checks command-line arguments and then calls you know various functions to you know write data to the to the program or read data from the programmer I think what would probably be more interesting is to sort of demo it and just kind of give you a sense of how it fits into the work flow so here I am in the code directory for episode 9 and I'm going to I'm going to assemble our blink bin program that controls that little seven segment display and of course the blink dot bin is a 32 K 6809 you know code image that's that we want to program into the EEE prom the the host program is called et Prague so if we write if we issue the community EE Prague - H that prints a little usage message and tells you what the command-line arguments are what we're gonna do is the full command is we are going to use the - F command specify the the firmware file that we want to write the - P option allows us to specify the device name for the serial port so the right now my Arduino is slash dev slash TTY USB zero is pretty typical the - capital D disables right protection - capital n will re-enable write protection after the data write has been completed and then the - V causes the utility to verify that all the data was written correctly but basically by reading the data after all the data has been written okay so let's see if that works ok so the host utility is now talking to the firmware and it's writing the data each of these dots that are being printed as a progress indication indicate 1k of data so it's going along at kind of a reasonable clip here certainly it's not gonna be anything like the 5 minutes that would be required if we were doing you know one byte at a time so the write has now in theory completed so now it's reading the data back in order to verify that all the data was written correctly and essentially the host program just checks the data buffer where the data was read and verifies that it is byte for byte identical to the data written and if so then we should be in good shape because our data is now in the EEPROM alright so to conclude let's think a little bit about whether or not this project was worthwhile so I will definitely acknowledge there were significant time and effort involved took some time to design the hardware to construct the hardware soldering all those wires definitely took some effort the development of the firmware and the host program took some time so you know that's definitely something to consider as far as the cash expenses they weren't too bad I had most of the parts I needed on hand I did spend maybe twenty dollars or so to get those lexan sheets to build the enclosure and also the standoffs that I used in the enclosure although some of those were leftover and I'll use those in future projects the real reason to do these this kind of project is as a learning experience so one of the things I thought was interesting was the way I figured out that problem with the timing of page writes was I actually got out the oscilloscope and monitored the the right enable signal on the EEPROM and it was extremely obvious from looking at the traces on the scope that those right pulses were more than 150 microseconds apart and that you know definitely told me what the problem was and gave me a head start on figuring out how to solve it and just in general I think it's good to follow through on these projects and really see them to completion and just the experience of you know diagnosing problems and figuring out a solution you know kind of helps you be more productive in you know getting other projects done okay and as always you know you can look in the video description and there will be links to these schematics in the code definitely feel free to use them however you see fit and in the next video we'll return to the 6809 system and definitely add some RAM maybe add some peripheral devices so I will see you in the next video
Info
Channel: daveho hacks
Views: 2,426
Rating: 4.9245281 out of 5
Keywords: eeprom, eeprom programmer, arduino, 28c256
Id: 3JDdSSu8tQ0
Channel Id: undefined
Length: 34min 55sec (2095 seconds)
Published: Mon Aug 12 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.