Skip to main content

Emulate Integrated Circuits

Project description

# ICemu - Emulate Integrated Circuits

`icemu` is a Python library that emulates integrated circuits at the logic level. For example,
if you want to simulate a circuit with a decoder driving the clock pin of two shift registers,
it would look like this:

dec = SN74HC138()
sr1 = CD74AC164()
sr2 = CD74AC164()
mcu_pin = OutputPin('PB4')

sr1.pin_CP.wire_to(dec.pin_Y0)
sr2.pin_CP.wire_to(dec.pin_Y1)
sr1.pin_DS1.wire_to(mcu_pin)
sr2.pin_DS1.wire_to(mcu_pin)

print(dec.asciiart())
_______
A>|- U +|>Y7
B>|- +|>Y6
C>|- +|>Y5
G2A>|- +|>Y4
G2B>|- +|>Y3
G1>|+ +|>Y2
Y0<|-___+|>Y1

You could then play with pins at your heart contents and have them "propagate" through wires and IC
logic automatically.

## See it in action

Here's a little video of `icemu` used in my [seg7-multiplex][seg7-multiplex] project:

[![asciinema](https://asciinema.org/a/WsYhXc1VcgfmkKZ8SAT18xYjv.png)](https://asciinema.org/a/WsYhXc1VcgfmkKZ8SAT18xYjv)

That timer has 3 7-segments led matrices driven my 3 shift registers themselves driven by a 3-8
decoder. These are all emulated in a virtual circuit and the output is the output of the led
matrices themselves.

## What is it for

The goal of this library is to facilitate the testing and debugging of embedded software. When we
run software on an embedded prototype, it's often hard to debug failures because we don't even
know if the problem comes from hardware (wiring, it's always the wiring!) or software. Moreover,
testing directly on a prototype often involves significant setup time.

With emulation, we have a quick setup time, introspection capabilities, all this stuff. We can then
confirm the soundness of our logic before sending it to our prototype.

## Why Python

Because it's used for debugging purposes, speed is not essential. Also, Python is easy to glue
with C.

I've tried writing quick `icemu` prototype in C and Rust, but they were needlessly complicated.
With Python, it's easy to write the software and add new chips. Because there's gonna be a *lot*
of these chips to add, we might as well make this process as fast as possible.

## How to use

You can install `icemu` with pip on python **3.4+**:

$ pip install --user icemu

Then, you need to recreate your prototype's logic in a small Python program that uses `icemu` and
wrap that into easy to use functions. Those functions should be designed to receive pin state
change from the MCU and apply the logic change into your circuit. Make that program print relevant
information so that you can assert your logic's soundness.

Then, write yourself a small Hardware Abstraction Layer at the pin/register level, embed your
Python program like a regular C application would do, make your `ifdef`ed functions call helper
functions you've written in your Python program, compile and run!

## Examples

You can find small examples is the `tests` folders, but the best way to get the grand idea is to
look at a project that uses it such as my [seg7-multiplex][seg7-multiplex] or my
[solar-timer][solar-timer]. Read the Simulation part of the README to get started.

## License

LGPLv3, Copyright 2017 Virgil Dupras

[solar-timer]: https://github.com/hsoft/solar-timer
[seg7-multiplex]: https://github.com/hsoft/seg7-multiplex

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

icemu-0.2.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

icemu-0.2.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file icemu-0.2.0.tar.gz.

File metadata

  • Download URL: icemu-0.2.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for icemu-0.2.0.tar.gz
Algorithm Hash digest
SHA256 44af26703198ab7b425e0f2b2d7cf42c068a033109a830d24fe7e06ad679fd0a
MD5 e34c2eb8c715689bde54dd5acfb3c739
BLAKE2b-256 84dbe0329529711cc41f99c3b618cf296d9c69b70a27609d4d186caeaba82fbc

See more details on using hashes here.

File details

Details for the file icemu-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for icemu-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7138753648b04b8e3f302a45f4f091521c88ad5d45c41b78b323b1c4b3dc4990
MD5 ab9a36e29b06a7c46954759028aba2c0
BLAKE2b-256 6ed1bd7b6ca262e49a370b4c7fc840f5667c57aa3c1f7b87552da5aba47a870b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page