HPS (G-Sensor) controlled FPGA LEDs

Steps for controllingFPGA LEDs (eight) using accelerometer (G-Sensor) connected to the HPS.

  1. This lab makes use of the existing demo code present in \DE0-Nano-SoC_v.1.1.0_SystemCD\Demonstrations\SoC_FPGA\HPS_CONTROL_FPGA_LED.
  2. This folder consists of two folders HPS_CONTROL_FPGA_LED and software.
  3. HPS_CONTROL_FPGA_LED consists of Quartus project for configuring the FPGA and software consists of source code executable file to run the HPS.
  4. In order to control the FPGA LEDs using G-Sensor readings one needs to modify the main.c file present in software folder and add the g-sensor files ADXL345.c and ADXL345.h into the folder, these files are obtained from g-sensor demo code (\DE0-Nano-SoC_v.1.1.0_SystemCD\Demonstrations\SoC\hps_gsensor).
  5. Now modify the main.c file by writing code for accessing g-sensor data.
  6. In main.c include error.h, string.h, linux/i2c-dev.h, sys/ioctl.h, sys/types.h, sys/stat.h, ADXL345.h
  7. Define a macro for alt_u16 as unsigned short.
  8. Copy ADXL345 control functions (ADXL345_REG_WRITE, ADXL345_REG_READ and ADXL345_REG_MULTI_READ) from g-sensor demo code (\DE0-Nano-SoC_v.1.1.0_SystemCD\Demonstrations\SoC\hps_gsensor\main.c).
  9. In main function, Open I2C bus driver "/dev/i2c-0": file = open("/dev/i2c-0", O_RDWR);
  10. Specify G-sensor's I2C address 0x53: ioctl(file, I2C_SLAVE, 0x53);
  11. Specify desired register index in g-sensor: write(file, &Addr8, sizeof(unsigned char));
  12. Read one-byte register value: read(file, &Data8, sizeof(unsigned char));
  13. You can refer to g-sensor demo code for more details.
  14. Remove the existing main while loop and write your own logic in a loop by reading the G-Sensor and mapping those readings to control LEDs.
  15. Now modify the MAKEFILE by adding ADXL345 object file to target. You can use this makefile.
  1. Install Altera SoC EDS (skip if already istalled).
  2. Launch the Altera Embedded Command Shell (Embedded_Command_Shell.bat) by browsing the SoC EDS folder (SoC_EDS_folder\embedded).
  3. In the Command Shell, use the Linux “cd” command to change current directory to your DE0-Nano-SoC_v.1.1.0_SystemCD\Demonstrations\SoC\HPS_CONTROL_FPGA_LED demonstrations folder.
  4. Then, type a “make” command to start the building (compiling and linking) process, as shownbelow.
  5. Copy the gsensor_led executable from your computer to the bootable SD card:

This can be done in two ways:

Method I:Copy the executable into the SD card /home/root directory by using a LINUX PC.

Method II:Copy the executable using Linux system command “scp” over Ethernet.

a.Connect both the PC and the DE0-Nano-SoC board to Ethernet router using RJ45 Ethernet cable.

Note: If you don’t have a router. Connect the board to one of the ethernet port in the lab (disconnect the existing system lan cable).

b.Connect your computer to the development board by plugging the USB cable into the micro USB connector (J4) of DE0-Nano-SoC.

c.Power on the board then open the computer device manager in Windows. Check for the board’s COM port.

d.Configure the VT100 terminal (TeraTerm or HyperTerminal) for the obtained COM port with the below settings.

115200 baud rate
no parity
1 stop bit
no flow control settings

e.Restart the board.

f.Type root and the password (if any)

g.Type “udhcpc” to query an IP from DHCP server

h.Type “ifconfig” to check the Ethernet IP for your DE0-Nano-SoC board.

i.You can find the ip address at “inetaddr:” in eth0.

j.If you have not defined the password for the root account, please type in Linux command “passwd” to create a password.

k.Now, in Altera Embedded Command Shell (Embedded_Command_Shell.bat), type “scphps_gsensorroot@ip_address:/home/root

ip_address is obtained from step i

l.Continue by replying yes and give the password of the board (assigned in step j).

m.Now the transfer is complete.

  1. Open Quartus project and program the fpga file with HPS_CONTROL_FPGA_LED.sof file.
  2. Now connect the cable to UART port on the board and access the board using VT100 terminal (similar to previous lab).

Note: Don’t power off the board after configuring the FPGA.

  1. In terminal execute the file by typing “./gsensor_led”.
  2. Based on the accelerometer X-axis readings the FPGA LEDs are controlled.