Skip to content

Demo: Teacup on DE0 nano with imp

Aleksandr Penskoi edited this page Jun 16, 2021 · 2 revisions

The test bench structure

The test bench was designed with the following components:

  1. The tool computer (imp001) controls a modeling process and data transmission. There is a single-board computer by Electric imp.
  2. The NITTA processor. It evaluates the system dynamics model in real-time and provides modeling data by its interfaces as inputs for a system under test. For realizing this component, the DE-0 Nano board with Cyclone IV FPGA has been used.

The controller and the NITTA processor communicate throughout SPI (for data transmission) interfaces. We chose those interfaces because they are ubiquitous.

A user and the test bench communicate throughout electric imp cloud-based IDE https://impcentral.electricimp.com.

+---------------------------------------------+
| Browser: https://impcentral.electricimp.com |
+---------------------------------------------+
    |
    |
    |
+----------+
| Internet |
+----------+
    |
    | Wi-Fi (old version, maybe you need to use Wi-Fi tethering)
    |
+--------+   SPI   +----------+
| imp001 |---------| DE0-nano |
+--------+         +----------+

DEO-nano - imp сonnection diagram

There are recommended colors of the wire in the brackets. The proportions are broken.

           +---------------------------------------- GND     (black)
           |            +--------------------------- MOSI_lg (orange)
           |            |+-------------------------- MISO_lg (blue)
           |            ||+------------------------- SCLK_lg (yellow)          
           |            |||+------------------------ CS_lg   (white)
+----------|------------||||-----+
|    ooooo *oooo ooooo o****     |
|    ooooo ooooo ooooo o****     |
|                       |||+------------------------ CS   (white)
+-----+                 ||+------------------------- SCLK (yellow)
| USB |    DE0-nano     |+-------------------------- MISO (blue)
+-----+                 +--------------------------- MOSI (orange)
|                    +--------+  |
|  +--------------+  | ALTERA |  |
|  |        =     |  +--------+  |
|  | DIP: 4 3 2 1 |              |
|  |      =   =   |              |
|  +------|-|-|---+              |
|         | | +----- rendevou (down)
|         | +------ frequency (up)
|         +-------------- rst (down)
|                                |
|    ooooo ooooo ooooo ooooo     |
|    ooooo ooooo ooooo ooooo     |
+--------------------------------+
                    +--------------------------------+
                    | o GND                          |
                    | o VIN                          |
                    | o                              |
                    | o Pin1                         |
(blue)    MISO------* Pin2           imp001          |
(yellow)  SCLK------* Pin5                           |
(orange)  MOSI------* Pin7                           |
(white)     CS -----* Pin8                           |
                    | o Dtc9                         |
                    | o 3V3   +-----+                |
(black)    GND -----* GND     | USB |                |
                    +---------+-----+----------------+

DE0-nano configuration

Software requirements:

The software that is required to run and set up the test bench:

  1. Project NITTA https://github.com/ryukzak/nitta.
  2. Haskell stack https://nitta.io/penskoi/nitta/src/master/doc/stack-install.md for NITTA build.
  3. [Quartus Prime Lite Edition]https://fpgasoftware.intel.com/?edition=lite and Cyclone IV device support. It's needed for synthesis and programming a demo project into the DE0-nano evaluation board.

Demo startup

You should build and plug in the stand on your table, on your computer, you have already installed all needed software, and you have opened the terminal in the suitable catalog. Further instructions are written for Windows 10, but you can use them for Linux too.

Each example application is a function, the execution of which will cause generation of project, synthesize, program it to evaluation board and test it. Its execution will cause the directory generation with the same name as the project in the path /gen/main.

$ stack exec nitta -- examples/teacup.lua -v -t=fx24.32
[NOTICE : NITTA] synthesis process...ok
[NOTICE : NITTA] write target project to: "gen/main"...ok

Open generated project in Quartus (nitta.qpf file) and synthesize it: Processing -> Start Compilation. After this, you need to flash the result in FPGA. To do this, you need Tools -> Programmer. In the File field, you need to write a path to firmware nitta.sof, if you see <none>, you need to press the field twice and choose firmware path to output_files/nitta.sof, and after set checkbox Program/Configure to active. Press the Start button. If the button is deactivated:

Make sure that DIP switches position to match to one shown on the diagram above.

imp configuration

Software requirements

You need an account on https://impcentral.electricimp.com for getting data from the NITTA processor. You can manually register and creating the project for that purpose or request a login and password from the project maintainer.

Demo startup

Now prepare to work the controller.

Instruction, if you use new account @new_account@:

  1. Set up a Wi-Fi network and connect controller as in instruction: https://developer.electricimp.com/gettingstarted/explorer/blinkup.
  2. Register account on electric imp site: https://impcentral.electricimp.com.
  3. In the left part of the menu, choose the Development Device Group Devices Tab and press the Assign button. In the Device Group item, set the Development Device Group and name of DDG that you give while project creation, after press the Assign Devices. Field with DEVICE ID must appear with online status.
  4. On the left in the menu, go to the Code tab, and in the Device Code field, insert the code below:
sc <- hardware.pin8;
sc.configure(DIGITAL_OUT, 1);

spi1 <- hardware.spi257;
spi1.configure( CLOCK_IDLE_LOW | CLOCK_2ND_EDGE, 1000 )

function echoTest_2bytes() {
    local tmp;
    local i = 0;   
    
    while ( i <= 0xFF) {
        local b = blob(2);
        b.writen( i, 'c' );
        b.writen( i + 1, 'c' );
        sc.write(0);
        tmp = spi1.writeread(b);
        sc.write(1);
        i += 2;
    }
}

function fibonacciTest(n) {
    local tmp;
    local i = 0;   
    
    while ( i < n ) {
        local b = blob(8);
        sc.write(0);
        tmp = spi1.writeread(b);
        sc.write(1);
        i += 1;
        server.log(tmp)
    }
}

function fibonacciTestFloat(n, int, bitrate) {
    local i = 0;   
    
    while ( i < n ) {
        local a = blob( int / 8 );
        local b = blob( (bitrate - int) / 8 );
        sc.write(0);
        
        local tmp1 = spi1.writeread(a);
        local tmp2 = spi1.writeread(b);
        sc.write(1);
        i += 1;
        
        local j = 0;
        local tmp = format("Int: ")
        while( j<(int/8) ) {
            tmp += format("%x ", tmp1[j])
            j++;
        }
        
        tmp += format("\tFloat: ")
        j = 0;
        while( j<((bitrate-int)/8) ) {
            tmp += format("%x ", tmp2[j])
            j++;
        }
        
        server.log(tmp)
        
    }
}

function getSum(n) {
    local i = 0;
    while(i < n) {
        local a = blob();
        local b = blob();
        a.writen(i, 'i');
        a.swap4();
        b.writen(i, 'i');
        b.swap4();
        
        sc.write(0);
        local tmp1 = spi1.writeread(a);
        local tmp2 = spi1.writeread(b);
        tmp1.swap4();
        tmp2.swap4();
        sc.write(1);
        i += 1;
        server.log( format("> %d %d\t%d", i, tmp1.readn('i'), tmp2.readn('i')) )
    }
}

function getTest(n, size) {
    local i = 0;   
    
    while ( i < n ) {
        local b = blob(size);
        sc.write(0);
        local tmp = spi1.writeread(b);
        sc.write(1);
        i += 1;

        server.log(tmp);
        tmp.swap4();
        local a = tmp.readn('i');
        local b = tmp.readn('i');
        server.log( format("> %d\t%d", a, b) );
    }
}

function fibonacciDemo(n) {
    local i = 0;   
    
    while ( i < n ) {
        local b = blob(8);
        sc.write(0);
        local tmp = spi1.writeread(b);
        sc.write(1);
        i += 1;

        server.log(tmp);
        tmp.swap4();
        local a = tmp.readn('i');
        local b = tmp.readn('i');
        server.log( format("> Index: %d\tValue: %d", b, a) );
    }
}

function teacupDemo(n) {
    local i = 0;   
    
    while ( i < n ) {
        local b = blob(8);
        sc.write(0);
        local tmp = spi1.writeread(b);
        sc.write(1);
        i += 1;

        server.log(tmp);
        tmp.swap4();
        local a = tmp.readn('i');
        local b = tmp.readn('i');
        server.log( format("> Index: %d\tValue: %d", b, a) );
    }
}

function getSumFloat(n, int, bitrate, value1, value2) {
    local i = 0;
    
    local count = 1;
    
    while( i<(bitrate - int) ) {
        count *= 10; 
        i++;
    }
    
    i = 0;
    while(i < n) {
        local a = blob();
        local b = blob();
        
        a.writen(value1 * count, 'i')
        b.writen(value2 * count, 'i')
        
        a.swap4();
        b.swap4();
        
        sc.write(0);
        local tmp1 = spi1.writeread(a);
        local tmp2 = spi1.writeread(b);
        sc.write(1);
        i += 1;
        
        tmp1.swap4()
        server.log(tmp1)
        server.log(tmp1.readn('i').tofloat() / count)

    }
}

// getTest(10, 4)
// getSum(10);
// echoTest_2bytes()
// echoTest_4bytes()
// fibonacciTest(10)
// fibonacciTestFloat(10, 8, 32)
// getSumFloat(10, 30, 32, 23.84, 26.73)

fibonacciDemo(10)
  1. The data transfer journal should appear on the bottom right side of the terminal. It should look like this:
2018-08-20 16:19:27 +03:00 	[Status] 	Agent restarted: reload.
2018-08-20 16:19:28 +03:00 	[Status] 	Device connected
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 00 00 00 00 00
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 0	Value:  0
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 01 00 00 00 01
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 1	Value:  1
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 01 00 00 00 02
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 2	Value:  1
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 02 00 00 00 03
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 3	Value:  2
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 03 00 00 00 04
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 4	Value:  3
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 05 00 00 00 05
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 5	Value:  5
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 08 00 00 00 06
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 6	Value:  8
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 0d 00 00 00 07
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 7	Value:  13
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 15 00 00 00 08
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 8	Value:  21
2018-08-20 16:19:28 +03:00 	[Device] 	binary: 00 00 00 22 00 00 00 09
2018-08-20 16:19:28 +03:00 	[Device] 	> Index: 9	Value:  34

The work of other demos will look similar.

Replace imp by Rasberry Pi

Raspberry Pi 3 configuration

(black)      GND ----------------------+
(white)       CS ------------------+   |
                 +-----------------|---|-----------------------+
                 |  +--------------|---|-------+     +---------+
                 |  |ooooo  ooooo  *ooo*  ooooo|     |         |
                 |  |ooooo  oooo*  **ooo  ooooo|     |         |
                 |  +-----------|--||----------+     +---------+
(orange)    MOSI ---------------+  ||                +---------+
(blue)      MISO ------------------+|                |         |
(yellow)    SCLK -------------------+                |         |
                 |                                   +---------+
                 |                                 +-----------+
                 |                                 |           |
                 |  +-----+                        |           |
                 |  | USB |                        +-----------+
                 +--+-----+------------------------------------+

For SSH connection on Windows, we recommended using PuTTY.

  1. Run PuTTY and fill the following fields:
    • Host Name: 192.168.1.78
    • Port: 22
    • Connection type: SSH
    • Click 'Open'
  2. Default login and password:
    • login: pi
    • password: raspberry
  3. > cd NITTA/c-spi/
  4. > make && make start
$ make && make start
gcc -o spi spi.c -l bcm2835
sudo ./spi
Read back from SPI: 0x00 0x00 0x00 0x00 | 00000, Number: 0x00 0x00 0x00 0x00
Read back from SPI: 0x00 0x00 0x00 0x01 | 00001, Number: 0x00 0x00 0x00 0x01
Read back from SPI: 0x00 0x00 0x00 0x01 | 00001, Number: 0x00 0x00 0x00 0x02
Read back from SPI: 0x00 0x00 0x00 0x02 | 00002, Number: 0x00 0x00 0x00 0x03
Read back from SPI: 0x00 0x00 0x00 0x03 | 00003, Number: 0x00 0x00 0x00 0x04
Read back from SPI: 0x00 0x00 0x00 0x05 | 00005, Number: 0x00 0x00 0x00 0x05
Read back from SPI: 0x00 0x00 0x00 0x08 | 00008, Number: 0x00 0x00 0x00 0x06
Read back from SPI: 0x00 0x00 0x00 0x0D | 00013, Number: 0x00 0x00 0x00 0x07
Read back from SPI: 0x00 0x00 0x00 0x15 | 00021, Number: 0x00 0x00 0x00 0x08
Read back from SPI: 0x00 0x00 0x00 0x22 | 00034, Number: 0x00 0x00 0x00 0x09

ATTENTION! After work with RPi, you need to execute:

$ sudo shutdown -h now