Box0 Power Supply

Introduction

The device power supply is divided into two parts.

Analog

  • +5 V, −5 V supply
  • Over-current protection
  • Automatically enabled when AIN/AOUT is enabled.
  • Automatically disabled on over-current
  • Enable/disable from Computer
  • Poll Status from Computer
  • “±5V” LED for quick feedback
  • Shared with on-board OPAMP’s

Digital

  • +3.3 V Supply
  • Over-current protection
  • Automatically enabled when SPI/I2C enabled.
  • Automatically disabled on over-current
  • Activate/Deactivate from Computer
  • Poll activate status from Computer
  • “+3.3V” LED for quick feedback

Usage

LED

The power supplies has respective LED for quick feedback.

OFF Power supply is inactive
ON Power supply is active
BLINK Over-current and power supply is inactive

Short-circuit protection

When The user accidentally connect power pins to GND or opposite polarity.
In case, over-current occurs and the user will know that something is wrong.
for quick feedback, the respective LED will BLINK.

High Level Program

In [ ]:
#
# box-v5 Power Supply
# Author: Kuldeep Singh Dhaka <kuldeepdhaka9@gmail.com>
# Licence: GPLv3 or later
#

import box0

# python2 raw_input and python3 input
try: input = raw_input
except: pass

dev = box0.usb.open_supported()

print("Welcome! please enter a command:")
print("  b - [both] digital supply enable and analog supply enable")
print("  a - [analog] analog supply enable and digital supply disable")
print("  d - [digital] digital supply enable and analog supply disable")
print("  n - [none] digital supply disable and analog supply disable")
print("  s - [status] both suppy status")
print("  e - [exit] exit the program")

#turn both supply off
dev.ps_en_set(dev.PS_ANALOG | dev.PS_DIGITAL, 0)

try:
    while True:
        c = input("> ")
        if c == "b":
            dev.ps_en_set(dev.PS_ANALOG | dev.PS_DIGITAL, dev.PS_ANALOG | dev.PS_DIGITAL)
        elif c == "a":
            dev.ps_en_set(dev.PS_ANALOG, dev.PS_ANALOG)
        elif c == "d":
            dev.ps_en_set(dev.PS_DIGITAL, dev.PS_DIGITAL)
        elif c == "n":
            dev.ps_en_set(dev.PS_ANALOG | dev.PS_DIGITAL, 0)
        elif c == "s":
            mask = dev.ps_en_get()
            print("Analog: " + ("Enabled" if mask & dev.PS_ANALOG else "Disabled"))
            print("Digital: " + ("Enabled" if mask & dev.PS_DIGITAL else "Disabled"))
        elif c == "e":
            break;
        else:
            print("unknown command: " + c)
except KeyboardInterrupt: pass

#turn all supply off
dev.ps_en_set(dev.PS_ANALOG | dev.PS_DIGITAL, 0)

#close device
del dev

Low level Protocol Program

Constants

Name Value
PS_EN_GET 201
PS_EN_SET 202
PS_OC_GET 203
PS_OC_ACK 204

Read enable value

bmRequestType Host ← Device, Device, Vendor
bRequest PS_EN_GET
wValue 0x0000
wIndex 0x0000
wLength 0x0001
Data BIT0 = Analog, BIT1 = Digital

Note: BITx = 0, supply is off.
Note: BITx = 1, supply is on.

Write enable value

bmRequestType Host → Device, Device, Vendor
bRequest PS_EN_SET
wValue HIGH8(mask) LOW8(value)
wIndex 0x0000
wLength 0x0000
Data None

Note: In mask: BITx = 0, then crossponding value BITx is considered valid.
Note: In value: BIT0 = Analog, BIT1 = Digital. BITx = 0 mean off, and BITx = 1 means "on".

Read over-current value

bmRequestType Host ← Device, Device, Vendor
bRequest PS_OC_GET
wValue 0x0000
wIndex 0x0000
wLength 0x0001
Data BIT0 = Analog, BIT1 = Digital

Note: BITx = 1, supply is over-current.
Note: BITx = 0, supply is NOT overcurrent

Acknowledge over-current

bmRequestType Host → Device, Device, Vendor
bRequest PS_OC_ACK
wValue HIGH8(0) LOW8(value)
wIndex 0x0000
wLength 0x0000
Data None

Note: BIT0 = Analog, BIT1 = Digital.
Note: BITx = 1 mean Acknowledge, and BITx = 0 ignore the power unit.
Note: if a BITx is set and the crossponding unit is not having any over-current, then the request is STALLED.

In [ ]:
#
# box-v5 Power Supply
# Author: Kuldeep Singh Dhaka <kuldeepdhaka9@gmail.com>
# Licence: GPLv3 or later
#

import usb.core
import usb.util
from usb.util import CTRL_IN, CTRL_OUT, CTRL_RECIPIENT_DEVICE, CTRL_TYPE_VENDOR

BOX0V5_PS_EN_GET = 201
BOX0V5_PS_EN_SET = 202

POWER_ANALOG = 0x01
POWER_DIGITAL = 0x02

# python2 raw_input and python3 input
try: input = raw_input
except: pass

# open device
dev = usb.core.find(idVendor=0x1d50, idProduct=0x8085)
if dev is None:
    raise ValueError("Device not found")

# assign 1st configuration
dev.set_configuration()

print("Welcome! please enter a command:")
print("  b - [both] digital supply enable and analog supply enable")
print("  a - [analog] analog supply enable and digital supply disable")
print("  d - [digital] digital supply enable and analog supply disable")
print("  n - [none] digital supply disable and analog supply disable")
print("  s - [status] both suppy status")
print("  e - [exit] exit the program")

def power_supply_set(dev, analog, digital):
    """
    Activate/deactive power supply
    dev: USB Device
    analog: activate/deactivate Analog supply
    digital: activate/deactivate Digital supply
    """
    bmReqType = CTRL_OUT | CTRL_RECIPIENT_DEVICE | CTRL_TYPE_VENDOR
    mask = POWER_ANALOG | POWER_DIGITAL
    value = 0x00
    if analog: value |= POWER_ANALOG
    if digital: value |= POWER_DIGITAL
    wValue = (mask << 8) | value
    dev.ctrl_transfer(bmReqType, BOX0V5_PS_EN_SET, wValue)

def power_supply_get(dev):
    """
    Read power supply status
    dev: USB Device
    return a tuple (<analog-supply>, <digital-supply>)
    """
    bmReqType = CTRL_IN | CTRL_RECIPIENT_DEVICE | CTRL_TYPE_VENDOR
    data = dev.ctrl_transfer(bmReqType, BOX0V5_PS_EN_GET, 0, 0, 1)
    analog = (data[0] & POWER_ANALOG) != 0x00
    digital = (data[0] & POWER_DIGITAL) != 0x00
    return analog, digital

#turn both supply off
power_supply_set(dev, False, False)

try:
    while True:
        c = input("> ")
        if c == "b":
            power_supply_set(dev, True, True)
        elif c == "a":
            power_supply_set(dev, True, False)
        elif c == "d":
            power_supply_set(dev, False, True)
        elif c == "n":
            power_supply_set(dev, False, False)
        elif c == "s":
            analog, digital = power_supply_get(dev)
            print("Analog: " + ("Enabled" if analog else "Disabled"))
            print("Digital: " + ("Enabled" if digital else "Disabled"))
        elif c == "e":
            break;
        else:
            print("unknown command: " + c)
except KeyboardInterrupt: pass

#turn all supply off
power_supply_set(dev, False, False)

#close device
del dev