MagSW v20a (Development Preview)

Magnetic switch for remote-controlled models with a microcontroller and voltage brown-out detection.

February 19, 2019

19-FEB-2019: This is a preview for the MagSW v20a. The content is subject to change.

The Story

I have had this one in mind since I worked on the previous v10a version. MagSW v20a is an extended variant of the MagSW v10a. The v20a uses a tiny microcontroller instead of the D-type flip-flop for the switch memory. The rest of the circuit remains identical. Adding a small microcontroller to the system was extremely tempting. The microcontroller allows for features which are difficult to implement without it. The key and only difference in functionality between the MagSW v10a and MagSW v20a is that the latter monitors the onboard voltage and signalizes its minimal detected level through the LED (aka brownout detection). More on this later.

MagSW v20a from the top

MagSW v20a from the top

MagSW v20a from the bottom

MagSW v20a from the bottom

Technical Data

Technical data are mostly identical to the v10a variant.

Parameter Value
Operating voltage range 3-18V
Maximum continuous current 4.43A
Typical on-resistance typ. 34mΩ
Standby current <3.5 uA
Operating temperature -40 to 80°C
Dimensions 15x8mm (bare PCB)
Weight 0.48g (bare PCB)
Protections overcurrent, overtemperature, starts always-on
Status indicator 1x LED, lits or blinks different patterns to signalize voltage level
Required magnetic field >63mT
Memory typ. 7s (the off state only)

Description

I described the fundamentals of a magnetic switch for R/C applications in the previous article which covers the v10a version. For this reason, I am going to describe only additional functionality.

Voltage Monitoring

In my opinion, most of the reliability issues in R/C applications have something to do with onboard power. Servos can draw current up to several amps when they change position quickly and under load. For this reason, it is important that the battery pack which supplies electronics has very low internal resistance. However, as batteries in the pack age, the internal resistance increases and causes sudden voltage drops under the load. This may cause spurious resets of the microcontroller in the receiver and result in connectivity issues, sudden freezing or complete system lockout.

The MagSW v20a measures output voltage every 1ms and compares the value with the pre-set threshold. The switch has three voltage thresholds with four functional states. System changes the functional state once the voltage reaches the next lower threshold. The LED signalizes one of the functional states with a different blinking pattern. The system can change the functional state only from the top to the bottom (HIGH->MEDIUM->LOW->CRITICAL). Only the power cycle resets the state back to a higher level if present.

It is important to understand that the MagSW v20a does not inform you about the remaining capacity in the battery!!! It only reports that onboard net voltage dropped below the certain level during the flight (operation) and you should consider doing something about it (e.g. charging or replacing the pack). Most modern batteries have a very flat discharging curve and estimating remaining capacity based on voltage is highly inaccurate, if not impossible.

You may modify following macros if you desire to change voltage thresholds:

/* Thresholds for the voltage measurement */
# define ADC_LEVEL_HIGH   N/A   /* High Level >= 4.84V */
# define ADC_LEVEL_MID    120   /* Medium Level < 4.84V */
# define ADC_LEVEL_LOW    100   /* Low Level < 4.03V */
# define ADC_LEVEL_CRIT   87    /* Critical Level < 3.51V */

Example for the ADC_LEVEL_MID macro:

where:

  • N - is resolution of the AD converter (8b),
  • Vref - is voltage reference (3.3V),
  • Vout - is desired voltage threshold (here 4.84V),
  • R4, R2 - are resistors in the sensing divider,
  • D - is calculated value for the macro.

Notes:

  • I don’t cover Battery Eliminator Circuits (BECs) here because it is not a typical application for a magnetic switch such as the MagSW.
  • In reality, the problem with internal resistance is even worse because of connectors, their wear and wires resistance.

The Circuit

The circuit is very similar to the previous v10a version. Positive terminal from the battery connects to the pad J1 (+BAT). Positive terminal from the load (receiver) connects to the pad J3 (+RX). Pads J2 and J4 are common ground (GND). Input and output capacitors C2, C3 and C7, C8 are connected in series. This prevents catastrophic failure if one of the MLCC capacitors cracks and shorts. This is a design practice from the automotive industry. Capacitor C4 sets output slew-rate and resistor R3 sets the current limit threshold for the high-side switch U3. Resistors R2, R4 form a resistor divider for the voltage measurement. Capacitor C5 adds low-pass filtering response to it and reduces noise. The linear regulator U1 with the required output capacitor C1 provide stable 3.3V for the logic. The hall sensor U2 has an open collector type of output. For this reason, it requires a pull-up resistor R1. Capacitor C9 is a bypass capacitor for the tiny 8-b microcontroller U4. The LED D1 indicates the functional state of the magnetic switch. The resistor R5 limits the current through the LED. Resistor R6 decouples the programming interface from the trigger signal and makes In-Circuit-Serial-Programming (ICSP) possible through pads J5-J9.

Hall Sensor Signal Filtering

Unlike the previous version with low-pass RC filtering the v20a removes possible glitches coming from the hall sensor in the firmware. The principle is very simple. A valid trigger impulse from the hall sensor must be longer than 100ms (set by macro HALL_DEGLITCH_PERIOD_MS). Any pulses shorten than this de-glitch period are ignored. This, together with the highly insensitive hall sensor, provide enough robustness to suppress spurious turn-ons and -offs.

The Firmware

The firmware is written in ANSI C programming language and contains only a single source file (main.c). The code is simple, documented and self-explanatory for anyone familiar with embedded programming. Scroll to the end of the source file for notes. I used the MPLAB X IDE v 5.10 with the free version of the XC8 v2.0 compiler. The project compiles with zero warnings, zero errors. The generated binary file (HEX) uses approximately 28% of Data and 60% of the program memory of the microcontroller. The complete project, source file as well as compiled binary file can be found in the Design Data section.

Measurements

Refer to the previous version.

Using the MagSW v20a

The video below shows how the prototype reacts to input voltage changes with the LED signalizing all four states.

Building Your Own Copy

Refer to the previous version.

Design Data

MagSW v20a Complete KiCad 5.0.2 Project
MagSW v20a Schematic - PDF
MagSW v20a Gerbers
MagSW v20a BOM - MS Excel
MagSW v20a Interactive BOM
MagSW v20a MPLABX project
MagSW v20a fw v1.0.1 binary file

Conclusion

The 2018 season showed that the v10a version is a reliable solution. The v20a version just adds the voltage detection feature and makes the device more intelligent. The tiny microcontroller in the system increases complexity due to programming but may also identify problems related to onboard power.

FAQ

Q: What is the difference between the v10a and v20a version

A: The v20a version monitors the onboard voltage and reports back the minimum voltage level detected.

Q: Which hardware tool do I need to program the MCU.

A: You need a USB programmer which supports the PIC10F322 MCU, e.g. I find PicKit3 to be the most versatile option (check eBay, just be aware that Chinese clones may or may not always work…).

License

All HW design data are licensed under CERN Open Hardware License v.1.2 or later. If you like the design, please consider buying me a beer (PayPal). All firmware data are released as open-source, public domain.

Additional Pictures