Controlling a USB Port with Hysteresis in a Solar Power System – SunControl – Why?

Controlling a USB Port with Hysteresis in a Solar Power System – SunControl – Why?

We have been asked about how the USB port is controlled on SunControl and also for an explanation of hysteresis and why it is important in a solar powered system.

The SunControl Kickstarter goals have been met and the kickstarter is still active (as of  July 2, 2017):

.
[callout size=”col-12″ title=”Checkout the SunControl Kickstarter” button_title=”Go to Kickstarter” button_link=”https://kck.st/2rGInI0″  button_size=”normal” button_rounded=”true” button_color=”red”]

 

USB Port Control on SunControl

The USB PowerControl section of SunControl is very similar to the SwitchDoc Labs product USB PowerControl. This section of SunControl is a digitally controlled power switch for your Arduino or Raspberry Pi.  Anything you can plug into a USB port can be controlled with this USB Port. It is either controlled by the input of the LiPo battery voltage (LIPOBATIN) or by GPIO lines connected to the Grove USB Control port.

hysteresis

The Problem

The USB PowerController Board is basically a controlled Solid State Relay to turn the power on and off to the Raspberry Pi. This board sits between the Solar Power Controller (SunAirPlus) and a Raspberry Pi Model A+. The input to the board was designed to come directly from a LiPo battery so the computer won’t be turned on until the LiPo battery was charged up above ~ 3.8V. A hysteresis circuit is provided so the board won’t turn on and then turn immediately off because the power supply is yanked down when the computer turns on (putting a load not the battery). This really happens!!!! You kill Raspberry Pi SD Cards this way.

What causes these cycles is that your system gets to a certain voltage and the USB port turns on and connects to the load, which lowers the battery voltage and the USB port turns off again. The cycle then repeats.

You can’t just let the controller power up the computer. The problem is that the supply voltage will move up and down until there is enough charge in the battery to fully supply the computer. When the computer turns on (connecting a full load), you will pull the battery down hard enough to brown out the computer causing the Raspberry Pi to crash. This constant rebooting cycle can corrupt and ruin your SD card and cause your computer to never boot at all, even when the power is restored. We had this VERY thing happen to us 3500 miles away with Project Curacao. Arduinos are more tolerant of this, but Raspberry Pi’s do not like a ill-behaved power supply. You just can’t be sure of what state the computer will power up at without a good power supply.

This issue can be handled in a number of ways. The first is to use another computer (like an Arduino made to be very reliable by using a WatchDog – see the Reliable Computer series on switchdoc.com – https://www.switchdoc.com/2014/11/reliable-projects-watchdog-timers-raspberry-pi-arduinos/ ) to disconnect the Raspberry Pi’s power through a latching relay or MOSFET when there isn’t enough power. Project Curacao ( https://www.switchdoc.com/project-curacao-introduction-part-1/) used this approach.

 

Hysteresis to the Rescue

HysteresisIn order to control a USB Port based on a battery voltage, you need to turn on at one voltage and turn off at another. This process is called Hysteresis and prevents damage to your Raspberry Pi SD card or other processors caused by rapid on and off power cycles.

The input to the board was designed to come directly from a LiPo battery so the computer won’t be turned on until the LiPo battery was charged up above 3.7V.  We provide a hysteresis circuit so the board won’t turn off until the voltage goes below around 3.3V.  This is an excellent board to shut on and off USB powered devices like a Raspberry Pi and Arduino.  It works just like a conventional relay, except that it requires virtually no current to keep it on or off. Like a latching relay.

The SunControl Hysteresis circuit on LIPOBATIN is based on a TA75S39 Operational Amplifier used as a comparator. A comparator with hysteresis has two important thresholds: upper and lower. Unlike a simple comparator, however, the output of the comparator doesn’t depend solely on whether the input is above or below one of these thresholds. It depends on both the current state of the output and the current value of the input. If the output is high, it will stay high until the input voltage drops below the lower threshold. If the output is low, it will stay low until the input voltage rises above the upper threshold.

The diagram to above shows a hysteresis ‘loop’ that describes how a comparator functions. The horizontal ‘X’ axis is the input, and represents the difference of the two input voltages. The vertical “Y” axis represents the comparator’s output state.

If the comparator is initially ‘OFF’, the MINUS input voltage has to become slightly above the PLUS input voltage before the comparator output turns ‘ON’. This is represented by moving right along the bottom part of the loop.

Once the comparator is ‘ON’, the MINUS input voltage needs to drop slightly below the PLUS input voltage before it turns ‘OFF’ again (moving left along the top of the loop).

The ‘ON’ state is set in the USB PowerControl to be 3.7V and the ‘OFF’ state is set to be about 3.3V. The output of the comparator drives the input to the Load Switch.

The Grove Digital Input that allows you to control the USB PowerControl using two GPIO Lines (one enable and one control line) to switch on and off from a Grove Digital Port. The Grove Enable Line, when high, disables the LIPOBATIN line and makes control of the device under the Grove CONTROL Line. When the Grove Enable Line is low, the LIPOBATIN line controls the relay as in the original USB PowerControl. The Grove Enable Line is pulled down by a 43K resistor so by default it uses LIPOBATIN.

Conclusion

By careful design, SunControl provides excellent support for preventing reliability issues with Arduino and Raspberry Pi based systems and especially protects the Raspberry Pi SD Card from fast cycle reboots.