Emulate an EPROM - How Hard Could it Be?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

The upcoming project is a Mini Apple IIe. I took the MEGA-II out of an Apple IIgs and now I am building an Miniature Apple IIe based on it. (Something that Apple never did!)

If you're interested in the project, there are over 80 hours of living streaming archived on Twitch. Once I got it to the point that my minimal computer boots to an Applesoft prompt, it was time to move on to a more sophisticated prototype.

๐Ÿ‘๏ธŽ︎ 4 ๐Ÿ‘ค๏ธŽ︎ u/baldengineer ๐Ÿ“…๏ธŽ︎ Sep 24 2021 ๐Ÿ—ซ︎ replies

Terrific, thanks for this! Super relevant to a project of mine. Was starting with a Teensy, you clearly have me reconsidering that. I especially like how you left in what you learned and measured from the โ€œfailureโ€ steps.

๐Ÿ‘๏ธŽ︎ 2 ๐Ÿ‘ค๏ธŽ︎ u/FredSchwartz ๐Ÿ“…๏ธŽ︎ Sep 24 2021 ๐Ÿ—ซ︎ replies
Captions
so i've been wondering how hard could it be to emulate an eeprom using a microcontroller let's find out [Music] for a project i am essentially making a miniature version of this apple 2e computer so if i want to use a usb keyboard i need a modern microcontroller to emulate this one in the 2e the keyboard is made of switches in a matrix there is a microcontroller with custom firmware scanning it when it detects a key press it addresses a masked rom chip which maps the key to a ascii value that chip is connected to the main memory bus of the apple 2e if i can emulate that rom chip then i can use whatever i want as a keyboard for my computer also in the 2e are memory and i o controllers which talk to the keyboard micro to know when keys are pressed so using a logic analyzer i could see that every 21 microseconds the mmu activates a signal connected to the output enable of the keyboard rom chip my final project will not make use of a keyboard matrix so i can't just emulate that i want to get it and its chips out of here so i need something that can talk to the main data bus but also be high impedance when not in use to help make measurements i made a small interposer board that lets me connect either the rom or an arduino along with a logic analyzer such as this digilent digital discovery for my first test i tried to use an arduino mega to emulate the rom's output enable i set up an input pin with an interrupt on change this way when the signal goes low the data pins can be changed from high impedance to outputting in ascii a and then when the signal goes high again the pins can go back to high impedance frankly i was excited about this option because it seemed like a perfect fit here's what happened yeah that's the apple 2e crashing into its monitor so let's see what the logic analyzer shows and it shows when the keyboard signal asserts the bus value is hex 20 when the arduino should be putting out hex 65. i played around with the code for a little bit but then i got to thinking how long does it take for an arduino to respond to an interrupt so i modified the code to toggle a pin inside the interrupt routine or instead of one pin an entire port of pins same thing on my first trace i did not even see the pin from the isr going high by the way on the logic analyzer i am using the label any key for my debug signal at this point i was pretty frustrated i double checked the code i double checked the wiring i double checked the lock and then it hit me when i zoomed the logic analyzer trace out then i could see my debug signal toggling but it was way after the enable signal using the cursors i found it took 3.5 microseconds so yeah there's your problem the actual keyboard enable signal is only active for about 500 nanoseconds so the arduino is taking way too long to respond and ends up trashing the data bus now i looked at the data sheet and the avr can't get into an isr any faster than about 1.5 microseconds which is way too long so we need another option the teensy 4.0 has a 600 megahertz microcontroller on it my hope was that it could get into an isr faster than a 16 megahertz processor before connecting to the apple 2e i wanted to check to see what would happen with just the processor so i wired it directly to the logic analyzer the output pin gets two wires from the digital discovery because it can also be a pattern generator the generator simulates the output enable signal and then the logic analyzer can measure how long it takes to enter the isr the code is very simple a rising edge on the input pin enters the isr which then turns the pin on elsewhere in the code i turn it off looking at the logic analyzer we can see that when the input goes high so does the output and that the teensy is way faster it gets into that isr in less than 200 nanoseconds here about 180 but that's the amount of time it takes just to get into the isr once inside we still have to do some other stuff so i thought maybe we would have to go to an fpga but then i remembered that the processor on the pi pico the rp2040 has a very special feature the rp2040 on the pi pico has something called programmable i o pins or pio modules these modules contain state machines that run the i o pins completely independent of the processor or the software that it's running first i downloaded and installed circuit python which is as easy as dragging and dropping once it reboots open up the code.py file and write python and i can already see the comment saying but wait a minute isn't python going to be slower remember that doesn't matter because the pio runs completely independent from the software and a reason i like circuit python is because you write the pio code as a string so it is very fast to write and test the assembly like instructions now in this video i will not get into the assembly instructions for the pio if that's something you're interested in learning about let us know over on the element14 community over there you'll find all the code that i'm using here my digital discovery was still connected to something else so in this case i connected an analog discovery to the pi pico to test its code in the test code we wait for an input pin to go low then output a low we wait for the input pin to go high and output a high the pio has its own clock here i'm clocking it at 125 megahertz back to the logic analyzer i set it up to trigger on the input signal and we can see that the output signal is reacting very quickly the markers say less than 50 nanoseconds so this was really great news the original rom chip takes about 100 nanoseconds to respond to the output enable signal the pi pico does it in like 40 to 60 nanoseconds at 8 nanoseconds per instruction we have plenty of overhead to do the things we need to do to emulate a rom so i knew we were on the right track [Music] and now it is time for my next trick the pi pico has to act like a keyboard rom inside of an actual apple 2e so i spent a lot of time coming up with the pio code which would emulate the behavior we saw in the actual apple 2e for the final test i connected the pi pico to my interposer which was plugged in where the rom used to be the circuit python code receives a character from the serial input and then puts that into the pio to be output whenever output enable is asserted at this point i have not recreated the control signals from the keyboard controller to tell the i o controller when a key has been pressed so i'll press a key on the actual keyboard to generate those signals but the pi pico will output whatever value we tell it to so no matter what key i press on the keyboard we're going to output a different ascii value before i show the result here's how the setup worked the window in front is a serial connection to the pio in the back is a composite capture of the apple 2e i shot this during a live stream here's how it went [Laughter] such a simple thing such a simple thing b [Laughter] pressing any key on the keyboard will generate the code of the last character sent over serial which is exactly what i wanted you can tell because i'm happy which brings me to a little bit of a concession the code i have here doesn't perfectly emulate an eeprom on the address side circuit python is decoding the address which is relatively slow but that's okay because a slow human this guy is typing on the keyboard now in a real eeprom we would need to decode the address faster which i think we could do with another pio module and then use a dma to get data between them but i did not need to go that far for this project so how hard could it be to emulate an eeprom using a microcontroller well with a pi picos pio module it's pretty easy so at this point i have enough information to know that in my final project i can probably use the pipe eco to emulate a keyboard if you'd like updates on that project follow me over on the element14 community and while you're there why don't you let us know about other things where you've often wondered how hard could it be [Music] you
Info
Channel: element14 presents
Views: 18,718
Rating: 5 out of 5
Keywords: electronics, hardware, hacking, mods, weekly, element14, maker, engineering, element14presents, Pi Pico, Arduino, EPROM, Masked ROM, Emulating ROM, Apple IIe
Id: XyMrzPP4KBk
Channel Id: undefined
Length: 8min 40sec (520 seconds)
Published: Wed Sep 22 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.