Introduction to DigitalJS
DigitalJS is a powerful digital circuit simulator rooted in JavaScript, created to mimic the logic circuits designed by hardware tools such as Yosys. Yosys, a reputable tool in the hardware design community, has its output files seamlessly converted to DigitalJS format using the companion project, yosys2digitaljs. This makes DigitalJS not only a tool for engineers and hardware enthusiasts but also an invaluable educational resource due to its focus on readability and easy examination of logic circuits.
For those eager to explore its capabilities hands-on, DigitalJS is available online as part of a separate project. This accessibility ensures that users—from hobbyists to students—can engage with digital circuit simulations directly through their browsers.
Getting Started with DigitalJS
To integrate DigitalJS into your projects, you have several options:
-
Install DigitalJS directly from NPM with a simple command:
npm install digitaljs
-
Alternatively, use the Webpack bundle accessible online.
With DigitalJS, simulating a circuit is straightforward. You will need to provide a circuit represented in a JSON format and render it on a webpage. Here’s a quick glance at how it works in JavaScript coding:
// Initialize the circuit simulation
const circuit = new digitaljs.Circuit(input_goes_here);
// Visualize the circuit on a web page element with ID 'paper'
const paper = circuit.displayOn($('#paper'));
// Enable real-time simulation of the circuit
circuit.start();
Understanding the Input Format
DigitalJS relies on a JSON input format to represent circuits, using three main keys: devices
, connectors
, and subcircuits
.
-
Devices: This section lists all components of a circuit. Each device has unique identifiers and properties, including a mandatory
type
. For example, an AND gate is represented as:"dev1": { "type": "And", "label": "AND1" }
-
Connectors: These define connections between devices, ensuring that connections adhere to input-output rules and matching bitwidths. A connection example is:
{ "from": { "id": "dev1", "port": "out" }, "to": { "id": "dev2", "port": "in" } }
-
Subcircuits: This section allows for creating modular circuit designs by defining reusable circuit blocks.
Diverse Device Types
DigitalJS supports a broad range of device types, each designed for specific functions in logic circuits. Key categories include:
-
Logical Gates: Devices such as And, Or, Not, and their variations for reducing logic input (e.g., AndReduce).
-
Arithmetic and Bitwise Operations: Includes devices for operations like Addition, Subtraction, as well as bit shifting.
-
Comparators: Devices to compare values, providing binary outputs based on relationships like equal, greater than, or less.
-
Memory and State Machines: Devices like Memory components, D flip-flops, and finite state machines for storing and managing state.
-
User Inputs and Outputs: Elements like Buttons, Lamps, and 7-segment displays facilitating interaction and display of results.
Future Enhancements
The team behind DigitalJS is enthusiastic about potential future upgrades, including:
- More intuitive editing tools for configuring gates.
- Various file format support for imports and exports such as Verilog and Intel HEX.
- Enhanced user interface features for mobile devices, undo-redo functionality, and export capabilities.
DigitalJS stands as a testament to the evolving landscape of digital simulation tools, providing a comprehensive solution for both professional and educational environments.