Comparing version 0.0.23 to 0.0.24
{ | ||
"name": "hdl-js", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Hardware definition language (HDL) and Hardware simulator", |
@@ -789,8 +789,12 @@ # hdl-js | ||
A clock operates on the [clock rate](https://en.wikipedia.org/wiki/Clock_rate), that is, _number of cycles per second_, measured in **Hz**. The hight the clock rate, the faster machine is. | ||
A clock operates on the [clock rate](https://en.wikipedia.org/wiki/Clock_rate), that is, _number of cycles per second_, measured in **Hz**. The higher the clock rate, the faster machine is. | ||
And a **clock cycle** consists of two parts: _rising edge_, and _falling edge_. | ||
Clock's runtime consists of _cycles_, and _clock cycle_ has two phases: _rising edge_ (aka "tick"), and _falling edge_ (aka "tock"). | ||
As mentioned in the [memory chips](#memory-chips) section, all clocked gates can change their internal state _only on the rising edge_. And on the falling edge the _commit_ the value form the state to the output pins. | ||
<p align="center"> | ||
<img src="http://dmitrysoshnikov.com/wp-content/uploads/2018/01/hdl-js-system-clock-1024x302.png" alt="Clock image" width="700" /> | ||
<p/> | ||
As mentioned in the [memory chips](#memory-chips) section, all clocked gates can change their internal state _only on the rising edge_. And on the falling edge they _commit_ the value form the state to the output pins. | ||
For example, running the: | ||
@@ -926,3 +930,2 @@ | ||
/* | ||
@@ -938,4 +941,44 @@ | ||
It is also possible to `start`, `stop`, and `reset` the clock: | ||
```js | ||
const hdl = require('hdl-js'); | ||
const { | ||
emulator: { | ||
Clock: { | ||
SystemClock, | ||
}, | ||
}, | ||
} = hdl; | ||
// Reset the clock: | ||
SystemClock.reset(); | ||
// Subscribe to the events: | ||
SystemClock.on('tick', value => console.log('tick:', value)); | ||
SystemClock.on('tock', value => console.log('tock:', value)); | ||
// Run it: | ||
SystemClock.start(); | ||
/* | ||
Output (every second): | ||
tick: +0 | ||
tock: -1 | ||
tick: +1 | ||
tock: -2 | ||
tick: +2 | ||
tock: -3 | ||
... | ||
*/ | ||
``` | ||
### Composite gates | ||
TODO; WIP |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
217307
981