To be able to begin development on our project, we must first create a Nios II system for the Altera DE2 board using the Quartus II software provided free from Altera. The following system components are needed; Nios II Processor, JTAG/UART, SDRAM Memory Controller, I2C Interface Core, USB Host Controller, Ethernet Host Controller, GPIO for our General Purpose Input/Output and more memory may be added based on necessity. All of the previously mentioned components can be put together using the SOPC builder plug-in for Quartus II. With successful pin assignments and component settings, a new system will be created upon compilation.
The software side of the project becomes a little more rugged. To interface with the sensors, the memory addresses allocated for the GPIO headers needs to be initialized. The algorithm goes as follows:
- Record the temperature from the temperature sensor
- The temperature/humidity sensor uses I2C protocols to transfer data
- Store it in memory
- Have only the highest 50 and lowest 50 temperatures in memory with time stamps
- This could be possibly done using a timeout-interrupt routine to focus more on the accelerometer readings
- Have the accelerometer connected to an interrupt.
- If the shock measured passes a certain threshold, record the data with a timestamp.
- The FPGA will be constantly checking the Ethernet data in case a command is received from a remote device.
- If received, the processor will finish up its recent task and then process and execute the command.
- The use of Ethernet programming will also allow the board to communicate with the device via USB to possibly withdraw data, and or send commands to the host device.
Next we needed to connect the external sensors to the expansion headers. Due to last minute changes the ADXL345 is connected as I2C vice SPI as the figure below suggests. It should be noted that even though the Altera DE2 expansion headers can output 3.3 volts, when tested we this we were getting values that ranged from 3 volts to 3.8 volts. Due to concerns that we could damage the external sensors we implemented a voltage regulator for all supplies. This guaranteed our voltage remained at 3.3 volts regardless of what the Altera DE2 board outputs. Of course to keep the voltage above 3.3 we only used the 5 volt output pins on the expansion headers. When we connected the external sensors we had to connect to pull-up resistors to the data and clock lines of the ADXL345, as this is standard for I2C protocol. This step would be repeated for the ISL12058 real time clock as well, but would not be necessary for the SHT21as the breakout board had resistors already in place. Another protocol of ADXL345 is the voltage applied on the SDA line must be within 0.3 volts of any other device using I2C, in order to maintain this we matched the resistors on every device. The value we used for Rp is 4.7kΩ. The ADXL345 relative directions for the x, y, and z direction plus the expected output can be seen below. Another figure below shows the connections for the SHT21 humidity and temperature sensor. You can see the decoupling capacitor and pull-up resistors that are included on the breakout board. The largest challenge in building an environmental sensing module is the coding. Initially this project was undertaken in assembly language, and a skeletal frame was constructed. Unfortunately this would ultimately not work. To this day we do not quite know how that failed. What we do know is that it was suggested that we attempt this in C, since the Quartus software used to build the environmental sensing module has a C complier, linker, libraries, and a debugger.
The basic idea for the program when we first began was simple; a start up section would set-up all register and initialize the real time clock. Now for the sake of a production model, this start up section would be accessible to the customer, allowing them to change the time on the clock and adjust some of the sensitivity on specific sensors. But for the needs of this project, under the scope of testing the feasibility of such a device, we would only need to access this section at the start-up of the environmental sensing module. Following the start-up section, a quick check for interrupts is done, if there is an interrupt then a determination of which sensor is interrupting is performed with a case switch, resulting in the reading of the sensor. This data with timestamp is stored in memory if it meets the requirements of storage. If no interrupt has occurred, then the system sits in an infinite loop until one occurs. This is not really infinite, as the interrupt from the SHT21 comes every minute. A one minute delay is implemented here to guarantee that the SHT21 does not overheat due to excessive measurements. All temperature, humidity, and shock measurements are then compared to stored values already in memory, if the magnitude exceed any of those magnitudes already stored, they overwrite the value of the least importance, otherwise the system go back to check for the interrupt again. This method ensures constant temperature and humidity checks every minute and only stores the top fifty temperatures, bottom fifty temperatures, top fifty humidity, and bottom fifty humidity. Similarly the top and bottom fifty shock measurements which trigger interrupts are recorded.