18: 16-Bit Communication Between Arduino and FPGA (DE0-Nano)

Please connect the following circuit for 16-bit communication between Arduino and FPGA (DE0-Nano):

PIN13 (the most significant bit) should be connected to the most significant bit of DE0-Nano (e.g. GPIO_1_D[3])

PIN12 should be connected to the second most significant bit of DE0-Nano (e.g. GPIO_1_D[2]).

PIN11 should be connected to the third most significant bit of DE0-Nano (e.g. GPIO_1_D[1])

PIN10 (the least significant bit) should be connected to the least significant bit of DE0-Nano (e.g. GPIO_1_D[0]).

Part 1: Arduino code:

To send a sequence of 16-bit signals [0000, 0001, 0010......1110, 1111] using Arduino, you can use the following code. 

const unsigned int LED_PIN13 = 13;

const unsigned int LED_PIN12 = 12;

const unsigned int LED_PIN11 = 11;

const unsigned int LED_PIN10 = 10;

const unsigned int PAUSE = 1000; //ms

void setup()

{

  pinMode(LED_PIN10, OUTPUT);

  pinMode(LED_PIN11, OUTPUT);

  pinMode(LED_PIN12, OUTPUT);

  pinMode(LED_PIN13, OUTPUT);

}

void loop()

{

  for (int input_value = 0; input_value < 16; input_value++)

  {

    for (int i = 10; i <= 13; i++)

    {

      digitalWrite(i, (input_value >> (i - 10)) & 1);

    }

    delay(PAUSE);

  }

}

Verilog code

To receive the 16-bit signals from Arduino and flash the 4 onboard LEDs on DE0-Nano accordingly, you can use the following code. After uploading the code, the 4 onboard LED on DE0-nano will be flashed in according to the 16-bit sequence. Inside the always block, there is a case statement that checks the value of the signal. Depending on the value, the led register is updated with the corresponding LED pattern. The code that is considered most important is highlighted in blue color, while the declaration terms can be omitted if the port is not required for your project.

module DE0_NANO(

CLOCK_50,

LED,

KEY,

SW,

DRAM_ADDR,

DRAM_BA,

DRAM_CAS_N,

DRAM_CKE,

DRAM_CLK,

DRAM_CS_N,

DRAM_DQ,

DRAM_DQM,

DRAM_RAS_N,

DRAM_WE_N,

EPCS_ASDO,

EPCS_DATA0,

EPCS_DCLK,

EPCS_NCSO,

G_SENSOR_CS_N,

G_SENSOR_INT,

I2C_SCLK,

I2C_SDAT,

ADC_CS_N,

ADC_SADDR,

ADC_SCLK,

ADC_SDAT,

GPIO_2,

GPIO_2_IN,

GPIO_0_D,

GPIO_0_IN,

GPIO_1_D,

GPIO_1_IN,

);

input           CLOCK_50;

input      [1:0] KEY;

input      [3:0] SW;

output     [12:0] DRAM_ADDR;

output      [1:0] DRAM_BA;

output           DRAM_CAS_N;

output           DRAM_CKE;

output           DRAM_CLK;

output           DRAM_CS_N;

inout     [15:0] DRAM_DQ;

output      [1:0] DRAM_DQM;

output           DRAM_RAS_N;

output           DRAM_WE_N;

output           EPCS_ASDO;

input           EPCS_DATA0;

output           EPCS_DCLK;

output           EPCS_NCSO;

output           G_SENSOR_CS_N;

input           G_SENSOR_INT;

output           I2C_SCLK;

inout           I2C_SDAT;

output           ADC_CS_N;

output           ADC_SADDR;

output           ADC_SCLK;

input           ADC_SDAT;

inout     [12:0] GPIO_2;

input      [2:0] GPIO_2_IN;

inout     [33:0] GPIO_0_D;

input      [1:0] GPIO_0_IN;

input     [33:0] GPIO_1_D;

input      [1:0] GPIO_1_IN;

wire [3:0] trigger; // Combined trigger signal

output reg [3:0] LED;

assign trigger = {GPIO_1_D[3:0]};

always @(posedge CLOCK_50)

begin        

case (trigger)

        4'b0000: LED <= 4'b0000;

        default: LED <= trigger;  // link the trigger value for LED output

        endcase

end

endmodule



Comments