iCE40 Low Power Sensor Hub Solution for Mobile Devices June 2014 Reference Design RD1189 General Description The iCE40 Sensor Hub Solution is a low power sensor hub solution for mobile devices using iCE40LM and iCE40 Ultra™ FPGAs. It is designed to monitor sensors and periodically send the sensor data to the application processor. The Sensor Hub reference design acts as a buffer between the sensors and the application processor. When the Sensor Hub is used in a design, it allows the application processor to sleep for longer periods of time. The Sensor Hub reduces unnecessary communication between the sensors and the processor, thus saving power consumption by allowing the processor not to be in an “always on” state. The iCE40 Sensor Hub Solution is configurable, available as either standalone off the shelf or fully customizable, making it a sensor agnostic solution. Figure 1. System Block Diagram iCE40 Sensor Hub Solution BMP085 Sensor Monitor MAX44006 Sensor Monitor SPI Slave I2C Master (1.8 V Interface) LSM330DLC Sensor Monitor (Application Processor Interface) SHT20 Sensor Monitor I2C Master (3.3 V Interface) LSM303DLHC Sensor Monitor Power - On Reset Module As a standalone solution, the iCE40 Sensor Hub connects to the application processor’s Serial Peripheral Interface Bus (SPI) with clock frequency set to 10.8 MHz. This enables a fast communication speed to/from the processor. The iCE40 Sensor Hub standalone solution acts as I2C master to the supported sensors. There are two sets of I2C connections configured with multiple sensors at each connection in the iCE40 Sensor Hub standalone solution. The default sensors supported in the standalone iCE40 Sensor Hub Solution are: Bosch BMP085 Digital Pressure Sensor; Maxim Integrated MAX44006 RGB Color, Infrared, and Temperature Sensors; Sensirion SHT20 Humidity and Temperature Sensor IC; STMicro LSM330DLC 3D accelerometer and 3D gyroscope; and STMicro LSM303DLHC 3D accelerometer and 3D magnetometer module. The iCE40 Sensor Hub standalone solution has a system operating frequency of 27 MHz, SPI bus frequency to application processor of 10.8 MHz, and I2C clock frequency of 400 kHz. The SPI bus is configured to have a voltage of 1.8 V, and the two I2C buses are configured to have voltages of 1.8 V and 3.3 V, enabling the solution to connect to sensors with different I/O voltages and bridging sensors of different I/O voltages to the application processor. © 2014 Lattice Semiconductor Corp. All Lattice trademarks, registered trademarks, patents, and disclaimers are as listed at www.latticesemi.com/legal. All other brand or product names are trademarks or registered trademarks of their respective holders. The specifications and information herein are subject to change without notice. www.latticesemi.com 1 rd1189_1.1 Low Power Sensor Hub Solution for Mobile Devices The fully customizable solution capability of this solution is due to its FPGA based architecture. This capability is ideal, but not limited to users who would like to include/remove supported sensors, change the data acquisition FIFO depth, create an I/O bridge between sensors and processor, or customize sensor monitoring time period. Regardless of the solution type, the iCE40 Sensor Hub Solution has a core voltage of 1.2 V. It is available in a very small form-factor 25-pin WLCSP package. The package has 0.35 mm ball pitch, making the overall package size to be 1.71 mm x 1.71 mm that easily fit into a number of mobile devices such as smart phones. Other packages include .4 mm ball pitch with 36 balls (2.5 mm x 2.5 mm) or 49 balls (3 mm x 3 mm). The solution operates at industrial temperature range of -40 oC to 100 oC. Figure 2. Package Diagram for iCE40LM (Balls Up) A5 A4 A3 A2 A1 B5 B4 B3 B2 B1 C5 C4 C3 C2 C1 D5 D4 D3 D2 D1 E5 E4 E3 E2 E1 Note: Package diagram of the iCE40 Ultra will be provided when available. As a standalone solution, you simply obtain the solution which includes the device, Diamond Programmer software, and ready-for-download bitstream. As a fully customizable solution, you will obtain the device, the iCEcube2 design software, the programming software, and the source code of the Sensor Hub Solution. Features • Configurable Sensor Hub for Mobile Devices – Sensor Agnostic Solution – Default System frequency of 27 MHz – Power-On Reset capability • Default Supported Sensors: – Bosch BMP085 Digital Pressure Sensor – Maxim Integrated MAX44006 RGB Color, Infrared, and Temperature Sensors – Sensirion SHT20 Humidity and Temperature Sensor IC – STMicro LSM330DLC 3D accelerometer and 3D gyroscope – STMicro LSM303DLHC 3D accelerometer and 3D magnetometer • Serial Peripheral Interface (SPI) Bus connection to Application Processor with the following Default settings: – Interface frequency of 10.8 MHz – Interface voltage of 1.8 V – Solution is a “slave” of the Application Processor – SPI slave mode CPOL = 1 and CPHA = 1 (mode “3”) – SPI slave features MSB first • One I2C Bus with default interface voltage of 1.8V at 400kHz for: – Bosch BMP085 Digital Pressure Sensor – Maxim Integrated MAX44006 RGB Color, Infrared, and Temperature Sensors 2 Low Power Sensor Hub Solution for Mobile Devices – STMicro LSM330DLC 3D accelerometer and 3D gyroscope • One I2C Bus with default interface voltage of 3.3 V at 400 kHz for: – Sensirion SHT20 Humidity and Temperature Sensor IC – STMicro LSM303DLHC 3D accelerometer and 3D magnetometer module • General – Core voltage of 1.2 V – I/O voltages of 1.8 V and 3.3 V – 25-pin WLCS at 1.69 mm x 1.69 mm with 0.35 mm pitch – Industrial Grade (-40 oC to 100 oC) Applications • Notebook PCs • Smart Phones • Tablets • Handheld Gaming Units • GPS Units • Digital Cameras Functional Block Diagram Figure 3. Functional Block Diagram iCE40 Sensor Hub Solution C4 E3 BMP085 Sensor Monitor proc_sdo proc_sclk proc_csn A5 A4 A3 SPI Registers and Control Logic proc_intr B5 SPI Interface Module proc_sdi C2 MAX44006 State Machine LSM330DLC Sensor Monitor Data FIFO B1 poola_sensor_scl poola_sensor_sda I2C Arbiter SHT20 State Machine LSM303DLHC Sensor Monitor Data FIFO A1 LSM330DLC State Machine SHT20 Sensor Monitor Data FIFO I2C Arbiter I2C Module (1.8 V Interface) MAX44006 Sensor Monitor Data FIFO sensor0_xclr BMP085 State Machine LSM303DLHC State Machine Power-On Reset Module 3 I2C Module (3.3V Interface) Data FIFO I2C Control and State Machine Logic SPI Reg Module I2C Control and State Machine Logic clk E5 D5 poolb_sensor_scl poolb_sensor_sda Low Power Sensor Hub Solution for Mobile Devices Specifications Recommended Operating Conditions Table 1. Recommended Operating Conditions - iCE40LM Symbol Parameter Typ. Max. Units See DS1045, iCE40LM Family Data Sheet 1.2 See DS1045, iCE40LM Family Data Sheet V Bank 1 I/O Driver Supply Voltage 1.71 1.8 1.89 V Bank 2 I/O Driver Supply Voltage 3.14 3.3 3.46 V Junction Temperature Operation See DS1045, iCE40LM Family Data Sheet - See DS1045, iCE40LM Family Data Sheet Typ. Max. Units See DS1048, iCE40 Ultra Family Data Sheet V VCC Core Supply Voltage VCCIOVB11 VCCIOVB21 tJUND Min. o C 1. Assumes operating under “off-the-shelf standalone1 solution”. Table 2. Recommended Operating Conditions - iCE40 Ultra Symbol VCC Parameter Core Supply Voltage Min. See DS1048, iCE40 Ultra Family Data Sheet VCCIOVB11 Bank 1 I/O Driver Supply Voltage 1.89 V VCCIOVB21 Bank 2 I/O Driver Supply Voltage 3.46 V tJUND Junction Temperature Operation See DS1048, iCE40 Ultra Family Data Sheet See DS1048, iCE40 Ultra Family Data Sheet o C 1. Assumes operating under “off-the-shelf standalone1 solution”. Power Supply Ramp Rates See DS1045, iCE40LM Family Data Sheet and DS1048, iCE40 Ultra Family Data Sheet Power-On-Reset Voltage Levels See DS1045, iCE40LM Family Data Sheet and DS1048, iCE40 Ultra Family Data Sheet. ESD Performance See DS1045, iCE40LM Family Data Sheet and DS1048, iCE40 Ultra Family Data Sheet. DC Electrical Characteristics See DS1045, iCE40LM Family Data Sheet and DS1048, iCE40 Ultra Family Data Sheet. Set the VCCIO values to the values stated in the Recommended Operating Conditions table. Power Supply Current See DS1045, iCE40LM Family Data Sheet and DS1048, iCE40 Ultra Family Data Sheet. Absolute Maximum Ratings See DS1045, iCE40LM Family Data Sheet and DS1048, iCE40 Ultra Family Data Sheet 4 Low Power Sensor Hub Solution for Mobile Devices Performance Characteristics Table 3. Performance Characteristics - iCE40LM1, 4 Symbol Parameter Min. Fcoremax System Frequency Tcoremaxdcd Maximum duty cycle distortion for System Clock Fi2cmax Tcoi2c33 I2C Interface Frequency2 I2C setup time (1.8 V interface) I2C hold time (1.8 V interface) I2C clock to out time (1.8 V interface) I2C setup time (3.3 V interface) I2C hold time (3.3 V interface) I2C clock to out time (3.3 V interface) Tcoxclr sensor0_xclr clock to out time Tsui2c18 Thdi2c18 Tcoi2c18 Tsui2c33 Thdi2c33 Fspimax SPI Bus Frequency Tsuspi SPI setup time Typ. Max. Units 27 MHz % 400 kHz ns ns ns ns ns ns ns 10.8 MHz ns Thdspi SPI hold time ns Tcospi SPI clock to out time ns Tscsn proc_csn setup time ns Thdcsn proc_csn hold time ns Tcointr proc_intr clock to out time Tsampbmp085 BMP085 Sampling Period3 5636096 Cycles ns Tsamplsm303 LSM303DLHC Sampling Period3 2621440 Cycles Tsamplsm330a LSM330DLC Accelerometer Sampling Period3 2621440 Cycles Tsampmax44006 MAX44006 Sampling Period3 5636096 Cycles 2621440 Cycles 2621440 Cycles 256 Cycles 3 Tsampsht20 SHT20 Sampling Period Tsamplsm330g LSM330DLC Gyroscope Sampling Period3 Tpor 1. 2. 3. 4. 3 Power-On Reset duration Assumes operating under “off-the-shelf standalone1 solution” Value applies for both 1.8 V and 3.3 V based interface Relative to System Frequency All values are based on iCEcube2’s Timing Analyzer’s results. The design is not validated by test engineering. 5 Low Power Sensor Hub Solution for Mobile Devices Table 4. Performance Characteristics - iCE40 Ultra1, 4 Symbol Parameter Min. TBD System Frequency Tcoremaxdcd Maximum duty cycle distortion for System Clock Fi2cmax Tcoi2c33 I2C Interface Frequency2 I2C setup time (1.8 V interface) I2C hold time (1.8 V interface) I2C clock to out time (1.8 V interface) I2C setup time (3.3 V interface) I2C hold time (3.3 V interface) I2C clock to out time (3.3 V interface) Tcoxclr sensor0_xclr clock to out time Tsui2c18 Thdi2c18 Tcoi2c18 Tsui2c33 Thdi2c33 Fspimax SPI Bus Frequency Tsuspi SPI setup time Typ. Max. Units MHz % kHz ns ns ns ns ns ns ns MHz ns Thdspi SPI hold time ns Tcospi SPI clock to out time ns Tscsn proc_csn setup time ns Thdcsn proc_csn hold time ns Tcointr proc_intr clock to out time ns Tsampbmp085 BMP085 Sampling Period3 Cycles Tsamplsm303 LSM303DLHC Sampling Period3 Cycles Tsamplsm330a LSM330DLC Accelerometer Sampling Period3 Cycles Tsampmax44006 MAX44006 Sampling Period3 Cycles 3 Tsampsht20 SHT20 Sampling Period Tsamplsm330g LSM330DLC Gyroscope Sampling Period3 Tpor 1. 2. 3. 4. Cycles 3 Power-On Reset duration Cycles Cycles Assumes operating under “off-the-shelf standalone1 solution” Value applies for both 1.8V and 3.3V based interface Relative to System Frequency All values are based on iCEcube2’s Timing Analyzer’s results. The design is not validated by test engineering. FPGA Characteristics See Device Data Sheet. Note that once customization is performed, the values in “Performance Characteristics” may not be the same. 6 Low Power Sensor Hub Solution for Mobile Devices Pin Configuration and Function Descriptions Figure 4. Bottom View of iCE40LM4K-SWG25TR (Balls Up) A5 A4 A3 A2 A1 B5 B4 B3 B2 B1 C5 C4 C3 C2 C1 D5 D4 D3 D2 D1 E5 E4 E3 E2 E1 Note: Bottom view of the iCE40 Ultra device will be provided when available. Table 5. Pin Function Description - iCE40LM1 Pad Name Port Name Port Direction Description 2 A1 poola_sensor_scl Inout I C Interface SCL for sensors with 1.8 V interface A2 VCCIOVB1 Input I/O Power Supply A3 proc_csn Input SPI bus slave select (Active Low) A4 proc_sclk Input SPI bus serial clock A5 proc_sdo Input SPI bus serial data in to slave B1 poola_sensor_sda Inout I2C Interface SDA for sensors with 1.8 V interface B2 GND Input Ground B3 CRESET Input Configuration Reset (Active Low). See data sheets. B4 VCC Input Core Power Supply B5 proc_intr Output C1 ice_SI Output Configuration Output to external SPI Memory C2 proc_sdi Output SPI bus serial data out from slave C3 CDONE Output Configuration Done. See data sheets. C4 sensor0_xclr Output Master Clear for Pressure Sensor (Bosch BMP085) C5 General Purpose I/O D1 flsh_sclk D2 ice_SO D3 General Purpose I/O Input/Output Input Input Input/Output Processor Interrupt to Application Processor 3.3 V I/O for user interface Configuration Clock Configuration Input from external SPI Memory 3.3 V I/O for user interface D4 GND Input Ground D5 poolb_sensor_sda Inout I2C Interface SDA for sensors with 3.3 V interface E1 flsh_cs Input Configuration Chip Select (Active Low) E2 VCCIOVB2 Input I/O Power Supply E3 clk E4 General Purpose I/O E5 poolb_sensor_scl Input Input/Output Inout 1. Assumes operating under “off-the-shelf standalone1 solution”. 7 System Clock 3.3 V I/O for user interface I2C Interface SCL for sensors with 3.3 V interface Low Power Sensor Hub Solution for Mobile Devices Table 6. Pin Function Description - iCE40 Ultra1 Pad Name TBD Port Name Port Direction poola_sensor_scl Inout Description I2C Interface SCL for sensors with 1.8 V interface TBD VCCIOVB1 Input I/O Power Supply TBD proc_csn Input SPI bus slave select (Active Low) TBD proc_sclk Input SPI bus serial clock TBD proc_sdo Input SPI bus serial data in to slave TBD poola_sensor_sda Inout I2C Interface SDA for sensors with 1.8 V interface TBD GND Input Ground TBD CRESET Input Configuration Reset (Active Low). See data sheets. TBD VCC Input Core Power Supply TBD proc_intr Output Processor Interrupt to Application Processor TBD ice_SI Output Configuration Output to external SPI Memory TBD proc_sdi Output SPI bus serial data out from slave TBD CDONE Output Configuration Done. See data sheets. TBD sensor0_xclr TBD General Purpose I/O TBD flsh_sclk Input Configuration Clock TBD ice_SO Input Configuration Input from external SPI Memory TBD General Purpose I/O TBD GND Input Ground TBD poolb_sensor_sda Inout I2C Interface SDA for sensors with 3.3 V interface TBD flsh_cs Input Configuration Chip Select (Active Low) TBD VCCIOVB2 Input I/O Power Supply TBD clk Input System Clock TBD General Purpose I/O TBD poolb_sensor_scl Output Input/Output Input/Output Input/Output Inout Master Clear for Pressure Sensor (Bosch BMP085) 3.3 V I/O for user interface 3.3 V I/O for user interface 3.3 V I/O for user interface I2C Interface SCL for sensors with 3.3 V interface 1. Assumes operating under “off-the-shelf standalone1 solution”. Theory of Operations The iCE40 Sensor Hub Solution monitors the sensors attached to its I2C buses. It monitors each sensor periodically for new values. Each sensor monitor can be configured separately. Each sensor monitor block has a dedicated FIFO to store the read values of corresponding sensors. After sensor data has been read, the sensor monitor sends an interrupt to the application request to indicate that sensor data is present. The application processor is then expected to read the FIFO contents through the SPI bus. Once the sensor data has been read, then the application processor will need to clear both the FIFO and the interrupt. The default supported sensors in the iCE40 Sensor Hub Solution are divided into two groups: those with 1.8 V interface and those with 3.3 V interface. The default supported sensors are as follow: • 1.8V interface voltage: – Bosch BMP085 Digital Pressure Sensor – Maxim Integrated MAX44006 RGB Color, Infrared, and Temperature Sensors – STMicro LSM330DLC 3D accelerometer and 3D gyroscope • 3.3V interface voltage: – Sensirion SHT20 Humidity and Temperature Sensor IC – STMicro LSM303DLHC 3D accelerometer and 3D magnetometer 8 Low Power Sensor Hub Solution for Mobile Devices Functional Descriptions This sub-section describes the function of each sub-block in inside the iCE40 Sensor Hub Solution. Many of these blocks have HDL module associated with them. Sensor Monitor Top Level The Sensor Monitor Top Level is found in sensor_hub. This module contains submodules for all Sensor Monitors, the two I2C interfaces, and SPI interface to/from application processor. It also contains a Power-On Reset (POR) module. The POR module initiates a system reset upon power up for Tpor number of cycles. The iCE40 Sensor Hub Solution operates after system reset has been completed. BMP085 Sensor Monitor The BMP085 Sensor Monitor monitors Bosch BMP085 Digital Pressure Sensor, and it is found in BMP085_prsr. This module begins by calibrating the BMP085 sensor by reading the pre-defined values in the calibration matrix of the BMP085 sensor. Once calibration is completed, the BMP085 sensor monitor will periodically read the temperature and pressure values from the BMP085 sensor. As a standalone off the shelf solution the number of cycles with respect to the system clock at which this module reads the BMP085 sensor value is Tsampbmp085. For the fully customizable solution, you can change the number of cycles by changing the INTR_THRESHOLD parameter value. All values read from BMP085 are stored in a FIFO that’s accessible by the application processor through the SPI Interface to Application Processor module. Once sensor data has been read, this module issues an interrupt for the Application Processor to indicate that data is present. When the Application Processor gets the interrupt, it first reads the BMP085 status register bit to determine whether the data available in the FIFO is calibration data or sensor data, which will the be used appropriately for calculations. After the Application Processor receives the data, it is expected that the interrupt and the FIFO will be cleared by the Application Processor. At the end of each acquisition this module issues XCLR signal to reset the sensor. Figure 5. BMP085 Pressure Sensor None Initialization Readout EEPROM registers, 16 bit, MSB first Calibration Read uncompensated 2 bytes temperature and 2 bytes pressure values 5 times per second Operation 9 Low Power Sensor Hub Solution for Mobile Devices LSM303DLHC Sensor Monitor The LSM303DLHC Sensor Monitor monitors STMicro LSM303DLHC's 3D magnetometer module, and it is found in LSM303_magneto. This module starts by initializing the LSM303DLHC by writing to CRA, CRB, and MR registers of the LSM303DLHC device to set the operation mode of the magnetometer. Once initialization is completed, the LSM303DLHC sensor monitor will periodically read the magnetic value from LSM303DLHC. As a standalone off the shelf solution the number of cycles with respect to the system clock at which this module reads the LSM303DLHC sensor value is Tsamplsm303. For the fully customizable solution, you can change the number of cycles by changing the INTR_THRESHOLD parameter value. All magnetic values read are stored in a FIFO that’s accessible by the application processor through the SPI Interface to Application Processor module. Once sensor data has been read, this module issues an interrupt for the Application Processor to indicate that data is present. After the Application Processor has received the data, then it is expected that the interrupt and the FIFO be cleared by the Application Processor. Figure 6. LSM303 Compass Write CTRL_REGA = 8’h08 To Disable Temp sensor, Set Min. o/p data rate = 3 Hz Write CTRL_REGB = 8’h20 To set Sensor input field range - +/1.3 Gauss Initialization Write MR_REG = 8’h00 To set continuous conversion mode None Read 6 bytes data values from DATA register 10 times per second 10 Calibration Operation Low Power Sensor Hub Solution for Mobile Devices LSM330DLC Accelerator Sensor Monitor The LSM330DLC Accelerator Sensor Monitor monitors only the accelerometer portion of STMicro LSM330DLC 3D accelerometer and 3D gyroscope module, and it is found in LSM330DLC_accel. This module starts by initializing the LSM330DLC by writing to Control REG1A and Control REG4A registers of the LSM330DLC device to set the operation mode of the accelerometer. Once initialization is completed, the LSM330DLC sensor monitor will periodically read the accelerometer value from LSM330DLC. As a standalone off the shelf solution the number of cycles with respect to the system clock at which this module reads the LSM330DLC device is Tsamplsm330a. For the fully customizable solution, you can change the number of cycles by changing the INTR_THRESHOLD parameter value. All acceleration values read are stored in a FIFO that’s accessible by the application processor through the SPI Interface to Application Processor module. Once sensor data has been read, this module issues an interrupt for the Application Processor to indicate that data is present. After the Application Processor has received the data, then it is expected that the interrupt and the FIFO be cleared by the Application Processor. Figure 7. LSM330DLC Accelerometer Wait for approximately 75ms for sensor to configure Write ‘Sample rate’ REG = 8’h57 To set ODR = 100 Hz, to enable normal mode and to enable X, Y and Z axis Initialization Write ‘Full scale and Resolution selection’ REG = 8’h08 To set FS=+/-2G, and to set high resolution output mode None Read 6 bytes of data values from DATA register for resp. o/p axis 10 times per second 11 Calibration Operation Low Power Sensor Hub Solution for Mobile Devices MAX44006 Sensor Monitor The MAX44006 Sensor Monitor monitors Maxim Integrated MAX44006 RGB Color, Infrared, and Temperature Sensors, and it is found in Max44006_als. This module starts by initializing the MAX44006 by confirming the Power-On State of the device; and setting up the UPR_THRM, UPR_THRL, LWR_THRM, LWR_THRL, PERSIST_TIMER, AMBIENT configuration, and sensor mode of the device. These sets the operational modes of the sensor, including the RGB interrupt thresholds, RGB gain, and ADC conversion timing. Once initialization is completed, the MAX44006 sensor monitor will periodically read the color, infrared, and temperature values from MAX44006. As a standalone off the shelf solution the number of cycles with respect to the system clock at which this module reads the MAX44006 device is Tsampmax44006. For the fully customizable solution, you can change the number of cycles by changing the INTR_THRESHOLD parameter value. All values read are stored in a FIFO that’s accessible by the application processor through the SPI Interface to Application Processor module. Once sensor data has been read, this module issues an interrupt for the Application Processor to indicate that data is present. After the Application Processor has received the data, then it is expected that the interrupt and the FIFO be cleared by the Application Processor. Figure 8. MAX44006 Ambient Light Sensor Write MS byte of Upper threshold REG = 8’hAA Write LS byte of Upper threshold REG - 8’h00 To set Upper threshold limit for light sensing Write MS byte of Lower threshold REG = 8’h00 Write LS byte of Lower threshold REG - 8’h00 To set Lower threshold limit for light sensing Initialization Write Persist Timer threshold REG = 8’h10 To To set Persist value as 8 Write Ambient Configuration REG = 8’h00 To Disable temperature sensor, disable IR compensation and to use factory calibrated gains Write ‘MAIN Configuration’ REG = 25 To Enable ambient interrupt, to use green channel data to compare with ambient interrupt threshold None Read 8 bytes sensor value from DATA register approximately 5 times per second 12 Calibration Operation Low Power Sensor Hub Solution for Mobile Devices SHT20 Sensor Monitor The SHT20 Sensor Monitor monitors only the humidity sensor of the Sensirion SHT20 Humidity and Temperature Sensor IC, and it is found in SHT20_humidity. This module starts by initializing the SHT20 by resetting the sensor, and reading and writing the user register of the SHT20 device. These set the operation mode of the SHT20 device. Once initialization is completed, the SHT20 sensor monitor will periodically read the humidity value from SHT20. As a standalone off the shelf solution the number of cycles with respect to the system clock at which this module reads the SHT20 device is Tsampsht20. For the fully customizable solution, you can change the number of cycles by changing the INTR_THRESHOLD parameter value. All humidity values read are stored in a FIFO that’s accessible by the application processor through the SPI Interface to Application Processor module. Once sensor data has been read, this module issues an interrupt for the Application Processor to indicate that data is present. After the Application Processor has received the data, then it is expected that the interrupt and the FIFO be cleared by the Application Processor. Figure 9. SHT20 Humidity Sensor Wait for approximately 15ms for sensor to configure Read ‘USER REGISTER’ and save the data to user_reg Initialization Write ‘USER REGISTER’ = 8’h3A ({1’b0,user_reg[6:3],1’b0,1’b1,1’b0}) To set Measurement resolution enable, on chip heater enable and to disable OTP reload None Read 3 bytes of data values 10 times per second 13 Calibration Operation Low Power Sensor Hub Solution for Mobile Devices LSM330DLC Gyro Sensor Monitor The LSM330DLC Sensor Monitor monitors only the gyroscope portion of STMicro LSM330DLC 3D accelerometer and 3D gyroscope module, and it is found in LSM330DLC_gyro. This module starts by initializing the LSM330DLC by writing to Control REG1G register of the LSM330DLC device to enable the output data rate and to enable normal power mode for gyroscope operation. Once initialization is completed, the LSM330DLC gyro sensor monitor will periodically read the gyroscope value from LSM330DLC. As a standalone off the shelf solution the number of cycles with respect to the system clock at which this module reads the LSM330DLC gyro sensor value is Tsamplsm330g. For the fully customizable solution, you can change the number of cycles by changing the INTR_THRESHOLD parameter value. All gyroscope values read are stored in a FIFO that’s accessible by the application processor through the SPI Interface to Application Processor module. Once sensor data has been read, this module issues an interrupt for the Application Processor to indicate that data is present. After the Application Processor has received the data, then it is expected that the interrupt and the FIFO be cleared by the Application Processor. Figure 10. LSM330DLC Gyroscope Write for approximately 7 ms for sensor to configure Initialization Write ‘Sample rate’ REG = 8’h0F To set ODR = 95 Hz, to disable power down mode and to enable X, Y and Z axis None Read 6 bytes data values from DATA register for resp. o/p axis 10 times per second Calibration Operation I2C Arbiter The I2C Arbiter module muxes/demuxes the control signals to/from the I2C master to and from all sensor monitors. It goes through all sensor monitors one-by-one in a round-robin fashion to see whether a sensor data read request is present. When a sensor monitor is not available, it goes to the next sensor and so on. This module can be found in i2c_arbiter, and there are two instances of this module: one for the 1.8 V interface, and another for the 3.3 V interface. This module sends and receives command from each sensor monitor so that data can be sent/received through the I2C interface. The I2C arbiter also contains the control for I2C interface (found in i2c_reg_ctrl). SPI Interface to Application Processor This module is used to interface between the iCE40 Sensor Hub Solution and the application processor. It is found in spi_reg module. This module contains the SPI registers VERSION, ISR, CNTRL, and STATUS. This module starts by initializing the SPI Control Register 1 and waits until an interrupt or read from a sensor command is received from the processor. When a read command is received, this module goes to read from RXDR fol- 14 Low Power Sensor Hub Solution for Mobile Devices lowed by byte write. It then determines if the MISO byte is valid followed by write to TXDR command. Once these are completed, it goes back to an idle state. The state machine is in spi_slave module. When a read command is received from the application processor, this module sends commands to the desired sensor so that the stored sensor values in the FIFOs are read out. This module then receives the stored sensor values and sends them to the application processor. Once the data has been read, the application processor will need to clear the FIFO and the interrupt register for the corresponding sensor. When a write command is received from the application processor, this module decodes the commands and sends the appropriate data to the desired register locations. Finally, this module also contains an interrupt arbiter (intr_arb) module that polls interrupt (i.e. to indicate that sensor data is present) from the sensor monitors. This module ensures that the processor is interrupted by only one of the sensor monitors at a time and the interrupts by other sensor monitor during that time are latched and presented one after the other. Once the interrupt is recognized and served by the processor, the interrupt arbiter module will acknowledge the sensor monitor that the interrupt has been received. Block Descriptions The purpose of this section is to provide detailed descriptions of each block of the iCE40 Sensor Hub to assist users who want to use this solution using alternative sensors. Top Level Module (sensor_hub) This module contains all of the sensor monitors, SPI interface to the application processor, and two sets of I2C interface to the sensors. The HDL code begins with the POR logic, which is set to Tpor cycles. All the sensor monitors are then instantiated with their respective parameters set. In addition to system clock and system reset, each sensor monitor has connections to/from one of the I2C interfaces and the SPI interface. Notice that each wire connection has the same name prefix dev#, where # is an integer, and name suffixes that corresponds to the module port name. Each wire connection is connected to SPI ports with corresponding dev# and name suffix. On the other hand, the I2C wire connections may not have the same sensor monitor dev# (although, each sensor monitor’s dev# set must be connected to the same I2C interface port’s dev# set), but will have the same name suffix. There’s only one I2C and one SPI connection for each sensor. The code then instantiates two i2c_arbiter modules, which contain the I2C interface. Each module has connection to the sensor monitors, and I2C pins of the solution. Not all ports of the i2c_arbiter may be connected to a sensor monitor, thus giving room for sensor expansion. The connection rule between the I2C interface and the sensor monitor as described above applies. Finally, the code instantiates the spi_reg module, which contains the SPI interface to the application processor. This module has connection to the sensor monitors. All sensor monitor need to be connected to this module. The connection rule between the SPI interface and the sensor monitor as described above applies. Sensor Monitors (BMP085, LSM303, MAX44006, SHT20, and LSM330DLC Accelerometer and Gyroscope) Each sensor monitor has the same general functions and may include operations specific to the target sensor. Each module initializes the sensor, reads the sensor data periodically via 12C interface, stores the sensor read data, and sends interrupt to the application processor via SPI interface to indicate that sensor data is present. The following table summarizes the ports to/from the sensor monitors: 15 Low Power Sensor Hub Solution for Mobile Devices Table 7. Ports To/From the Sensor Monitors Signal For BMP085, LSM303, MAX44006, SHT20 For LSM330DLC accelerometer and gyroscope Direction Description fifo_data[7:0] o_fifo_data[7:0] Output Contains stored sensor read data (from the data FIFO). This is the data to be sent to the Application Processor through the SPI interface. fifo_clr_ack o_fifo_clr_ack Output Signal for the SPI interface logic to indicate that the data FIFO has been cleared successfully (Active HIGH) intr o_intr Output Signal for the SPI interface logic to indicate that sensor read data is present for Application Processor to access (Active HIGH) calibration o_calibration Output Signal for the SPI interface logic to indicate that the sensor monitor is performing calibration operation on the sensor (Active HIGH) on_ack o_on_ack Output Signal for the SPI interface logic to indicate that DEV_ON has been successfully processed (Not implemented; it is tied to logic HIGH) off_ack o_off_ack Output Signal for the SPI interface logic to indicate that DEV_OFF has been successfully processed (Not implemented; it is tied to logic HIGH) underflow o_underflow Output Signal for the SPI interface logic to indicate that FIFO underflow has occurred (Not implemented; it is tied to logic LOW) overflow o_overflow Output Signal for the SPI interface logic to indicate that FIFO overflow has occurred (Not implemented; it is tied to logic LOW) active o_active Output Signal for the SPI interface logic to indicate that the sensor monitor is performing a function (e.g. reading sensor data) (Active HIGH) full o_full Output Signal for the SPI interface logic to indicate that the data FIFO is full (Active HIGH) empty o_empty Output Signal for the SPI interface logic to indicate that the data FIFO is empty (Active HIGH) Output XCLR signal specifically for BMP085 device (Active HIGH) xclr clk i_sys_clk Input System Clock rst i_sys_rst Input System Reset fifo_rden i_fifo_rden Input Signal from SPI interface logic to read the data FIFO for the sensor data (Active HIGH) fifo_clr i_fifo_clr Input Signal from SPI interface logic to clear the data FIFO after the data has been read by SPI interface logic (Active HIGH) inte i_inte Input Signal from SPI interface logic to enable interrupt for the sensor - NOT IMPLEMENTED IN SENSOR MONITOR intr_ack i_intr_ack Input Signal from SPI interface logic to indicate that "intr" has been received and to deassert the "intr" in the sensor monitor (Active HIGH) on i_on Input Signal from SPI interface logic to control DEV_ON - NOT IMPLEMENTED IN SENSOR MONITOR off i_off Input Signal from SPI interface logic to control DEV_OFF - NOT IMPLEMENTED IN SENSOR MONITOR i2c_start o_i2c_start Output Signal to the I2C interface logic to indicate to access the sensor (Active HIGH) read_write_n o_read_write_n Output Signal to the I2C interface logic to indicate whether the accessed command is a read or a write (Read = HIGH, Write = LOW) 16 Low Power Sensor Hub Solution for Mobile Devices o_slave_address[7:0] Output Signal to the I2C interface logic to indicate the slave device (sensor) address read_byte_count[7:0] o_read_byte_count[7 :0] Output Signal to the I2C interface logic to indicate the number of bytes to read reg_address[7:0] o_reg_address[7:0] Output Signal to the I2C interface logic to indicate the slave device's (sensor) register's address fwrite_data[7:0] o_write_data[7:0] Output Contains the data to write to the slave device (sensor) through the I2C interface logic read_data[7:0] i_read_data[7:0] Input Contains the data read from the slave device (sensor) through the I2C interface logic read_data_valid i_read_data_valid Input Indicates whether the read_data is valid (Active HIGH) i2c_done i_i2c_done Input Indicates whether the I2C transaction has been completed (Active HIGH) slave_address[7:0] Note: Although the port names for LSM330DLC Accelerometer and Gyroscope are different from the other sensors, functionally the two set of port names are the same. The following is a walkthrough of a sensor monitor code, specifically for SHT20 sensor. Codes in this section are taken directly from the HDL file. Note that in most cases, the topics in each paragraph below are presented in the order in which they appear in the HDL code. The first action in the code is to define two parameters: INTR_THRESHOLD and INIT_THRESHOLD. The former parameter defines the number of clock cycles (with respect to the system clock) at which the sensor monitor will periodically read the data from the target sensor. The latter parameter defines the number of clock cycles (with respect to the system clock) at which the sensor monitor need to wait before issuing any operation so that the sensor will operate properly (i.e. initialization time). To calculate the time value, simply multiply the values of each parameter with the clock period. The counters for the above thresholds are written under the following comments: • //init_time • *This interrupt is generated for every • *Counter Note that the code under second comment above generates the interrupt to trigger read data from sensor (sensor_int). The second action is to define the slave address of the sensor to be monitored. This is performed by the following code: /* * Slave address of the sensor device */ assign slave_address = 8'h40; // Example Slave Address Setting Code It is important to use the wire name “slave_address” to define the slave address. Note that the slave address value depends on the desired sensor, and it is an 8-bit value. A state machine is then defined in the HDL. The state machine contains sensor initialization procedures. Once initialization has been completed, the state machine moves to loopback between waiting and reading sensor states. The state machine is written under the following comments: /* * State machine to control sensor configuration and data acquisition */ 17 Low Power Sensor Hub Solution for Mobile Devices The states of the state machine are then used to control various logic used to control the following wires: • i2c_start: This net signals the I2C interface to access the sensor. • read_write_n: This net signals tells the I2C interface whether the I2C operation is a read (1) or write (0) • read_byte_count: This bus determines the number of byte to be read by the I2C operation • reg_address: This bus determines the slave device’s (sensor) register to be accessed by the I2C operation • write_data: This bus contains data to be written in to the slave device (sensor) through the I2C operation The code location of the each of the above logic can be found under the comment “//<WIRE_NAME>”. Note that additional sensor specific logic for I2C transactions are implemented around this area. For example, SHT20 has “user_reg_data” and “word_count” logic. A code for interrupt to the application processor is then written. This interrupt signals the processor that sensor read data is present for reading by the processor; it is found in “intr” and it is active HIGH. The code is located under the comment “//intr”. Calibration for sensor logic is implemented. Not all sensors require calibration, and in the case of SHT20, it is not present. The code is under the comment “//calibration”. Logic to signal the SPI interface logic that the sensor is busy (e.g. performing data acquisition) is implemented under the comment “//active”. The signal name is “active”, and it is active HIGH. The remaining set of codes involves data FIFO and its control. The FIFO is 64x8-bit, and it is instantiated using the “afifo_8” module, which has the following ports: Signal Direction Description rst Input Reset wren Input Write Enable wrclk Input Write Clock wrdata[7:0] Input Write Data rden Input Read Enable rdclk Input Read Clock rddata[7:0] Output Read Data full Output Full empty Output Empty In addition to FIFO control, there is logic to process “fifo_clr”, which is a signal sent by the application processor via SPI interface to clear the data FIFO, and logic to acknowledge that FIFO has been cleared (“fifo_clr_ack”). Additional FIFO control is present, but currently, underflow and overflow logic have not been implemented. Also available to this block is the signal “i2c_done”. This signal is sent from the I2C interface to indicate whether the I2C transaction has been completed. The condition that triggers the sensor monitor to read data from the sensor is written in the following code: assign trig_acquisition = sensor_intr && empty && ~intr; This means that read is triggerred when sensor monitor indicates the periodic reads (sensor_intr), the data FIFO is empty (“empty”), and the sensor monitor is not interrupting the application processor (“~intr”). Note that logic to process DEV_ON and DEV_OFF, as well as the logic to create their acknowledges have not been implemented. 18 Low Power Sensor Hub Solution for Mobile Devices I2C Interface Module (i2c_arbiter) The I2C Interface Module is found in the i2c_arbiter file. It is used to provide connection between the sensor monitors to the sensors via I2C interface. In addition to I2C interfacing and processing I2C commands to/from sensors, this module contains the logic that polls the sensor monitors one-by-one in a round-robin fashion to see whether a sensor data read request is present. When a sensor monitor is not available, it goes to the next sensor and so on. The following table summarizes the ports to/from the I2C Interface Module: Table 8. Ports To/From I2C Interface Module Signal Direction Description clk Input System Clock rst Input System Reset scl_in Input sda_in Input I2C clock output I2C data input I2C output clock enable control I2C output data enable control scl_oe_n Output sda_oe_n Output dev#_i2c_start Input Signal from the sensor monitor to indicate to access the sensor (Active HIGH) - Connect to logic LOW if unused dev#_read_write_n Input Signal from the sensor monitor to indicate whether the accessed command is a read or a write (Read = HIGH, Write = LOW) - Connect to logic LOW if unused dev#_slave_address[7:0] Input Signal from the sensor monitor to indicate the slave device (sensor) address - Set to 0 if unused dev#_read_byte_count[7:0] Input Signal from the sensor monitor to indicate the number of bytes to read - Set to 0 if unused dev#_reg_address[7:0] Input Signal from the sensor monitor to indicate the slave device's (sensor) register's address - Set to 0 if unused dev#_write_data[7:0] Input Contains the data from sensor monitor to write to the slave device (sensor) - Set to 0 if unused dev#_read_data[7:0] Output Contains the data read from the slave device (sensor). The data is sent to sensor monitor. dev#_read_data_valid Output Indicates whether the read_data is valid. It is sent to sensor monitor. (Active HIGH) dev#_i2c_done Output Indicates whether the I2C transaction has been completed. It is sent to sensor monitor. (Active HIGH) Note: # is an integer from 0 to 3 (i.e. 4 sensors). With proper code modification, it can be expandable. The following is a walkthrough of the i2c_arbiter code. Codes in this section are taken directly from the HDL file. Note that in most cases, the topics in each paragraph below are presented in the order in which they appear in the HDL code. Notice that one of the first parameters defined is the device number (DEV0 to DEV3). The first logic implemented is the state machine that polls the sensor monitor to see whether there’s a request of I2C transaction using the “dev#_i2c_start” signal (“i2c_start”). The state machine leaves the processing state when “i2c_done” (provided by the submodule “i2_reg_ctrl”) is asserted. Note the round robin scheme of polling the sensor monitor. The next set of logic simply latches the signals received from sensor monitor for the I2C interface to process. These signals are: i2c_start, read_write_n, slave_address, read_byte_count, reg_address, and write_data. The next set of logic is used to process the data received from each sensor before they are sent to the target sensor monitor. These logic are for the following signals: read_data_valid, read_data, and i2c_done. 19 Low Power Sensor Hub Solution for Mobile Devices Finally, the i2c_arbiter calls “i2c_reg_ctrl” which contains the actual I2C controller. This module also contains the logic to control i2c_done, count number of bytes, process read or write, and receive read_data (and read_data_valid). The following table summarizes the ports to/from the i2c_reg_ctrl: Table 9. Ports To/From i2c_reg_ctrl Signal read_data[7:0] read_data_valid i2c_done Direction Description Output Contains the data read from the slave device (sensor). The data is sent to sensor monitor. Output Indicates whether the read_data is valid. It is sent to sensor monitor. (Active HIGH) Output Indicates whether the I2C transaction has been completed. It is sent to sensor monitor. (Active HIGH) scl_oe_n Output sda_oen Output I2C output clock enable control I2C output data enable control clk Input System Clock rst Input System Reset Input Signal from the sensor monitor to indicate to access the sensor (Active HIGH) Input Signal from the sensor monitor to indicate whether the accessed command is a read or a write (Read = HIGH, Write = LOW) Input Signal from the sensor monitor to indicate the slave device (sensor) address Input Signal from the sensor monitor to indicate the number of bytes to read Input Signal from the sensor monitor to indicate the slave device's (sensor) register's address Input Contains the data from sensor monitor to write to the slave device (sensor) i2c_start read_write_n slave_addr[7:0] read_byte_count[7:0] reg_address[7:0] write_data[7:0] scl_in Input sda_in Input I2C clock output I2C data input Lattice Semiconductor does not recommend that the i2c_reg_ctrl be modified. SPI Interface Module (spi_reg) The SPI Interface Module is found in the spi_reg file. It is used to provide connection between the sensor monitors to the application processor via SPI interface (spi_slave). In addition to SPI interfacing and processing SPI commands to/from application processor, this module contains an interrupt arbiter (intr_arb) module that polls interrupt (i.e. to indicate that sensor data is present) from the sensor monitors. Finally, the SPI registers are contained in this module. The following table summarizes the ports to/from the SPI Interface Module: Table 10. Ports To/From the SPI Interface Module Signal Direction Description clk Input System clock rst Input System reset SPI_SCLK Input SPI interface (connected to proc_sclk pin) SPI_SS_N Input SPI interface (connected to proc_csn pin) SPI_MOSI Input SPI interface (connected to proc_sdo pin) SPI_MISO Output SPI interface (connected to proc_sdi pin) 20 Low Power Sensor Hub Solution for Mobile Devices Signal Direction Description Output Interrupt to Application Processor. It is connected to proc_intr pin. This signals the processor that there's read data available for the processor and to begin the read operation. (Active HIGH) Output Reset the systems when interrupt has reached timeout limit - NOT USED IN SYSTEM (Active HIGH) intr soft_reset dev#_fifo_rden dev#_fifo_data[7:0] dev#_fifo_clr dev#_fifo_clr_ack dev#_inte dev#_intr Output Input Output This signal clears the sensor monitor FIFO data after data has been read by SPI interface logic (Active HIGH) Input dev#_on dev#_on_ack dev#_off dev#_off_ack dev#_underflow dev#_overflow dev#_active dev#_fifo_full dev#_fifo_empty Signal from the sensor monitor to indicate that the the FIFO data has been cleared successfully (Active HIGH) Output Enables interrupt of the sensor that corresponds to the sensor monitor - NOT IMPLEMENTED IN SENSOR MONITOR (Active HIGH) Input Signal from the sensor monitor to indicate that sensor read data is present for Application Processor to access (Active HIGH) Input Signal from the sensor monitor to indicate tha t the sensor monitor is performing calibration operation on the sensor. Not all sensors have this. (Active HIGH) Output Signal for the sensor monitor to indicate that "intr" has been received and to deassert the "intr" in the sensor monitor (Active HIGH) Output Signal for the sensor monitor to control DEV_ON - NOT IMPLEMENTED IN SENSOR MONITOR dev#_calibration dev#_intr_ack Reads sensor monitor FIFO (Active HIGH) Sensor read data (fifo_data[7:0] port) from sensor monitor. This data will be sent to Application Processor via SPI interface logic. Input Output Signal from the sensor monitor to indicate that DEV_ON has been successfully processed (Tied to logic HIGH at sensor monitor) Signal for the sensor monitor to control DEV_OFF - NOT IMPLEMENTED IN SENSOR MONITOR Input Signal from the sensor monitor to indicate that DEV_OFF has been successfully processed (Tied to logic HIGH at sensor monitor) Input Signal from the sensor monitor to indicate that FIFO underflow has occurred (Tied to logic LOW at sensor monitor) Input Signal from the sensor monitor to indicate that FIFO overflow has occurred (Tied to logic LOW at sensor monitor) Input Signal from the sensor monitor to indicate that the sensor monitor is performing a function (e.g. reading sensor data) (Active HIGH) Input Signal from the sensor monitor to indicate that the data FIFO is full (Active HIGH) Input Signal from the sensor monitor to indicate that the data FIFO is empty (Active HIGH) Note: # is an integer from 0 to 6 (i.e. 7 sensors). With proper code modification, it can be expandable. The following is a walkthrough of the spi_reg code. Codes in this section are taken directly from the HDL file. Note that in most cases, the topics in each paragraph below are presented in the order in which they appear in the HDL code. The first parameters defined in the code are: VERSION (which is for VERSION register), and INTR_TIMEOUT_COUNTER (which is used for timeout in the interrupt arbiter). The code then proceeds to process the information received from application processor (“mosi_byte”). Mosi_byte is then decoded into command information and device number. The decoded information is then processed into either Register Write Interface, Register Read Interface, FIFO Data Read Interface, or Processor Interrupt Mechanism. 21 Low Power Sensor Hub Solution for Mobile Devices At Register Write Interface: • If reg_address = 3, then it is a reset from the processor. Reset from processor is currently not implemented, but there’s a soft_reset mechanism when timeout in the interrupt arbiter occurs. • If reg_address = 4 then the CNTRL register are updated for FIFO clear (which is required after a sensor read), DEV_ON, and DEV_OFF. Note that DEV_ON and DEV_OFF logic are not implemented at the sensor monitor. • If reg_address = 2 then the interrupt enable registers are updated. Note that the interrupt enable is not implemented in the sensor monitor. • If reg_address = 5 then the STATUS registers are updated for underflow and overflow. Note that the overflow and underflow logic are not implemented in the sensor monitor. The Register Read Interface, grabs commands from the SPI interface through “miso_byte_req” to update registers (“update_register”). When “update_register” signal is true, values of CNTRL and STATUS are updated. One clock cycle later, the requested register (i.e. “reg_address”) is sent to the application processor via “miso_byte” signal. The FIFO Data Read Interface contains the logic to perform the data read from the sensor monitor. The Processor Interrupt Mechanism is used to read or write the ISR register (which is located in the interrupt arbiter. At the end of the SPI Interface Module code, the spi_slave and intr_arb are instantiated. The following table summarizes the ports to/from the interrupt arbiter module: Table 11. Ports To/From Interrupt Arbiter Module Signal Direction Description clk Input System Clock rst Input System Reset intr dev#_intr Output Interrupt to Application Processor. It is connected to proc_intr pin. This signals the processor that there's read data available for the processor and to begin the read operation. (Active HIGH) Input Signal from the sensor monitor to indicate that sensor read data is present for Application Processor to access (Active HIGH) dev#_intr_ack Output isr[7:0] Output Content of ISR register (for spi_reg) Output Determines if the interrupt state has reached timeout limit. It is used to create a soft_reset at SPI interface logic - NOT USED IN SYSTEM (Active HIGH) Input Signal from SPI interface logic to determine if Application Processor wants to read ISR register (Active HIGH) Input Signal from SPI interface logic to determine if Application Processor wants to write ISR register (Active HIGH) timeout_reset isr_read isr_write Signal for the sensor monitor to indicate that "intr" has been received and to deassert the "intr" in the sensor monitor (Active HIGH) Note: # is an integer from 0 to 6 (i.e. 7 sensors). With proper code modification, it can be expandable. Notice that the INTR_TIMEOUT_COUNTER parameter is used in this module for interrupt output. The round robin sensor monitor polling state machine is implemented first. When an interrupt from sensor monitor is received, the state machine processes the interrupt (ASSERT_INTR state). In the event that ASSERT_INTR has reached timeout limit, RESET_INTR state is reached. Counters for timeout are implemented directly after the state machine. 22 Low Power Sensor Hub Solution for Mobile Devices The interrupt arbiter also contains logic to decode which sensor issued the interrupt. It also asserts the corresponding ISR location for each sensor. Notice that only 1-bit of the ISR register is active at any time. Finally, there’s logic to send interrupt to the processor (“intr”) to indicate that sensor data is present and ready for read. During the WAIT_FOR_ACK state, the sensor that issues interrupt will get an acknowledge signal (dev#_intr_ack). This acknowledge will be sent to sensor monitor when the application processor has read the sensor data and cleared the ISR register (via “isr_write” signal). Finally, there’s reset logic for “timeout_reset” when WAIT_FOR_ACK is too long. It is currently not used in the solution. The following table summarizes the ports to/from the spi_slave module: Table 12. Ports To/From Interrupt spi_slave Module Signal Direction Description i_sys_clk Input System Clock i_sys_rst Input System Reset miso_byte[7:0] Input Data to send to Application Processor miso_byte_valid Input Determines if data to send is valid miso_byte_req mosi_byte[7:0] mosi_byte_valid cmd_byte o_miso Output Determines whether the received command is write (Active HIGH) or read (Active LOW) Output Data received from Application Processor Output Determines if received data is valid (Active HIGH) Output Determines if received data is a command byte (Active HIGH) Output SPI interface (connected to proc_sdi pin) i_mosi Input SPI interface (connected to proc_sdo pin) i_csn Input SPI interface (connected to proc_csn pin) i_sclk Input SPI interface (connected to proc_sclk pin) The spi_slave module contains the hard SPI module called “SB_SPI”. It contains logic that determines whether the command is write or read, and state machine to process the SPI master commands so as to prepare data for the backend interface. I2C Clock and Data I/O Control The following code is used to create the bi-directional I/O as required in I2C standard. assign poola_sensor_sda = (!poola_sda_oe_n)? 1'b0: 1'bZ; assign poola_sensor_scl = (!poola_scl_oe_n)? 1'b0: 1'bZ; assign poolb_sensor_sda = (!poolb_sda_oe_n)? 1'b0: 1'bZ; assign poolb_sensor_scl = (!poolb_scl_oe_n)? 1'b0: 1'bZ; Note that the assigned wire above need to be declared as “inout” at the top level module. The above code is to drive the output line. As input line, simply connect the assigned wire to the desired destination. 23 Low Power Sensor Hub Solution for Mobile Devices Design Considerations SPI Interface This section describes the SPI interface between iCE40 Sensor Hub and the Application Processor. The Application Processor obtains sensor data over SPI lines through the spi_reg module. This module expects SPI in mode “3” format, i.e. CPHA = 1 and CPOL = 1, and MSB first while transmitting a byte of data over the bus. The first byte after chip select assertion is treated as command byte, which would give the address of the register to-be-accessed. A dummy byte is sent in case of processor read operation to allow the read logic to decode the command and provide appropriate data in successive bytes. In case of write, the SPI Master would place the data bytes on the bus immediately after the command byte. The following timing diagrams show various read/write access patterns. Multi byte transaction is supported only for read operation. Figure 11. Single Byte Read Operation SCLK MOSI 1 N2 N1 N0 A2 A1 A0 0 X7 X6 X5 X4 X3 X2 X1 X0 Dummy byte Command byte MISO D7 D6 D5 D4 D3 D2 D1 D0 Data bytes CS Figure 12. Single Byte Write Operation SCLK MOSI 0 A6 A5 A4 A3 A2 A1 0 D7 D6 D5 D4 D3 Dummy byte Command byte MISO CS 24 D2 D1 D0 Low Power Sensor Hub Solution for Mobile Devices Figure 13. Multi-Byte Read Operation SCLK 1 MOSI N2 N1 N0 A2 A1 A0 0 X7 X6 X5 X4 X3 X2 X1 X0 Dummy byte Command byte B0 D7 B0 D6 B0 D5 MISO … … Bn D2 Bn D1 Bn D0 Data bytes CS Notes: 1. In the above timing diagrams, N2, N1, and N0 under the Command byte indicate the device (sensor) number to which the current register read/write is applicable. Valid range is “000” to “101” 2. A2, A1, and A0 in the Command byte indicate address of the register. See “SPI Register Descriptions” for more details. 3. When A2 = 0, N2, N1, and N0 are don’t care 4. For a read operation from processor, MSB of command byte is always 1. 5. For a write operation from processor, MSB of command byte is always 0. 6. LSB of command byte is always 0 for both read and write from processor 7. CS must not be asserted until all the bytes are read in case of multiple bytes read 8. Multiple byte write operation is not defined SPI Registers Description Each sensor has the following set of registers to configure the Sensor Hub to acquire sensor data. These registers are accessed by A2, A1, and A0 bits of the Command byte. The following table describes registers accessed by the A2, A1, and A0 bits. Table 13. Register Map for A2, A1, and A0 bits Address (A2,A1,A2 as 3-bit hex) Register Name Access Type 0x00 VERSION R 0x01 ISR R/W Interrupt status register (independent of sensor selected) 0x04 CNTRL R/W Control register (sensor specific) 0x05 STATUS R/W 0x06 DATA R Description Indicates the firmware version (independent of sensor selected) Status register (sensor specific) Acquired data register (sensor specific) Note: Sensor specific registers requires N2, N1, and N0 bits of the Command byte to access. Table 14. VERSION Register Bit Description 7 6 5 4 3 Firmware Version 25 2 1 0 Low Power Sensor Hub Solution for Mobile Devices Table 15. ISR Register Bit Description 7 6 5 4 3 2 1 0 0 0 INT5 INT4 INT3 INT2 INT1 INT0 INT0 – interrupt by sensor 0. This will be set by the sensor and cleared by the processor INT1 – interrupt by sensor 1. This will be set by the sensor and cleared by the processor INT2 – interrupt by sensor 2. This will be set by the sensor and cleared by the processor INT3 – interrupt by sensor 3. This will be set by the sensor and cleared by the processor INT4 – interrupt by sensor 4. This will be set by the sensor and cleared by the processor INT5 – interrupt by sensor 5. This will be set by the sensor and cleared by the processor Interrupt to the processor will be OR of INT0, INT1, INT2, INT3, INT4 and INT5. Note: Interrupts are always enabled. Table 16. CNTRL Register Bit Description 7 6 5 4 3 2 1 0 0 0 0 0 0 FIFO_CLR DEV_ON DEV_OFF FIFO_CLR – Writing '1' to this will clear the FIFO contents. DEV_ON – Writing '1' to this will enable the device if it is turned off DEV_OFF – Writing '1' to this will force the device into power down mode if it is active. Note: 1. All the bits of the CNTRL are set by the processor and will be reset by the sensor hub. 2. DEV_ON and DEV_OFF logic is currently not implemented. Table 17. STATUS Register Bit Description 7 6 5 4 3 0 0 EMPTY FULL CALIB 2 1 UNDERFLOW OVERFLOW 0 ACTIVE ACTIVE (R) – '1' indicates the device is operational. OVERFLOW – '1' indicates the processor failed to read acquired data before being overwritten by the next sample (this is a sticky bit can be cleared by the processor) UNDERFLOW – '1' indicates the processor has issued read command before the data acquisition is complete (this is a sticky bit can be cleared by the processor) CALIB (R) – '1' indicates calibration data is present in the FIFO FULL(R) – '1' indicates the data FIFO is full EMPTY(R) – '1' indicates the data FIFO is empty Note: UNDERFLOW and OVERFLOW logic is currently not implemented. 26 Low Power Sensor Hub Solution for Mobile Devices DATA Register Bit Description 7 6 5 4 3 2 1 0 Acquired Sensor Data [7:0] Data reading is multi-byte read operation (with single address). While reading the acquired sensor data it is expected that the application processor is aware of the numbers bytes to be read for a particular device. Complete SPI Registers Location The table below lists the first byte to be transmitted from SPI master (AP) to iCE on MOSI Line. This is combination of register address listed in SPI Registers Description section and also the control signal values listed after the SPI Timing diagram (under Notes). First Byte for SPI Read (1,N2,N1,N0,A2,A1,A0,0 as 8-bit hex) First Byte for SPI Write (0,N2,N1,N0,A2,A1,A0,0 as 8-bit hex) 0x80 - 0x82 0x02 ISR (device independent) 0x88 0x08 BMP085 pressure sensor control register Register Description Version (device independent) 0x98 0x18 LSM303DLHC magnetometer control register 0xA8 0x28 LSM330DLC accelerometer control register 0xB8 0x38 MAX 44006 Ambient Light Sensor control register 0xC8 0x48 SHT20 Humidity sensor control register 0xD8 0x58 LSM330DLC gyroscope control register 0x8A 0x0A BMP085 pressure sensor status register 0x9A 0x1A LSM303DLHC magnetometer status register 0xAA 0x2A LSM330DLC accelerometer status register 0xBA 0x3A MAX 44006 Ambient Light Sensor status register 0xCA 0x4A SHT20 Humidity sensor status register 0xDA 0x5A LSM330DLC gyroscope status register 0x8C - BMP085 pressure sensor data register 0x9C - LSM303DLHC magnetometer data register 0xAC - LSM330DLC accelerometer data register 0xBC - MAX 44006 Ambient Light Sensor data register 0xCC - SHT20 Humidity sensor data register 0xDC - LSM330DLC gyroscope data register Example: Sensor Hub generates interrupt when LSM330DLC accelerometer data is available in that sensor’s FIFO. When sensor data is available, Sensor Hub interrupts the application processor by generating a high on “proc_intr” pin. Processor must follow the below mentioned steps to read accelerometer data from iCE. 1. When “proc_intr” goes high, read the ISR register (0x82) by writing 0x82 as first byte on proc_sdo (MOSI) line. 2. Based on the ISR register value (3rd byte on MISO line), read the sensor data from corresponding device. For LSM330DLC accelerometer, the ISR value is 0x04. 3. To read the sensor data, write the corresponding data register address as first byte on proc_sdo (MOSI) line. To read accelerometer data, the data register address is 0xAC. 4. After reading 6 bytes of sensor data, write the value “0x00” to ISR register (0x02). 27 Low Power Sensor Hub Solution for Mobile Devices Pseudo Code Example for Application Processor The following code illustrates how an Application Processor could process the interrupt received from the sensor hub to obtain the sensor data. while(interrupt received) { Read ISR (0x01) Read FIFOx; FIFOx decoded based on ISR bits and predefined data length for that FIFO. Example: For Accelerometer, ISR bit 2 is checked and number of bytes to be read is 6. Reset FIFOx content. Reset ISR to indicate end of processing. Design Customization Considerations Since this is an FPGA based solution, you can customize this solution by changing the source code of the Sensor Hub Solution or add additional functions to this solution. Note that when customization is performed, the “Performance Characteristics” values might change. Adding Sensors The Block Description section describes the Sensor Monitor, I2C Interface Module, and SPI Interface module in detail. When adding sensors, you must implement the operations described in those sections. The following is a list of items to do and consider when adding a sensor. Sensor Monitor • Follow the port naming convention of the sensor monitor module • Set the INIT_THRESHOLD • Set the INTR_THRESHOLD • Create counters for the threshold values • Define slave_address • Create a state machine for sensor initialization, periodic sensor read, and wait between reads • Create logic for the following I2C interface signals: – I2c_start – Read_write_n – Read_byte_count – Reg_address – Write_data • Create logic for “intr” signal for the SPI interface • Create calibration logic if required by sensor • Create logic fo “active” signal for the SPI interface • Add a data FIFO with appropriate width and depth • Create logic to process “fifo_clr” and to create “fifo_clr_ack” • Create sensor read trigger logic • Create additional sensor specific logic as needed • Use “i2c_done” signal to let sensor monitor know when I2C transaction is complete 28 Low Power Sensor Hub Solution for Mobile Devices I2C Interface Module • Add sensor to the polling state machine • Create registers for the following signals from the sensor monitor: – I2c_start – Read_write_n – Read_byte_count – Reg_address – Write_data • Create connection to the sensor monitor for the following signals: – Read_data_valid – Read_data – I2c_done • Make sure “i2c_reg_ctrl” module still has its connection SPI Interface Module • Assign a unique 3-bit value that can be used by “device_no” bus for the sensor • Change VERSION value if needed • Change INTR_TIMEOUT counter if needed • Add sensor to the following logic section: – Register Write Interface – Register Read Interfact – FIFO Data Read • Add device to the “intr_arb” module – Add device to the interrupt monitor poll – Add device to the ISR assertion logic Removing Sensors The following is a list of items to do and consider when removing a sensor. Sensor Monitor Remove the unwanted sensor codes. I2C Interface Module • Remove sensor to the polling state machine • Remove registers for the following signals from the sensor monitor: – I2c_start – Read_write_n – Read_byte_count – Reg_address – Write_data • Disconnection the following signals to the sensor monitor: – Read_data_valid – Read_data – I2c_done • Make sure “i2c_reg_ctrl” module still has valid connection 29 Low Power Sensor Hub Solution for Mobile Devices SPI Interface Module • De-assign a unique 3-bit value that can be used by “device_no” bus for the sensor • Change VERSION value if needed • Change INTR_TIMEOUT counter if needed • Remove the sensor from the following logic section: – Register Write Interface – Register Read Interfact – FIFO Data Read • Remove device from the “intr_arb” module – Remove device from the interrupt monitor poll – Remove device from the ISR assertion logic Programming Solutions Due to the FPGA nature of this solution, the solution requires FPGA programming. The programming solutions include, but not limited to programming via FTDI chip, programming via SPI Flash, or programming via application processor. For more information on programming solutions, please refer to iCE40 Configuration Solutions Guide. Power Supplies Please refer to the FPGA board design guide. Layout Guidelines Please refer to the FPGA board design guide. Heatsink Selection Please refer to the FPGA board design guide. Software Requirements For standalone solution, Diamond Programmer and "sensor_hub_bitmap.hex” file. The following steps are required to program the device: 1. Create a new project 2. Set to SPI Programming For the fully customizable solution, iCEcube2, Diamond Programmer, and Sensor Hub HDL source files are required. For more information on iCEcube2, please refer to the iCEcube2 Design Software web page. Resource Utilization Table 18. Resource Utilization Family iCE40LM 1 iCE40 Ultra2 LUTs Registers PLBs BRAMs I/Os I2Cs SPIs 2468 1532 383 6 11 2 1 2468 1539 385 6 11 2 1 1. Performance and utilization characteristics are generated using iCE40LM4K-SWG25T with iCEcube2 design software. 2. Performance and utilization characteristics are generated using iCE5LP4K-SWG36 with iCEcube2 design software. 30 Low Power Sensor Hub Solution for Mobile Devices Typical Application Circuits Figure 14. Sensor Hub with Pre-programmed SPI Flash - iCE40LM VCCIOBV2 C8 C7 10 nF 0.1 uF VCCIOBV1 C9 1 uF R3 2K2 I2C Slave Ports of SHT20 LSM303DLHC C2 C1 10 nF 0.1 uF iCE40 Sensor Hub Solution R4 2K2 E2 VCCIOVB2 VCCIOVB1 A2 R5 2K2 R1 2K2 R2 2K2 E5 poolb_sensor_scl poola_sensor_scl A1 D5 poolb_sensor_sda poola_sensor_sda B1 System Clock Source CRESET B3 SPI Flash 12C Slave Ports of BMP085 MAX44006 LSM330DLC Switch E3 clk D2 C1 D1 E1 proc_sdi proc_intr proc_sdo proc_sclk proc_csn ice_SO Ice_SI flsh_sclk flsh_cs C2 B5 A5 A4 A3 C3 1 uF Application Processor’s SPI Ports VCC 3.3 V sensor0_xclr C4 VCC B4 GND B2 GND D4 R6 2K2 C5 C4 10 nF 0.1 uF C6 1 uF LED C3 CDONE Master Clear for BMP085 Note: Diagram of Sensor Hub with Pre-programmed SPI Flash for iCE40 Ultra will be provided when available. 31 Low Power Sensor Hub Solution for Mobile Devices Figure 15. Sensor Hub with Direct Programming through FTDI - iCE40LM VCCIOBV2 C7 10nF C8 0.1uF VCCIOBV1 C9 1uF R3 2K2 I2C Slave Ports of SHT20 LSM303DLHC C1 10nF iCE40 Sensor Hub Solution R4 2K2 E5 poolb_sensor_scl D5 poolb_sensor_sda System Clock Source FTDI FT2232H VCCIOVB1 A2 E2 VCCIOVB2 R1 2K2 12C Slave Ports of BMP085 MAX44006 LSM330DLC E3 clk proc_sdi proc_intr proc_sdo proc_sclk proc_csn C2 B5 A5 A4 A3 C3 1uF R2 2K2 poola_sensor_scl A1 poola_sensor_sda B1 D2 ice_SO C1 Ice_SI D1 flsh_sclk E1 flsh_cs B3 CRESET C3 CDONE C2 0.1uF Application Processor’s SPI Ports VCC sensor0_xclr C4 VCC B4 GND B2 GND D4 Master Clear for BMP085 C4 10nF C5 0.1uF C6 1uF Note: Diagram of Sensor Hub with Direct Programming through FTDI for iCE40 Ultra will be provided when available. 32 Low Power Sensor Hub Solution for Mobile Devices Figure 16. Sensor Hub with Programming through Application Processor - iCE40LM VCCIOBV2 C7 10nF C8 0.1uF VCCIOBV1 C9 1uF C1 10nF C2 0.1uF C3 1uF iCE40 Sensor Hub Solution R3 2K2 I2C Slave Ports of SHT20 LSM303DLHC R4 2K2 VCCIOVB1 A2 E2 VCCIOVB2 E5 poolb_sensor_scl D5 poolb_sensor_sda R2 2K2 12C Slave Ports of BMP085 MAX44006 LSM330DLC Switch E3 clk D2 C1 D1 E1 Application Processor proc_sdi proc_intr proc_sdo proc_sclk proc_csn ice_SO Ice_SI flsh_sclk flsh_cs C2 B5 A5 A4 A3 Application Processor’s SPI Ports VCC 3.3V sensor0_xclr C4 VCC B4 GND B2 GND D4 R6 2K2 C3 CDONE Master Clear for BMP085 C4 10nF C5 0.1uF C6 1uF LED SPI Flash (Data) R1 2K2 poola_sensor_scl A1 poola_sensor_sda B1 CRESET B3 System Clock Source R5 2K2 Note: Diagram of Sensor Hub with Programming through Application Processor for iCE40 Ultra will be provided when available. 33 Low Power Sensor Hub Solution for Mobile Devices Package Diagram Figure 17. iCE40LM Package Diagram Note: iCE40 Ultra Package Diagram will be provided when available. 34 Low Power Sensor Hub Solution for Mobile Devices 35 Low Power Sensor Hub Solution for Mobile Devices Disclosures The iCE40 Sensor Hub Solution is an FPGA based solution which requires IP to be downloaded to the device for this solution. This solution includes the Diamond Programmer for IP download and iCEcube2 design software for customization. The design files and ready-for-download .hex file are also included. Finally, SPI Flash might be needed depending on whether one time or multi programmable scheme is used. Ordering Information Solution Name Description Package BOM iCE40 Sensor Hub Solution (Commercial Grade) Commercial Grade Solution 25-pin WLCS at 1.71mm x 1.71mm iCE40LM4K-SWG25TR Device, iCEcube2 Design Software, Diamond Programmer, Sensor Hub Design Files, sensor_hub_bitmap.hex iCE40 Sensor Hub Solution (Industrial Grade) Industrial Grade Solution 25-pin WLCS at 1.71mm x 1.71mm iCE40LM4K-SWG25TR Device, iCEcube2 Design Software, Diamond Programmer, Sensor Hub Design Files, sensor_hub_bitmap.hex References • SCHEMATICS_LP3.5K_SENSOR_FUSION_DEMO.pdf • Smart Sensor Hub design document for HX8K platform Technical Support Assistance e-mail: [email protected] Internet: www.latticesemi.com Revision History Date Version October 2013 01.0 01.1 Change Summary Initial release. Updated BMP085 Sensor Monitor section. Updated LSM303DLHC Sensor Monitor section. Updated LSM330DLC Accelerator Sensor Monitor section. Corrected typographical error in Ports To/From the Sensor Monitors table. Changed Table 6 title to Ports To/From i2c_reg_ctrl. Changed Table 9 title to Ports To/From Interrupt spi_slave Module. June 2014 1.2 Changed document title to iCE40 Low Power Sensor Hub Solution for Mobile Devices Added support for iCE40 Ultra. 36