Commit 968f07c4 authored by Jules Gonzalez's avatar Jules Gonzalez
Browse files

Update tuto_nmigen.md, added part Transition to Nmigen

parent ba51e844
......@@ -39,3 +39,41 @@ Note that you need to replace these terms :
*- ICEBreakerPlatform -> ICEStickPlatform*
*- led = platform.request("led_r") -> led = platform.request("led")*
## Transition to Nmigen
### From variables to signals
Nmigen uses **Constants** and **Signals**.
**Constants** have a fixed value that cannot change.
Regarding the **Signals**, they can replace Python's **Variables**.
When using **Constants** and **Signals**, the number of bits used can be specified, aswell as whether it is signed or not. By default, it uses the least possible amount of bits to represent the value.
#### Constructors :
`a = Const(10, unsigned(16))`
`b = Signal(signed(4))`
#### Warning :
**Constants** and **Signals** are encoded on a limited number of bits, leading to issues when representing floats.
To face this issues, we chose to left shift all our values by 16 bits, effectively multplying them by 2<sup>16</sup>.
A float *x* is represented by the closest integer to _x*2<sup>16</sup>_, allowing us to keep track of the decimals.
This changes the way we do calculations :
>0.8 + 0.5 = 1.3 => 52 429 + 32 768 = 85 197
>
>0,8 * 0,5 = 0,4 => 52 429 * 32 768 = 1 717 993 472
The sum of 2 numbers left shifted by 16 bits gives us the correct result left shifted by 16 bits.
The product of 2 numbers left shifted by 16 bits gives us the correct result left shifted by 32 bits.
Since we dicided to store our values left shifted by 16 bits, we will need to right shift the result of our products before storig it.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment