Tuesday, June 21, 2022
HomeElectronicsGrowing window safety nodes with degree shifting I/O - Half 2

Growing window safety nodes with degree shifting I/O – Half 2


The Half 1 of this two-article collection mentioned a brand new peripheral known as multi-voltage I/O (MVIO), which is offered on the AVR DB household of microcontrollers. Briefly, the MVIO is an inner degree shifter on the die of the microcontroller that permits one I/O port to function in a distinct voltage area than the remainder of the machine. This reduces the invoice of supplies (BOM) and the design space whereas offering extra flexibility than exterior options.

The Half 2 of this collection will take a look at the MVIO being utilized in an software. It’s based mostly on a demo that makes use of 3D magnetometer as a window safety sensor to detect whether or not a window is open or closed.

One of many easiest methods to detect whether or not a window is open is to make use of a magnetic reed swap. A reed swap is an easy machine with electrical contacts which can be opened or closed by the presence of a magnetic area. By mounting a magnet to a window and the swap to a set place, the state of the window could be decided by continuity by way of the contacts. Nevertheless, there are two limitations with a reed swap.

Firstly, it can not differentiate between a cracked window and an open window. If the alarm is used, then the window can’t be cracked with out setting the alarm off. Secondly, the reed swap could be simply tampered with by inserting a second magnet close by. The secondary magnet holds the contacts of the swap in place whereas the window is opened.

To enhance tamper resistance and value, another answer was developed with a magnetometer. In contrast to a reed swap, which is both open or closed, the magnetometer measures and digitalizes the magnetic area parts. By monitoring the sector parts, the sensor can differentiate a cracked window from an open window and is far more tamper-resistant to magnets positioned close to the sensor.

To display the benefit of a magnetometer-based answer, we co-developed a sensible window-security sensor with Melexis, a provider of semiconductor-based sensing options. It’s based mostly on the microcontroller from the AVR DB household, which is the primary microcontroller to have an MVIO peripheral. Right here, an MLX90392 3D magnetometer has been used for monitoring the magnetic area energy. The magnetometer is powered from 1.8 V and communicates over I2C.

This demonstration additionally makes use of an MLX90632 far infra-red (FIR) sensor to watch the temperature of the room. The FIR sensor chosen is a better option than a neighborhood temperature sensor, because the node will expertise air drafts and direct daylight, which may trigger measurement errors. Whereas the MLX90632 is powered from 3.3 V, there’s a machine variant designed for 1.8 V I2C communication.

For wi-fi connectivity, an RN4870 Bluetooth module has been used for simplicity. This enables a consumer to work together with the demo from the smartphone, quite than a custom-developed communication bridge. In a manufacturing software, nonetheless, we’d advocate switching to another easier and decrease energy radio answer, like Sub-GHz radio, for every sensor node. The supply code and documentation are linked on the finish of the article.

Prototyping and improvement setup

For improvement, we used a Curiosity Nano Base for Click on Boards (AC164162) with an AVR DB Curiosity Nano Growth Board (EV35L43A). The RN4870 Bluetooth module and the MLX90632 temperature sensor can be found on Click on boards from MikroElektronika (RN4870 Click on and IrThermo 3 Click on). The MLX90392 magnetometer was supplied by Melexis on a pre-assembled analysis board for MLX90392.

After preliminary sensor communication testing, we rapidly realized {that a} take a look at fixture to manage the place of the magnet and sensor could be wanted. Utilizing our latent arts-and-crafts skills, we assembled a easy take a look at fixture with cardboard and scorching glue, as proven under.

 

Determine 1 On this prototype take a look at fixture and setup, the small white field hooked up to the fixture come from an off-the-shelf door swap. The included magnet was used for example of a normal safety magnet for testing functions. Supply: Microchip

The magnetometer

Conceptually, the window alarm facet of this method would look like the best to implement, however it was much more difficult than we initially thought. There are a few causes for the added complexity.

Firstly, the magnetometer is extraordinarily delicate. Small variations within the place of the magnet or magnetometer would throw the numbers off dramatically. The graphs under have been derived from the uncooked values of the magnetometer with out calibration or normalization (Determine 2). Throughout information assortment, the sliding mechanism was slid backwards and forwards.

Determine 2 The graph exhibits uncooked magnetometer area element intensities. Supply: Microchip

Reasonably than instantly monitoring every element’s most and minimal, which is able to fluctuate relying on the mounting place of the sensor, we used the overall magnetic area energy as a substitute (R = √(X2 + Y2 + Z2). For software program optimization causes, the applying makes use of the sq. of the magnetic area energy. The graph under exhibits the magnitude of the magnetic area throughout the identical take a look at. In software, the magnitude is calculated from normalized 16-bit values, as proven in Determine 3.

Determine 3 The graph exhibits the magnitude of the magnetic area energy through the take a look at. Supply: Microchip

To make the system extra delicate general, the magnetic area values in every axis have been normalized. From the pattern information proven, the magnitude of the Y-axis is the most important, adopted by Z after which X. Every axis will increase at a distinct fee from the others. This intuitively is sensible, because the magnetic flux would be the highest within the perpendicular course and the weakest in parallel. To normalize every axis, the microcontroller scales every by proper shifting the outcomes to suit inside a signed 8-bit worth. The scaling elements are calculated through the consumer calibration sequence to make the system extra delicate general.

Initially, the applying was going to additionally calculate the angle ratios of X/Y, X/Z and Y/Z for extra tamper resistance. However in testing, this calculation was discovered to be very unreliable as a result of giant variances in area depth. These angles added to the reminiscence utilization and the energetic time of the demo. We discovered the applying labored nicely with out them and disabled them by way of a macro. The computed angle ratios from the sooner information are proven under (Determine 4).

Determine 4 The X/Y, X/Z and Y/Z angle ratios of magnetometer have been computed from the sooner information. Supply: Microchip

To reliably make the most of the magnetometer, we developed a four-step calibration course of. This course of have to be carried out through the preliminary setup, however the consumer can retrigger it later, if wanted. The 4 steps to calibrate the applying are:

  1. Zeroing
  2. Normalization
  3. Setting threshold
  4. Verification

In zeroing, the window is totally opened, which locations the magnet as removed from the sensor as doable. The typical worth recorded for every axis is outlined because the offset worth. Subsequent, the window is closed, which locations the magnet very near the sensor. The sphere intensities in every axis are averaged on this place. After the set variety of samples, the microcontroller computes the normalization issue for every axis.

Subsequent, the consumer opens the window to the specified open/closed threshold. Whereas the consumer is opening the window, the applying is monitoring the utmost area energy (R2) recorded. Relying on positioning, the utmost area energy ought to happen at or near the closed-window place.

After this step, the consumer will shut the window. At this level, the system is checking to see if the alarm might be triggered whereas the window is being closed. If the alarm does journey, then the calibration failed and must be repeated. Then again, when the calibration is profitable, the values are written into inner EEPROM for later use.

Implementing temperature sensor

To interface with the MLX90632 sensor, we developed a brand new light-weight API that was designed to leverage microcontroller-specific options to enhance efficiency. Within the case of the MLX90632 temperature sensor, we carried out a calibration-constant caching system to retailer the sensor’s manufacturing unit constants into the microcontroller’s EEPROM. That is mechanically carried out by the microcontroller. On startup, the microcontroller checks its EEPROM to find out whether or not the constants from the sensor have been programmed into reminiscence. To confirm the constants, the microcontroller:

  • Matches the saved serial quantity to the sensor’s serial quantity
  • Verifies the XOR of the serial quantity on the finish of the reminiscence section

If both verify fails, the microcontroller will reacquire the sensor’s constants, compute the floating-point equivalents after which rewrite them into the EEPROM. If the reminiscence is taken into account legitimate, the microcontroller merely reads the saved constants quite than reacquiring and recomputing them.

This characteristic could be disabled in software program by undefining a macro. Alternatively, if the calibration button is held when the applying powers up, the applying will begin in secure mode, which considers all settings and values within the EEPROM invalid and can reacquire/reprogram (if enabled).

Working with 1.8 V

At 1.8 V, serial communication have to be dealt with extra fastidiously than the extra frequent 3.3-V or 5-V sorts. As an illustration, the interior pull-up resistors within the microcontroller could be too weak for the bus to satisfy the timing necessities. To resolve this difficulty, we added exterior pull-up resistors to the bus.

Throughout early testing, we tried to instantly measure the present consumption of an exterior 1.8-V energy provide utilizing a precision digital multimeter. Nevertheless, the burden voltage of the multi-meter was simply sufficient that the bus would brown-out throughout serial communication. We resolved this difficulty within the prototype by including a big tank capacitor to the ability provide to make sure the bus would stay above the brown-out threshold whereas the meter measured the present consumption. This isn’t a problem within the full software, since present could be measured from the ability enter and the ability provides are regulated on the board, quite than externally.

Last outcomes

As soon as the system was functioning accurately, we began improvement of a devoted PCB. The picture under is of the board that was developed (photographed with out the plastic case). The prototype system is to be proven at Sensors Converge 2022 on June 27-29 on the Microchip sales space # 218.

Determine 5 The prototype board has been photographed with out the plastic case. Supply: Microchip

Interfacing mixed-voltage domains is an important aspect of many designs. Generally, an exterior degree shifter have to be used to transform between voltage domains. The MVIO eliminates this element and integrates it into the microcontroller, which makes it virtually invisible to the developer. There are lots of doable designs and purposes that can profit from the addition of the MVIO peripheral within the system.

Supply code and documentation of the above software is offered at:  

https://github.com/microchip-pic-avr-examples/avr128db28-smart-security-sensor-mplab

Editor’s Observe: The creator extends particular due to Melexis for its help in creating this software.

Robert Perkel is software engineer for 8-bit MCU enterprise unit at Microchip Know-how.

Associated Content material



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments