Eodbox Documentation Release 1.0
Total Page:16
File Type:pdf, Size:1020Kb
EODBox Documentation Release 1.0 Bailey Winter, Jason Gallant May 26, 2016 Contents 1 How Does It Work?? 3 1.1 Utilizing Programmable Real-Time Units (PRUs)............................3 1.2 Device Details and Specifications....................................4 1.3 Run Modes and Data Storage......................................8 2 How Do I Make My Own?? 11 2.1 Getting Started.............................................. 11 2.2 Modifying the BeagleBone for Communication............................. 12 2.3 External Storage............................................. 12 2.4 Modifying the PRU Memory....................................... 14 2.5 Enable the Real-Time Clock....................................... 15 3 Indices and tables 17 i ii EODBox Documentation, Release 1.0 Weakly electric fish are capable of both emitting and detecting electric signals called electric organ discharges (EODs). Current methods of recording EODs use multiple pieces of equipment that are fragile, expensive and inconvenient to transport, and rely on commercial software to record and analyze data. The goal of this project was to create a low cost and portable alternative to current research equipment. We created a device that we beleive circumvents these limitations, based the BeagleBone Black Rev C (BBB). The BBB uses a Texas Instruments AM335x 1GHz ARM© Cortex-A8, a reduced instruction set computing microprocessor that is capable of running two billion instructions per second. This is powerful processor for its size and is capable of running a full operating system. Our goal was to create a device with a user interface that allows for an adjustable, high- speed sampling rate, a designated run time, adjustable gain, flexible storage, and two ‘run modes’: a raw data recording a mode where EODs are automatically extracted. The device can be broken up into two units: a microcontroller that supplies power and processes the data, and a shield that amplifies and digitizes the signal. Contents 1 EODBox Documentation, Release 1.0 2 Contents CHAPTER 1 How Does It Work?? 1.1 Utilizing Programmable Real-Time Units (PRUs) The BBB runs a Debian Linux operating system which is not preemptive and cannot interrupt a kernel code once it begins executing. This causes an issue, as it does not allow for data collection in real time if the software is run on the main processor. To overcome this issue I had to make use of the processor’s programmable real time units (PRU). The PRUs operate as shown: First, a device tree overlay must be created and applied that configures and enables the GPIO pins. Then two different codes need to be written. The PRU code (Fishy.p) instructs the PRU on how to operate. This code is compiled in to a PRU program binary which can be interpreted by the PRU. The Linux host program (Fishy_v1.c) loads the PRU program binary to the PRU. The host program also communicates between the PRU and the Linux host. It is responsible for receiving and sending interrupts to and from the PRU. The PRU code is written in the assembly language and instructs the PRU to write the digitized data to a memory buffer. The buffer is only large enough to hold four seconds of data when the highest sampling rate is selected. Originally, the PRU code was written so that the program would end once the buffer was full; however, it is necessary to record more than four seconds of data. The program has been modified to create a circular buffer, so when the memory buffer is filled, the PRU returns to the beginning of the buffer and overwrites the previous data. As mentioned earlier, the Linux host program transfers the PRU binary and acts as a communication bridge between the PRU and the Linux host. When the memory buffer was finite, the host program only loaded the PRU binary to the PRU and a separate program was written to retrieve the data from the memory. Now that the memory buffer is circular and data analysis is required to occur in real time, the host code had to be altered to both read and analyze the data in the memory buffer as it was being written. In order to read the memory buffer, the buffer needs to be broken into segments that are read through individually. The current memory address is denoted as the variable “tail”, the beginning of the buffer segment is denoted as the variable “last_read_result” and the end of the segment is denoted as the variable “read_result”. By breaking the buffer into segments two situations can occur: 1. read_result > last_read_result In this situation the process is quite simple. A “for loop” iterates from last_read_result to read_result. With each iteration, the value stored in the memory address at tail is read and tail_position, position of the tail in the memory 3 EODBox Documentation, Release 1.0 buffer, is moved two bytes. Once the end of the loop is reached last_read_result is set to read_result and the two are compared again. If the comparison reveals the same situation, the process is repeated. 2. read_result < last_read_result In this situation arises when read_result reaches the end of the memory buffer and loops back around, but last_read_result has reached the end yet. In this situation a two part copy needs to be made. First the difference between the end of the buffer and last_read_result is calculated. A “for loop” iterates through these end point in the same manner as described in Situation 1. The program then iterates through another for loop that starts at the start of the buffer and ends at read_result. 1.2 Device Details and Specifications The shield that attaches to the BBB contains the entire circuit that is responsible for amplifying and digitizing the signal. This circuit is based on the Backyard Brains Muscle SpikerBox and has been modified for the purposes of this project. The circuit can be broken down into several subunits that perform individual functions. 1.2.1 Power Supply The first subunit of this circuit is the power supply unit, which creates a constant supply of the voltage supply divided by two. This unit is largely unchanged from the original design. Additional decoupling capacitors, C1 and C12, have been added and preexisting ones, C2 and C13 have been reconfigured. C1 and C12 stabilize the supply voltage, VCC, by removing any high frequency oscillations from the signal. C2 and C13 do the same for VCC/2. The LED is used as a visual cue to tell the user when the shield is being powered. The constant VCC/2 output from the op-amp is 4 Chapter 1. How Does It Work?? EODBox Documentation, Release 1.0 accomplished using a negative feedback amplifier circuit. Connecting the output of the amplifier to the inverting input should result in an output that follows closely to the non-inverting input. As the non-inverting input voltage input increases, the output voltage increases with accordance to the differential gain. Because the output voltage is fed back into the inverting input of the op-amp, the difference between the inputs will decrease causing the output voltage to decrease. Over time this stabilizes to output a voltage nearly equal to the non-inverting input voltage, but still low enough that the difference between the two inputs can generate the output voltage. Note: Currently, the entire shield is powered by the 3.3 V output from the BBB. The BBB itself is powered by a laptop via a microUSB, limiting where and how the device can be used. The board can be modified in the future to provide power through a battery. 1.2.2 Real Time Clock (RTC) The second subunit is the real time clock (RTC) circuit. The BBB does not have an onboard RTC circuit, making it incapable of keeping the date and time. The filenames depend on the date and time an experiment is performed making it necessary to add a separate RTC circuit to the board itself. The RTC chip is supplied with 5V from the BBB, with C11 as a decoupling capacitor, from the BBB to enable it to communicate with the microcontroller. An additional 3 V coin-cell battery is used to allow the RTC to retain the date and time when it is not being powered by the BBB. A quartz crystal regulates the electronic frequency oscillator. This keeps the oscillator at a very precise frequency, resulting in a highly accurate clock. RTC_SCL and RTC_SDA connect to input pins on the BBB and are the communication lines between the RTC circuit and the microcontroller. In some designs, there are 2.2 kΩ resistors between RTC_SCL and the supply voltage, and RTC_SDA and the supply voltage. Removing these resistors makes the BBB to use internal pullup resistors, forcing the BBB to communicate at 3.3 V instead of 5 V thus preventing the BBB from damage. 1.2.3 Amplifier The next subunit is the circuitry which takes in and amplifies the EODs. This subunit will be broken down into sections and described individually. The first subsection is where the signal is input into the circuit. 1.2. Device Details and Specifications 5 EODBox Documentation, Release 1.0 The signal is inputted into the circuit through an XLR connector and consists of a positive input, negative input, and ground. The positive and negative inputs are connected to the non-inverting and inverting inputs of the differential op-amp respectively. This op-amp outputs the difference between the non-inverting and inverting inputs with a gain of one. The circuit contains two stages of amplification. The first stage amplifies the signal before filtration occurs to reduce the amount of noise that is amplified. The signal is then amplified further to achieve the desired amount of amplification.