Commit 5c151822 authored by ethan's avatar ethan
Browse files
parents f715fd7c 0c5c3c15
......@@ -108,3 +108,29 @@ Tuesday :
* Next thing to do : finish the nmigen multi-layer perceptron and test it.
---
### Week 8 (22/03/2021) :
---
* We managed to sucessfully install the tools to run nmigen programs on the FPGA. We then tested it with different examples and we tested our own little piece of code. This helped us understand how to control each led.
* We also worked on the translation of our multi-layer perceptron in nmigen. We are creating the file containing the information of the trained matrix that will be used by the fpga. This is still a work in progress because the file is not working yet.
* At the same time we worked on learning more about pyserial and UART to understand how data will be exchange between the computer and the FPGA.
* Finally we worked on the nmigen tutorial and the translation in english of this tutorial.
---
### Week 9 (29/03/2021) :
---
* Today we managed to correct the nmigen simulation and to launch it. Unfortunately we still have issues to show the matrix of Signals, on Gtkwave we can only see one of the Signal and not all of them, so we couldn't check with the simulation.
* We then used the program on the FPGA with different inputs for our example of the "Xor" (we made a different led shine depending of the result 1 or 0). The program worked on the FPGA but the output wasn't the expected output and the comparison between signals didn't work as expected. The main issue remaining for this part is to fix the result but we didn't identify yet what to fix.
* Another work consisted in understand UART links and the use of pyserial. We didn't manage yet to understand how it could be used in Nmigen.
* Finally we finished the english version of our Nmigen - FPGA tutorial for next year's group.
# Nmigen Tutorial
**Python version used :** Python 3.8.5
## Installation
**Nmigen :**
Click on [this link][1] to access a Github containing all the information needed to install **Nmigen** on different operating systems and other tools to interact with the FPGA card.
[1]: https://github.com/RobertBaruch/nmigen-tutorial "Nmigen tutorial"
---
During the installation of Next-PNR, we faced some issues that were solved using the following command lines :
*#NIX installation*
`curl -L https://nixos.org/nix/install | sh`
*#Creation of a shell containing the dependencies expected in the PATH, run this line for each new shell (it is faster after the first time because every files will already exist)*
`nix-shell -p icestorm nextpnr yosys 'python3.withPackages (ps: with ps; [ nmigen nmigen-boards ])'`
*#Test on examples*
`git clone https://github.com/icebreaker-fpga/icebreaker-nmigen-examples.git`
`cd icebreaker-nmigen-examples/blink`
`python3 blink.py`
---
Note that you need to replace these terms :
*-from nmigen_boards.icebreaker -> nmigen_boards.icestick*
*- 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.
## Transformation of Python modules to Nmigen modules
### Modules
In Python, a good habit to have is to divide your code into modules.
Those mmodules can by found in **Nmigen** but with a specific syntax.
In **Nmigen**, we need to create a class which implements *Elaboratble* and contains the two following methods :
>\_\_init\_\_() : Allows the initialisation of the attributes of the class (which should be represented by **Constants** and **Signals**)
>
>elaborate() : Method creating and returning the modules
In a module, there are two domains :
* **Combinatorial domain** : For operations between logic elements
* **Synchrone domain** : For operations using the cycles of a clock
*You can find examples on [Nmigen tutorial by Robert Baruch][1] or on [Nmigen][2]*
[1]: https://github.com/RobertBaruch/nmigen-tutorial "Nmigen tutorial"
[2]: https://github.com/m-labs/nmigen "Nmigen github"
### Simulation
**Nmigen** has its own simulation system.
Simulations can be launched using the commande *simulate*.
For more information, type the following command line in the console :
`python blinky.py simulate -h`
You have access to many options such as modifying the number of cycles of the simulation or adding options for **Gtkwave**.
**Gtkwave** allows you to visualize simulations on your computer.
This tool gives access to a graphic display of the simulation generated by **Nmigen**.
You just need to generate a *.vcd* file in your **Nmigen** code, which can then be openned using **Gtkwave**.
### Trasfering data to the FPGA card using Pyserial
The **UART** can be used to send data to the card.
More research needed.
### Using the LEDs of the card
Here is an example of the initialisation of the LEDs' array :
![alt text](./Images/LED_Nmigen.png "LEDs initialisation")
The LEDs' array is a byte array.
The card has 5 LEDs :
* First one on the left
* Second one at the top
* Third one on the right
* Fourth one at the bottom
* Fifth one in the middle
No preview for this file type
Markdown is supported
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