Silicon Labs Solutions for Active Infrared Proximity Sensing In this training module we are going to take a look at active infrared proximity detection and how Silicon Labs solves important design challenges when integrating this technology into end applications. 1 Agenda Proximity sensing basic concepts Why use proximity sensing Background information Design considerations The Si1120 and its operation Development kits Summary 2 We are going to first review some basic concepts associated with active proximity sensing and the system level advantages of using this technology. Next we will cover a brief overview of the theory behind the measurements and how these are applied to real world designs. Finally, we will take a look at the Silicon Labs proximity sensors and their operation including the MCU requirements to interface to these types of sensors and the tools available to ease the development process. 2 Active Optical Proximity Detection Basic Concept Emitter generates energy (infrared light) An object in proximity reflects the energy An optical sensor detects the energy Logic or a controller makes a decision regarding the proximity or movement of the object Ambient Light Sources Object in proximity Transmit window Receive window Emitter LED Signal Processing Detectors Visible Light Photodiode IR Photodiode Silicon Labs Proximity/Ambient Light Sensor 3 Silicon Labs provides solutions for active proximity sensing. A proximity sensing system is comprised of two elements: the IR emitter and the IR detector. The emitter generates the energy using an IR LED and control circuitry. The IR energy is transmitted through the mechanical assembly and is reflected back to the measurement system by an object in proximity. Within the mechanical assembly there is also an IR detector or photodiode. The photodiode generates a current output proportional to the incident light when a bias voltage is applied. The intensity of the light received by the photodiode is then communicated to an MCU such as the C8051 family from Silicon Labs. The MCU can then process the data and generate a measurement of the distance of the reflective object. There are several additional aspects that may be associated with proximity detection. Some Silicon Labs proximity sensors utilize a second photodiode to compensate for ambient light sources (Si1120). These diodes compensate for additional IR energy present in the environment due to light sources not associated with the measurement system. Examples of such light sources are incandescent and fluorescent lighting. Adding the second photodiode enhances the IR proximity detection by providing a method to compensate for the additional energy present. 3 Why Use Proximity Sensing? Reduced power consumption Consumers expect Longer battery life from portable units Lower power from wall powered devices when not in use Devices can go into low power modes when reflective objects are in proximity (cell phone held up to the ear so the unit can turn off the backlight and display) Devices can go into low power modes when not in use to conserve power and conform to green initiatives Value added features to enhance products New user interface features Motion detection Touchless gestures Devices can change operating state based on proximity detection Example: context changes when a person walks up to a terminal 4 Power consumption is a growing concern for all electronic devices whether it is battery powered or wall or aux powered devices (like Power over Ethernet (PoE)). IR proximity sensing is becoming popular in applications as the sensing mechanism used reduce the overall power consumption by enabling certain subsystem to be shut down when not in use. The Electromagnetic Spectrum Visible spectrum = 380 to 760 nm Near infrared = 750 to 2,500 nm Typical infrared LEDs: 850, 880, 940, & 950 nm Emitter wavelength based on silicon sensitivity in the electromagnetic spectrum 850 nm (Silicon Labs solutions) or 940 nm are common for the IR emitter Silicon response to light 5 The electromagnetic spectrum is a continuum of all electromagnetic waves arranged according to frequency and wavelength. The sun, earth, and other bodies radiate electromagnetic energy of varying wavelengths. The electromagnetic spectrum is more familiar to you than you might think. The microwave you use to heat your food and the cell phones you use emit and receive energy that is part of the Electromagnetic Spectrum. The light that our eyes can see is also part of the electromagnetic spectrum. This visible part of the electromagnetic spectrum consists of the colors that we see in a rainbow - from reds and oranges, through blues and purples. Infrared light lies between the visible and microwave portions of the electromagnetic spectrum. Infrared light has a range of wavelengths, just like visible light has wavelengths that range from red light to violet. "Near infrared" light is closest in wavelength to visible light and is what is used as the energy source in proximity sensing applications. Ambient Light (Background Lighting) Ambient light sensors measure light levels in the visible spectrum (photopic response) between 380 and 760nm Different light sources provide different spectral outputs Fluorescent: high visible spectrum, ultra-low infrared, & 100/120Hz flicker Incandescent: high visible, high infrared Sunlight: ultra-high visible, medium infrared (relative) Understanding the background light source can improve the infrared measurement Ambient lighting levels in an environment include both visible and infrared levels – these levels being interferers For reflective proximity the ambient light sources are subtracted from the IR measurement as a way to enhance the IR results ALS benefits Display backlight power reduction Improved user visual experience 6 Ambient light is all of the light (visible and infrared) in the environment that is not generated by the measurement system. Ambient light is generated by many sources including incandescent and fluorescent lighting, LED lighting and sunlight among others. Ambient light can be important for accurate measurements because each different source generates varying levels of infrared energy. It can reduce the overall dynamic range of the system and if not compensated will cause measurement errors in the final results. Relating Illuminance to Real-world Ambient Light Light meter 7 Illuminance is the total luminous flux (the flux density corrected for human vision) in a given area. The table above is provided in order to get an idea of how ambient light relates to real world environments by comparing the illuminance values for each. It can be seen from this table that proximity sensing applications are required to compensate for a wide range of ambient light conditions. And as mentioned, these values represent the visible spectrum. There are IR components that are part of the entire radiant flux in the environment that can interfere with the proximity measurements. Design Considerations (1 of 3) Proximity distance to be measured Light intensity is inversely proportional to the distance Distance is doubled due to the return trip from the reflective object Light must be able to reach the detector Determines IR emitter optical output characteristics (thus the current requirements as well) Filters can increase the overall range Reflective object characteristics Size and shape of object Surface of object Specular/scatter reflections Angle of reflection Absorption 8 Designers of devices that implement IR proximity detection need to be concerned with several items. First and foremost the detection range must be determined. In order to detect the reflected energy the object must be within range of the IR energy source. When determining the proximity range the IR energy output must be set in order to accommodate the decrease in light which is proportional to the inverse square of the distance. Taking into account that the light must travel in the transmit and receive path, the energy that the detector sees is inversely proportional to the fourth power of the distance from the emitter. The reflective object characteristics are also important factors to be considered and ultimately the goal is to maximize the amount of reflected energy received by the detector. The size and shape of the object determines how much of the emitter’s beam width is reflected and the shape determines the angle of reflection. In addition, surfaces have small irregularities that may reflect or scatter the IR energy. For example, a polished surface reflects better because the amount of irregularities on the surface is small compared to a surface that may be a rougher. In either case there are typically two types of reflections, specular and scatter. The specular reflection is the reflection that provides the highest intensity of the emitted energy due to the angle of incidence of the object. Another consideration is the absorption of the object. In many applications the human hand is the reflective object which can absorb some of the IR energy. Design Considerations (2 of 3) Environment Reflected light from other objects (multipath) IR emitter Electrical to optical conversion efficiency Emission angle Narrow angle provides greater measurement distance Wavelength Age Ambient Light Fluorescent Lamps (ballast flicker) Sunlight (large background light level, high levels of IR energy) Incandescent Lamps (high levels of IR energy) Optical Isolation between the emitter and the detector 9 When the IR energy is emitted from the source it can bounce off other objects and make its way back into the detector. This phenomena is called multipath and can be added to the detected signal. The IR emitter is an important consideration in proximity designs. There are several parameters associated with the IR emitter that need to be evaluated for these systems. Many proximity measurement systems are found in battery powered applications so power consumption is important. Choosing an IR emitter (like an LED) with a high electrical to optical efficiency would provide better battery performance by allowing lower currents to be used while hitting the range requirements of the application. The emission angle of the LED is also important and also contributes to the range of the system, but also the size of the target and the area around the device that can be monitored. All emitters have a certain range of wavelengths that they output. The peak output should correspond to the peak sensitivity of the detector. By selecting components that have the peak wavelengths the same provides the greatest efficiency of the system. For example, having an emitter with a peak output of 880nm would not be as good a choice as having an emitter that has a peak output of 850nm when using the Silicon Labs Si1120 that has its highest sensitivity at 850nm. In addition to the emitter’s peak wavelength the effects of aging of the emitter should also be considered as intensity and other parameters may changed over time. Ambient light will be covered in another section so we won’t cover it right now other than to say it can affect the overall measurement since background light sources contain wavelengths in the IR spectrum. The mechanical design of the complete assembly plays an important role in proximity sensing applications. The more isolation that can be provided by the mechanical assembly the more dynamic range that will be available to the sensor. For example, if we completely isolate the emitter and the receiver then all of the signal received is from the reflected object and there is minimal offset in the reading. If we allow too much light to enter the cavity where the detector is then the emitter energy can be received without be reflected by any objects. This will increase the measurement offset and reduce the dynamic range available for the reflected energy. Design Considerations (3 of 3) Single port Internal reflection over 100X larger than signal 100% reflectance variation prevents dumb threshold setting OK for short range (< 2.4 cm) motion triggered application Dual port has maximum sensitivity Allows for > 1 meter range either with lenses or by integrating pulses As long as fixed coupling is less than reflectance tolerates 100% variance in reflection May be “portless” by using existing products holes (but must have high optical isolation) As distance increases the dual port appears as a single port due to background IR Object in proximity Not recommended Transparent window Detector 10 Transmit LED internal reflection Object in proximity Receive window Detector Transmit window Transmit LED Optical block In the last section we discussed elements of the mechanical assembly for IR proximity measurements. One of the key issues to consider when implementing the mechanical design is to reduce the optical coupling. In systems where there is a lot of reflection or optical coupling from everything else other than the object it is difficult to detect the actual signal of interest. These other reflections create very large offsets much bigger than the objects reflection. Here we see two different topologies: single port and dual port. The single port has a single transparent window for both the transmit and receive energy. From the purple lines you can tell that the single port has high internal reflectance which will use up much of the dynamic range of the sensor. For this reason single port designs are not recommended. The single port design may be useful for short range, simple detection where the object’s reflection provides enough signal to be resolved. However, the sensing system requires higher resolution since the signal of interest is small compared to the unwanted internal reflections. The dual port design has separate windows for the transmit and receive energy and provides a barrier between the two paths thus reducing the optical reflections. For greater detection range, we can either use lenses or integrating pulses. Lenses can either be done on the transmitter or the receiver. The easiest option is to use an LED with an integrated lens. Integrating pulses is also called “averaging.” This can remove the sample-tosample variation to lower the noise floor, and therefore, allow better range. Portless designs use no enclosure and allow the light to pass unobstructed. In portless designs there should still be high optical isolation to provide for increased dynamic range. In any of the cases outlined, the signal detection capability is dependent on the dynamic range of the system: the background IR vs. the reflected energy from the object. In the single port case the dynamic range is consumed by the internally reflected energy. In the dual port case the distance and the ambient IR energy eventually take up the dynamic range. As the object moves farther away from the sensor the lower the reflected energy and the more influence the ambient IR has on the measurement. Proximity/ALS Product Snapshot Si1102-A-GM Proximity Detector Si1120-A-GM PWM Proximity/ALS Sensor Logic 0/1 output PWM output Standalone detector (no host required) Designed to work with host processor No ambient light sensor Integrated ambient light sensor Single LED driver Single LED driver Dedicated digital logic Dedicated digital logic 3x3 ODFN 3x3 ODFN Samples and EVB available Samples and EVB available Market Segment / Application Module manufacturers The module manufacturers pre-package sensors for the markets below Consumer products Industrial 11 White goods such as refrigerators, microwaves, washers, dryers, and dishwashers; office equipment such as phones, switchboards, printers, copiers, scanners; consumer products such as set-top boxes and health products Instrumentation panels, touch panels, automatic plumbing valves, paper dispensers, fluid dispensers, machine safety, cash machines, security systems, handheld scanners and computers, ticketing and voting machines, in-flight entertainment, casino/gaming machines and industrial controllers There are two devices currently for IR proximity detection: the Si1102 and the Si1120. The features for each are listed in the table. The key difference is that the Si1120 provides ambient light detection and provides a PWM output directly proportional to the reflected energy. The Si1102 does not include an ALS photodiode and is used as a standalone device to provide simple binary logic detection without ambient light detection. The Si1120 ALS photodiode helps identify the background ambient light characteristics for an improved infrared result. Each of these sensors can be used in a wide variety of applications as shown in the figure. 11 Si1120—PWM Proximity/ALS Sensor Low power, high performance proximity and ALS sensor PWM output High proximity detection range Up to 50 cm with single pulse Low power Typical 10uA average current consumption 3x3 ODFN Integrated differential photodiode, signal processor and LED driver Low noise ambient cancelling for maximum sensitivity Seven precision optical measurement modes 3 proximity 3 DC ambient 1 calibration High EMI immunity without shielded packaging Operating temperature: -40 to 85 ºC 12 Here we see the key features of the Si1120 which integrates all of the analog features required to implement robust IR proximity detection as well as ambient light sensing in a single package. The Si1120 provides a single pulse PWM output that is easily measured with an MCU and provides low power operation. We will see in upcoming slides how to configure the Si1120 and take proximity measurements with a sample application. 12 Benefits of the Implementation Single — pulse operation Reduces power consumption Increases battery life Fast detection response Reduces susceptibility to flicker noise Low-frequency noise reduction DC ambient auto-calibrated before each measurement Programmable periodic wake-up with power-down state between strobes Multi-burst integration [to compensate for flicker] Longer detection response Higher power consumption Shorter battery life Competitor IAVG≈ 50mA 25 us (up to 2ms during high reflectivity) IAVG≈ 0.5mA * Average current estimated with 10ms scan rates including LED current (Si1120) 13 One important aspect of many systems that implement IR proximity is overall power consumption. Each component in the system contributes to the overall power budget and the Si1120 is no exception. However, when discussing active proximity measurements the infrared LED is the primary consumer of energy. The Si1120 provides lower power operation by enabling single pulse operation thus limiting the amount of LED “on” time. This is contrasted to traditional approaches where multiple cycles are required to provide an integration of the light over a specified time period, thus consuming more current. In upcoming slides we will see how the Si1120 operates and highlight the PWM output as a representation of the light intensity. To summarize here, the pulse width increases with increased light intensity which provides a direct relationship to the current consumption. As light intensity increases so does the power consumption due to the wider pulse width, however, the average power consumption is reduced. Using the Si1120 Let’s take a look at how to use the Silicon Labs Si1120. 14 Si1120 Block Diagram Signal processing IR Photodiode ALS Photodiode LED driver 15 Here is a block diagram of the Si1120. The analog front end consists of two photodiodes that measure the incoming electromagnetic energy. One of the detectors is used to measure the IR energy and the other is used to measure the energy in the visible spectrum. The complete analog signal chain is integrated and provides the low going PRX output which is a pulse proportional to the light intensity. The TXO output is a constant current sink that can be set to 50mA or 400mA (with no current limiting) in order to directly drive an IR LED for the emitter. STX, SC and MD are control inputs to set the operating mode and STX also starts the conversion process. Si1120 Sample Schematic (Single LED) PWM output on PRX PRX output directly proportional to measured light Ends the measurement cycle by turning OFF the LED TXO sinks a constant current Programmable to 50 or 400 mA Can connect directly to the LED cathode Can connect to the source of a FET driver STX starts the measurement cycle Enables the current source to turn ON the LED Enables the PRX output 16 During device operation, the PRX, STX and TXO pins control the operation of the proximity detection system. The pulse width modulated PRX signal is output by the Si1120 and is a measure of the reflected IR energy. The TXO signal is a constant current sink for the IR LED which generates the energy that will be reflected off of the object in proximity. The STX signal is an input to the Si1120 and is used to start the measurement. As will be seen on a later slide the STX signal can also be used to abort the measurement as well. Shown in the figure is a sample schematic using a single IR LED driven directly from the Si1120. There are no external gates required to drive the LED as the Si1120 can sink the constant current required. The STX and PRX signal can be connected directly to the MCU for a glue-less interface for proximity measurements. Si1120 Measurement Modes Shutdown mode Three ambient modes 0.1 uA typical shutdown current Three proximity modes PRX400 PRX50 IR LED current = 400 mA IR LED current = 50 mA High internal reflectance Used for single-port optical window to compensate for high reflectance of the cover Measures both visible and infrared spectra Peak response at 530 nm: closest to human eye peak response (550 nm) 3 kLux maximum (assuming blackbody radiators) VIRH Measures both visible and infrared spectra Peak response at 830 nm 500 Lux maximum (assuming black-body radiators) VAMB IR LED current = 50 mA PRX50H VIRL Measures both visible and infrared spectra Peak response at 830 nm 100 kLux maximum (assuming blackbody radiators) Offset calibration mode (OFC) IR LED not enabled Measure ambient IR 17 The Si1120 has seven operating modes that range from measuring the ambient light to the reflected IR as well as determining the output LED drive current from the TXO pin. PRX400 is best for range, PRX50 is best for power saving (PRX50H is not generally used). OFC mode is typically used to figure out the minimum PRX pulse width without an LED which is representative of the PRX pulse width during dark ambient conditions since the LED isn’t turned on. OFC is used more rarely than either PRX400 or PRX50 as it is more like a calibration step and probably is done once every time the system boots and the value is stored in memory. OFC is used to represent what the PRX50 or PRX400 would have reported if there was no reflected IR energy. The PRX400 minus the OFC value, for example, is a more accurate representation of the reflectance. In applications implementing ambient light sensing, VAMB, VIRL and VIRH will all be used equally. However, not all applications will require ambient light sensing. Si1120 Operation: Setting Modes MCU controls setting the mode of the Si1120 SC, MD and STX should be GPIO during this phase MD (latch) and STX (latch) are sampled when SC is driven low The first two bits of the three bit mode setting is determined from these latched values MD set to final bit of the mode setting Changing modes typically requires putting the device in the low power mode first (SC driven high) Exception if mode can be selected by just changing MD (static) SC transitions low to latch the state of MD and STX SC MD Don’t care STX Don’t care MD (latch) STX (latch) 1 MD (static) 0 0 Once latched, drive MD to the state to complete the mode setting While SC high…set the MD and STX bits to the initial mode state PRX50 Mode Example: 010 18 As was mentioned previously, the MCU connected to the Si1120 is responsible for setting the operating mode of the device by generating three control bits. Setting the mode is controlled by the SC, MD and STX pins and is a two step process since the MD pin is used twice. The SC pin is the shutdown pin and when high (logic 1) puts the Si1120 in a low power mode. To set the operating mode, the MCU starts by putting the Si1120 into the low power mode. Next, the MCU has to set the value of the first two configuration bits by setting the value using the MD and STX inputs. Once these bits are set the SC pin is driven low latching the first two control bits (MD latch and STX latch in the figure) and bringing the Si1120 out of the low power mode. To complete the configuration the MCU then drives the MD pin to either a logic 1 or 0 depending on the desired configuration (MD static in the figure). The MCU then holds this pin static for the time the Si1120 is to remain in the set mode. Since the MD static value is not latched it can be used to change the mode of the Si1120 dynamically. For example, in the figure we see some values for the PRX50 mode which uses MD (static) as a logic zero. The MCU can change the value of the GPIO used for MD and make it high at any time. This changes the Si1120 mode to PRX50H without having to go into the low power mode first. Si1120 Operation: Starting a Measurement STX can be set by the MCU as a periodic signal or can be toggled via firmware TXO line is driven low by the Si1120 to enable current to flow through the IR LED and IR energy is emitted Once current flows the PRX signal is driven low by the Si1120 to represent the amount of light reflected back and received by the photodiode STX can be driven low prior to the Si1120 completing the measurement Reduces current consumption if accurate measurements are not required Good for simple detection applications Measure ambient IR IR LED Turns ON Abort a measurement IR LED Turns OFF STX TXO PRX Photodiode starts measuring reflected energy (minus ambient IR) 4 us to 2 ms 19 Now that the mode is set we can start using the Si1120 to take IR proximity measurements. The STX pin is now used as a source to start the measurement and can be controlled by the MCU hardware (by using timers) or by firmware. When the STX line is driven high the measurement cycle begins. At the time the STX goes high, the Si1120 takes the ambient IR reading and stores this for later. After the ambient measurement the TXO signal is driven low which then starts the constant current flow through the LED. During this time when TXO is asserted, the Si1120 actually measures a combination of ambient IR plus the reflected IR. To get the reflectance, the Si1120 subtracts the ambient IR measured at the beginning of the measurement cycle from the overall measurement when the LED is emitting the IR energy. If the accuracy of the measurement is not required, for example when doing a simple threshold detection, then a measurement cycle can be aborted by bringing the STX line low again thus raising PRX and TXO. This can reduce overall power consumption by minimizing the pulse width outputs. Si1120 Operation: Capturing the Photodiode Output The PRX low time is directly proportional to the amount of light received by the diode Use the Programmable Counter Array (PCA) to measure the low time Set to rising and falling edge captures Input capture is used to latch the value of the counter from PRX Capture Events Counter = 0045 0048 0047 0046 0040 0044 0043 0042 0041 Rising edge ISR: Store final count value PRX 0044 0048 0040 Capture/Compare register Falling edge ISR: Store initial count value PRX low time = Final count – initial count 20 At this point the MCU has controlled the I/O to the Si1120 in order to set the modes and start a measurement and as a result the PRX signal is driven low to represent the IR energy detected. The amount of time the PRX signal is low is a representation of the amount of energy that is reflected. The longer the pulse the more reflected energy has been detected, or in other words, the closer an object is to the sensor. The MCU used to control the I/O is also responsible for measuring the PRX pulse width. In the Silicon Labs C8051F microcontrollers the PCA timing unit can be used. These modules are capable of performing rising and falling edge triggered captures of the PRX signal. When the PRX signal is de-asserted the PCA module captures the time value of the counter. After the measurement completes the PCA can then capture the rising edge of the PRX signal. There are now two time values that represent the complete low pulse interval. The subtraction of the falling edge count from the rising edge counts provides the time for the PRX pulse and can be passed on to the proximity algorithms. 3 LED Example Schematic Each LED is enabled by GPIO from the MCU and controlled by the TXO output from the Si1120 Only one LED is active at any given time One LED per FET enabled at a time GPIO Input capture from PRX Output frequency to STX Output SC control Output MD control Px.x MCU port pin 21 An earlier slide showed a single LED implementation where the TXO signal was used to directly control a single LED. Here is another application example where the Si1120 is used, in conjunction with an MCU, to control three IR LEDs which may be useful for motion, position sensing (XYZ) or other similar functions (IR sliders). Each LED is gated through an external gate that is enabled on a time multiplexed fashion by the MCU. For example, in the figure the P2.1 signal, when high, enables the TXO signal to sink current from the D1 LED through Q1. The other two GPIOs shown (P2.2 and P2.3) would leave those gates disabled while the D1 LED is used. On the next cycle the P2.1 I/O is de-asserted and the P2.2 I/O is asserted causing the TXO signal to sink current through the LED connected to Q2. This cycle repeats for the remaining gates and diodes in the system. The Si1120EK includes a board that implements this 3 LED scheme and this schematic is a representation of that system. MCU Firmware: I/O Port Initialization Step 1: Configure the PCA channel 1 output pin to push-pull (P1.4) Step 2: Set the GPIO pins for LED enables, MD and SC to push-pull Step 3: Skip the I/O to push the CEX0 and CEX1 outputs to pins P1.2 and P1.4 Step 4: Enable the PCA in the crossbar 2 1 3 Step 5: Enable the crossbar 4 Sample code derived from the Si1120EK 3 LED board 5 22 The previous slides covered how the MCU controls the hardware interface to the Si1120. In this section, we will illustrate the structure of the firmware used to control the Si1120 (using a C8051F930). The firmware implementation uses the hardware outlined for the three LED system discussed prior. Refer to the three LED schematic on the previous slides to correlate the special function register settings with the pin designations and Si1120 input/output functions. The specific device data sheet should also be consulted for definitions of the specific registers used in these examples. The I/O of the MCU is connected directly to the Si1120 so we have to configure them to be either input or output depending on the function. For example, the Si1120 MD pin is input so the MCU GPIO pin must be set as a push-pull output. The example shown here provides the I/O settings for all of the control inputs as well as the PCA pin settings for the application. There is a priority encoded crossbar in Silicon Labs MCUs that enable all of the digital peripherals in the device to be placed on the I/O instead of the traditional multiplexed I/O. As a result, there are skip registers and an enable for the crossbar that needs to be set in order to make the PCA signals available to specific pins after they have been configured for the input or output direction. For more information check out any Silicon Labs MCU data sheet for port input/output more information on the crossbar and its operation. MCU Firmware: Initializing the PCA Step 1: Set the clock source to the PCA Step 2: PCA channel 1 used for a square wave output Derives the sample time for the Si1120 STX input Step 3: PCA channel 0 used for input capture mode Receives the PWM output PRX from the Si1120 Rising and falling edge capture to measure the complete low time of PRX Step 4: Enable the PCA interrupts Step 5: The frequency mode uses a 16 bit compare so the values gets added to the latest compare value 1 2 3 4 5 6 7 Step 6: Set the LED enables to the default output Step 7: Start the counter 23 As mentioned earlier the PCA is responsible for capturing the timing events for the PRX going low and again when it goes high. In this application the PCA is also responsible for setting the STX time base for initiating measurements in which the fastest rate recommended for the Si1120 is 500 Hz. In this example we will set the rate to 400 Hz. With that in mind we have to set the clock source to the PCA; and let’s assume we have a system clock of 24.5 MHz which is very common among Silicon Labs devices. If we were to use the 16 bit counter without scaling the clock input we could get a minimum overflow rate of 387 Hz (24.5 MHz/65536). This hits our target of 400 Hz, however, it does not leave a lot of room to modify the system level performance, for example, if we wanted to run below 100 Hz to reduce power. The flip side is we want to provide as much resolution for the measurement as possible. Using the SYSCLK/4 as the counter input we can get as low as 96 Hz and provide a resolution of 160 ns. After setting the clock the PCA channels are then configured. Channel 1 is set to drive the STX output for the 400 Hz output and channel 0 is set to measure the PRX output. You will notice a section in the code that sets the PCA0CPL1/CPH1 registers and adds a divide ratio. This is allows a constant frequency output from the PCA module similar to the hardware functionality similar to some other timers in the C8051F family. MCU Firmware: Setting the Si1120 Mode Step 1: Make STX a GPIO pin by disabling the PCA to the crossbar Step 2: Drive GPIO pin SC high Step 3: Set the MD latch and the STX latch values for the desired mode Step 4: Drive SC low to latch the data Step 5: Drive MD to the final value for the desired mode Step 6: Return STX to the PCA output 1 2 3 4 5 3 2 4 5 SC MD STX Don’t care Don’t care MD (latch) 1 MD (static) STX (latch) 6 24 Setting the mode to the Si1120 requires a two stage process that involves controlling three output pins of the MCU: MD, STX and SC. The description of how to set the mode was discussed earlier so the firmware implementation is shown here. Within the Silicon Labs MCUs there is a crossbar and each peripheral that passes through the crossbar has to be enabled which provides the connection to the I/O pins. When setting up the Si1120 mode we are going to reuse the STX pin as it is used to set the mode as well as initiate measurements. For this reason step one above disables the PCA through the crossbar allowing the firmware to control the GPIO pin directly. The remaining steps follow the mode setting procedure outlined previously by setting the Si1120 to the low power mode by raising SC and changing the I/O. The numbered lines of code correspond to the steps given and the follow the timing diagram for setting the modes. MCU Firmware: PCA Channel 1 ISR PCA channel 1 generates a square wave output 16 bit comparisons determine the sample interval for each LED by driving STX After each comparison the PCA compare register is added to the Next_Compare_Value 25 Once the initialization sequence is completed the firmware has to be set up to service the operation of the Si1120 using the PCA interrupt service routines (ISR). PCA channel one was configured to be the square wave output which was generated by adding our ratio value to the current count to always provide the same overflow rate. Within the channel one ISR the next count value is determined and loaded into the compare registers to provide the next overflow. That is all the ISR does for this PCA output driving the STX signal. MCU Firmware: PCA Channel 0 ISR PCA channel 0 measures the PRX low time by capturing the falling and rising edges PRX goes low causing a capture event and the ISR stores the data Subsequent PRX rising edge causes a second capture event once again storing the data The difference between the two captured values provides PRX low time Once PRX low time complete the ISR changes to the next LED 26 … The PCA channel 0 ISR is a little more complicated as it is measuring the PRX low time by capturing the falling and rising edges and is entered twice. The ISR first determines if the event was from a falling edge by measuring the pin value. If low, the ISR then stores the captured timer value and exits and waits for the next edge. On the next trigger event, which would be a rising edge, the ISR once again stores the captured timer value and then determines the time interval between edges by subtracting the falling edge capture from the rising edge capture. This calculation provides the measure of the reflected energy. In the case of the three LED example, once the value of the reflected energy is measured for the current LED the ISR also moves the external gate enable to the next LED in the sequence and the cycle repeats. Development Kits 27 Three – LED Motion Demonstration Seven LEDs on board Can implement several measurement modes Single proximity measurements Three LED motion measurements Two LED slider measurements Ambient light sensing Provides interface to C8051F930 low power MCU Highlights time division multiplex scheme for monitoring multiple LEDs Interfaces to the QuickSense Studio GUI DK Part #: Si1120EK 28 Three IR LED Motion Demo Hand moves left to right to left blue/red lead pink leads Hand moves bottom to top to bottom red pink blue blue leads pink/red lead 29 Let’s take a look at a sample acquisition using the Si1120EK. In this example the LEDs labeled red, pink and blue are enabled using the jumpers on the board. In the top plot a hand moves from left to right and then back again. From the figure you can see the red and blue traces start at the same time indicating that the Si1120 is receiving the reflected energy from the hand from both LEDs at the same time. The only difference is the magnitude since the blue LED is farther from the Si1120 then the red. As the hand moves to the right the pink LEDs reflected energy starts to get detected as shown by the increase in magnitude. The opposite is true for the reverse direction in the plot. As the hand moves right to left the pink leads the red and blue. IR Slider Demonstration An infrared slider can sense as far as the most distant IR LED can be sensed by the Si1120 Multiple methods of set-point gesture recognition including: A left to right or right to left motion with a pause indicating set-point A left to right or right to left swipe USB connection is all that is required DK Part #: IrSLIDEREK 30 Another reference kit that highlights the use of the Si1120 is the IR Slider (IRSLIDEREK). This board provides two LED emitters spaced equally from the Si1120. As the hand moves across the range of interest it generates the profile shown in the plot. From these inputs the location of the hand can be detected. There are also gestures that can be recognized by the MCU such as single taps or double taps all without ever touching anything. Some additional gestures that can be interpreted are: a left to right or right to left motion with a ‘press’ and ‘retract’ and a simple approach and retract of an object without any lateral movement. Front Panel Evaluation Kit Infrared proximity sensing Ir proximity sensing is provided via an Si1120 controlling a single IR LED Capacitive proximity sensing Capacitive sensing is provided via a a single pad surrounding four touch buttons connected to an C8051F800 QuickSense Studio support Real-time performance analysis support provided via USB connection to QuickSense Studio Kit Contents FrontPanel2-EB demo board USB cable FrontPanel2EB quick start guide 31 F340 EK Part #: FrontPanel2EK Si1102 Evaluation Kit Infrared threshold detection The Si1102EK demonstrates a simple infrared proximity threshold—a visible LED illuminates when an object crosses an invisible threshold Configurable range Proximity threshold range and scan rate is controlled by two thumb-wheel potentiometers Battery operated This self-contained demonstration operates from a single coin-cell battery Kit Contents Si1102AB demo board Si1102EK Quick Start Guide 32 EK Part #: Si1102EK Summary of the QuickSense Infrared Sensors Si1102/1120 provides industry-leading performance High sensitivity infrared photodiode Industry-leading range up to 50 cm Innovative single pulse proximity sensor Immune to fluorescent flicker Ultra-low system power Si1120-A-GM Integrated ambient light photodiode (Si1120) Reduces backlight power in low-light settings Addressing the needs of user interface development QuickSense Studio provides rapid deployment Patent pending touch-less slider and gestures Algorithms including background light type determination 33 33 Learn More at the Education Resource Center Visit the Silicon Labs website to get more information on Silicon Labs products, technologies and tools The Education Resource Center training modules are designed to get designers up and running quickly on the peripherals and tools needed for application development http://www.silabs.com/ERC http://www.silabs.com/mcu Si1102EK: www.silabs.com/Si1102EK Si1120EK: www.silabs.com/Si1120EK IrSliderEK: www.silabs.com/slider FrontPanel2EK: www.silabs.com/frontpanel AN442: Designer’s Guide for the Si1102 & Si1120 To provide feedback on this or any other training go to: http://www.silabs.com/ERC and click the link for feedback 34 Visit the Silicon Labs Education Resource Center to learn more about the MCU products. www.silabs.com/MCU 35