Skip to content

An analog, transistor-level simulation of an 8-bit CPU in SPICE

License

Notifications You must be signed in to change notification settings

F35idk/spice-cpu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spice-cpu

An analog, transistor-level simulation of an 8-bit CPU in SPICE.

To load a custom program, edit scripts/rom.h. The default program should compute the GCD of 12 and 36 (12), and store the result in the X and Y registers. To run the simulation, simply:

./run.sh --cycles [number of cycles to run]

Optionally, simulation data may be stored in a ".raw"-file. This allows viewing the signal waveforms generated by the simulation in programs like gwave. Just specify a path:

./run.sh --cycles [number of cycles to run] --output [/path/to/raw-file]

or more briefly:

./run.sh -n [number of cycles to run] -o [/path/to/raw-file]

To test the program on the emulator:

./run.sh -n [number of cycles to run] --emulate

alternatively:

./run.sh -n [number of cycles to run] -e

The emulator should give the exact same results as the simulator, but run approximately 1000000 times faster. For testing the simulator against the emulator, see scripts/test_cpu.c. For testing the combinational and sequential logic circuits in circuits/ngspice, see scripts/test_circuits.c These can be compiled with:

gcc scripts/test_circuits.c scripts/emulate.c scripts/simulate.c scripts/write_rom.c scripts/util.c -lngspice -o test_circuits

and:

gcc scripts/test_cpu.c scripts/emulate.c scripts/simulate.c scripts/write_rom.c scripts/util.c -lngspice -o test_cpu

Specifications

  • Harvard architecture
  • 250 kHz (in-simulation) clock speed
  • 16 bytes of RAM and ROM
  • 4-bit address bus
  • 8-bit data bus
  • 2 general purpose registers (X and Y)
  • 14 unique opcodes (see scripts/instruction.h)
  • NMOS logic gate design

NMOS logic was chosen because it is significantly less taxing on the simulator than CMOS logic (SPICE seems to struggle with simulating really low-current circuits). As for the clock speed, the CPU could probably go above 250 kHz, but I've yet to test it.

Details

The scripts in scripts/ use the libngspice API to run and interact with the simulation. The ngspice-compatible netlists for each subcircuit in the CPU can be found in circuits/ngspice/. LTspice schematics are available in circuits/ltspice/.

Simulation Dependencies

  • libngspice v34

About

An analog, transistor-level simulation of an 8-bit CPU in SPICE

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published