Shop OBEX P1 Docs P2 Docs Learn Events
RL4000: 4-Bit CPU trainer — Parallax Forums

RL4000: 4-Bit CPU trainer

Here's a Prop project that I've been working on...
I finally got to the point where all the LEDs are working.
Still have buttons and LCD to wire up...

For some reason (still to be determined), I decide to create a 4-bit CPU trainer.
The idea is that this could be used to teach people how CPU's work...
This is about the simplest CPU possible that can do anything fun.

This is actually going to be an RL4000 emulator, but it can also be constructed in real form from DIP chips.
The CPU design is shamelessly copied from the Nibbler:
http://www.bigmessowires.com/nibbler/

I asked Steve and he emailed the Nibbler design has a CC-BY-SA license.
He also asked that I not use the name "Nibbler". So, I'm calling this RL4000.

Here are some great things about Nibbler (AKA RL4000):
1. Super simple
2. Can be realized with DIP chips
3. Comes with an Assembler written in MFC (I love MFC)
4. Comes wiht a Simulator (also in MFC)
5. Comes with fairly complex games and other code

Hopefully this RL4000 Emulator will add
1. Lots of LEDS (everybody likes LEDs) for visual indication of inner workings
2. A way to easily change out programs
3. A way to escape Emulator and enter an interactive mode

2016 x 1512 - 861K
2016 x 1512 - 934K
2016 x 1512 - 1M
«13

Comments

  • RaymanRayman Posts: 14,589
    edited 2018-02-22 14:47
    I forgot a couple other great things:

    1. Original design was done in Eagle (the PCB code I use). This was done just for the schematic. But, I've already figured out how to turn that into a PCB. (Note that the RAM chip had to be changed to an 8-bit version because 4-bit version no longer is sold). BTW: I think I can use a Propeller to make a low cost EEPROM programmer. We'll see how that goes... (Might use Flip module so everything stays DIP)

    2. Someone posted a Verilog version of Nibbler. It is very simple. So, this could also be transitioned into an intro to Verilog and FPGA...
  • Cluso99Cluso99 Posts: 18,069
    Looking good :)
  • Countdown to NibbleCog being developed in 3..2..1..
  • Nice form-factor: compact but not too small. Clear easy-to-read labels. Pretty LED indicators and colors. Looks like it will be straightforward for learners/users to comprehend with all the data and state info available at a glance.
  • Nicely laid out. If you have a color laser you can print onto heavy duty polyester laser label paper which is waterproof but really looks fancy. I use full A4 sheets and LibreOffice Draw for accurate artwork and test print it on plain paper or cheaper plain label paper. Then when I'm happy with it I might step and repeat the artwork to fit more onto one page.

    These labels look really really good, you would think they were professionally done. One tip though, you had to cut holes for your LEDs but I like to hide the LEDs behind the label and just make sure that it is blank there as the LED color shines through the thin white easily. Some black toners aren't so nice as they have a matte finish but HP and some others have a nice even glossy black. I use Avery L7067 labels. Once it goes into production I normally have polycarbonate labels made from the artwork or have it printed directly onto the metal (very nice).

    Here's a picture of a simple label (all mine normally have customer logos on them) and there is the odg format file as a sample.
    355 x 500 - 204K
    970 x 487 - 20K
  • RaymanRayman Posts: 14,589
    That's an interesting idea, Peter. I do have an issue with cutting holes out for the LEDs.
    I probably could have done a better job there with my hole punch, but was in a hurry...
    Keeping them below the surface would be easier.

    BTW. I was really off in power requirements... I thought I'd need 20 mA for each of the LEDs.
    But, these new Cree LEDs are so bright, each one was blinding at 20 mA. Had to swap out ~200 Ohm resistors with 5k resistors to make it so didn't hurt to look at it! I think it can be USB powered now...
  • RaymanRayman Posts: 14,589
    edited 2018-02-19 14:48
    BTW: I 3d printed the top panel and then applied a printed sticker with waterproof film on top. This saved me from drilling out all the LED holes...

    The Bud plastic enclosure did turn out to be about perfect for this.
    The PCB was designed to fit it and it seems to be right.
    It has a nice cutout with small panel that can be customized in the back where USB, SD, audio connect.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2018-02-19 15:04
    The classic LED from the 70's could handle 20ma maximum but because they were so inefficient they needed every milliamp they could get just to see them in dim light. Most LEDs are more than bright enough at 3 to 5 ma, anything more is called LED Lighting! To this day though the Internet promotes the idea that 20ma is "needed".

    If you mount your LCD so that the glass is level with the front of the case then you can easily slide in some 0.24mm thick clear presentation cover plastic as a window that protects the LCD glass nicely too.
  • Cluso99Cluso99 Posts: 18,069
    I never use anything less than 3K3, but usually 5K (or 4K9) and sometimes 10K, on my LEDs.
  • RaymanRayman Posts: 14,589
    I may have just gotten a spin version of the emulator to work (attached).
    I cheated with the ALU and ported the C++ simulator code for the 74181 to Spin.
    That got me wondering if this is a simulator or emulator...

    I think it is now a simulator, but once I had the real I/O it will be an emulator...

    Anyway, this code runs through the Ram Test code provided with Nibbler.
    I think it's doing the right things...
    I suppose I could have copied more from the simulator, but this is fun :)
  • I like using 4-8 bit trainers. I put together an 8085 with an eprom and ram. So far it reads a keypad and has several seven segment displays. I toggle bytes in manually with dip switches address, data , write etc. . Now that my program is loaded I can load it in Hex with the keypad. Fun, Fun, Fun
  • RaymanRayman Posts: 14,589
    I noticed that home brew CPU making is still around... You can still buy the 74181, ram and rom chips in DIP format you need. Looks to me like this home brew crowd is the main consumer...
  • Heater.Heater. Posts: 21,230
    Oh yes, there is a lot of homebrew CPU building going on.
    Like this, just started RISC V implementation by Robert Baruch

  • RaymanRayman Posts: 14,589
    It's actually kind of fun to think about building your own homebrew CPU...
    I'm tempted to see about building the RL4000 (Nibbler) using DIP chips and the Eagle schematic I have.

    But, maybe it's good enough that it can and has been built before.
    I'm thinking it's better to focus on FPGA implementation...
  • Heater.Heater. Posts: 21,230
    Rayman,
    ...maybe it's good enough that it can and has been built before.
    That is why I never played football, or any other sports, it was always good enough for me that the other kids were doing that so I did not have to :)
    It's actually kind of fun to think about building your own homebrew CPU...
    Ah, that is better. Do it just for the fun. For you.

    Personally I think the fun is is in the challenge. Can I design my own CPU? Without slavishly copying some other design? Do I understand the problem well enough to do that? Never mind if it's not very fast or capable.

    I'm all for the FPGA idea. Traditionally the problem there was that FPGA's and dev boards are not cheap and that the development tools are a real pain. That situation has been remedied somewhat recently with the arrival of Yosys. Quick and easy HDL for the cheap Lattice FPGA's.

    Next problem is that programming a CPUs in binary via switches or hex keypads and displays soon gets kind of tedious. One then needs to write an assembler or a compiler for ones weirdo instruction set.

    The guy building the RISC V processor out of logic chips has an advantage there. All the assemblers and compilers you need for the RISC V instruction set exist already.




  • RaymanRayman Posts: 14,589
    edited 2018-02-21 19:41
    Funny you mention the toolchain... I was looking around for minimal CPU implementations that can work with the GNU C compiler and ZPU (and your name) came up :)

    My little $25 FPGA eval board from Lattice isn't big enough to do P1V, but can certainly do RL4000 (AKA Nibbler). Maybe it could do a ZPU?
  • Heater.Heater. Posts: 21,230
    Wow! That is a blast from the past.

    See, I cheated. Rather than build a CPU of my own I wrote a ZPU emulator for the Propeller. I did not know anything much of FPGA and Verilog/VHDL at the time, and FPGA was rare and expensive, else I might have gone that way instead.

    Good old Zog. The first ever way to get C/C++ running on a Propeller !

    Well, apart from my ZiCog Z80 emulator.

    Speaking of minimal CPU implementations, I sometimes ponder the idea of building a SUBLEQ processor. The SUBLEQ architecture only has one instruction, "SUBtract and Branch if Less or EQual". Which means you don't need an opcode or an instruction decoder.

    The SUBLEQ has the advantage that there is already a C compiler for it. Well, almost C like language.

    https://esolangs.org/wiki/Subleq


    Where did you find "heater", "GNU C" and "ZPU" if not on this forum?











  • RaymanRayman Posts: 14,589
    edited 2018-02-21 20:26
    well, I googled a lot and came across this:
    https://opencores.org/project,zpu

    Then, I did Wikipedia for ZPU (the CPU one) and came across a Parallax Forum thread in the references...
  • RaymanRayman Posts: 14,589
    Steve did a really nice job with Nibbler. The only thing I don't like (and maybe it's picky) is the name for this instruction:
    LIT loads a literal immediate nibble value to the accumulator. It might also have been named LDI.
    

    LDI is perhaps better, but then you have LD (load A from RAM) and LDI.
    Have to think more about it, buy my first inclination is to rename LIT to LDI and LD to LDM...
  • Heater.Heater. Posts: 21,230
    edited 2018-03-15 17:55
    OMG. I'm in wikipedia!

    https://en.wikipedia.org/wiki/ZPU_(microprocessor)

    Not only that but in the same list of references that includes the Gods of the RISC architecture: David A. Patterson and John L. Hennessy
    https://www.amazon.com/Computer-Organization-Design-RISC-V-Architecture/dp/0128122757/ref=sr_1_1?s=books&ie=UTF8&qid=1519245849&sr=1-1&keywords=Computer+Organization+and+Design+riscv

    And the brains behind the RISC V architecture: Asanovic, Krste.
    https://riscv.org/

    How is that even possible?


  • RaymanRayman Posts: 14,589
    edited 2018-02-21 21:29
    I was assuming you wrote it :)
    Sorry, wasn't meant to be a slight...
    After seeing the Parallax reference, I did think you must have wrote it...
  • Heater.Heater. Posts: 21,230
    Ha! I'm not so smart as to be that devious.

    I noticed that wikipedia page a year or so ago. What I did not notice was the hallowed names included in the list.

    Anyway, it's good to know that the Parallax forums are an authoritative reference :)
  • I thought about building the Intel 4004 using transistors. But I don't have the spare time right now. (4004 was the adding machine cpu back in the day)
  • RaymanRayman Posts: 14,589
    I did read about the 4004 while researching this project. It is actually way more complex than Nibbler (I mean RL4000) but probably executes slower due to lower clock speed and 4 times the clocks per instruction...
  • Anyway nice project. I always like to follow the x86 instruction set if I'm writing the microcode for a homebuilt CPU using logic gates and eprom. Starting with the basic mov, jmp, nop, lda , etc
  • Heater.Heater. Posts: 21,230
    DigitalBob,
    I always like to follow the x86 instruction set if I'm writing the microcode for a homebuilt CPU
    Why for goodness sake?

    The x86 instruction set is one of the most complex to implement. Even Intel implements it incorrectly. Even the humble MOV instruction is a nightmare of complexity. Did you know you know there is a C compiler that generates nothing but x86 MOV instructions? MOV is Turing complete.

    Or do you mean the Intel 8080 instruction set?

    Hmm....makes me think....How about building a single instruction computer that only implements the x86 MOV instruction, then we could use the
    movfuscator to generate programs for it :)

    https://github.com/xoreaxeaxeax/movfuscator



  • RaymanRayman Posts: 14,589
    I like instruction names like mov, jmp, nop and lda too. Possibly my only departure from Nibbler will be to rename the instructions. Well, if I can come up ones I like better, that is. Not sure that is possible yet...

    Was initially wishing there was room for a NOP here. Maybe the first four bits all zero would mean NOP and the lower nibble could say whether to make this for 1 byte instruction or 2 byte instruction.
    The main issue there is it would probably break all the big example programs that come with Nibbler as I imagine they use all 16 instructions somewhere (but maybe I should check that).
  • Heater.Heater. Posts: 21,230
    Ah, so not actually the instruction set, as in the same instructions and behaviours, but just using the mnemonics.

    I guess mnemonics like MOV, JMP, NOP and many others are commonly used all over the place, even if the instructions sets are not the same.

  • When building these simple 4 or 8 bit logic gate cpu's I like to write the microcode patterned after the Intel I guess more like the 8080 (Thank you Heater) These are simple cpu's so I don't write a whole lot of instructions. It's great to watch each instruction execute when using the step clock.
  • Heater.Heater. Posts: 21,230
    edited 2018-02-25 08:43
    DigitalBob,
    When building these simple 4 or 8 bit logic gate cpu's I like to...
    You make it sound like you are creating new 4/8 bit CPUs all the time. How many are you up to now?

    I have yet to manage even one. Even after pondering the idea for decades :(

    That pondering started in the late 1970s/early 80's when I got hold of the data books for the AMD 2900 bit slice chips: http://www.cpu-world.com/CPUs/2901/index.html


Sign In or Register to comment.