Skip to content

Latest commit

 

History

History
173 lines (125 loc) · 4.53 KB

sensor.power.md

File metadata and controls

173 lines (125 loc) · 4.53 KB

sensor.power


API for power consumption/metering device drivers

Object filename description:

sensor.type.model.spin2

type is one of: power, current

model indicates the manufacturer's model number of the device

Base Methods

These are methods that are common to all power sensor drivers

Method Description Param Returns
startx() Start driver using explicitly defined settings Notes 1-3 cog id+1
stop() Stop the driver n/a n/a
defaults() Set sensor factory default settings n/a n/a

Notes:

  1. For I2C-connected sensors:

    • startx(SCL_PIN, SDA_PIN, I2C_FREQ, ADDR_BITS): status
    • Not all devices support alternate I2C addresses.
  2. startx() returns the launched cog number+1 of com engine used on success.

  3. startx() returns FALSE (0) if the driver fails to start, for these possible reasons:

    • No more cogs available
    • One or more specified I/O pins are outside allowed range
    • Bus frequency is outside allowed range
    • If supported by the device, dev_id() didn't return the expected value
  4. defaults() may simply call reset(), if sensible, as opposed to calling several other driver methods, in order to reduce memory usage.

  5. Drivers may have one or more preset_() methods, that establish a set of pre-set settings.

  6. stop() performs the following tasks:

    • Stop any extra cogs that were started (if applicable)
    • Clear all global variable space used to 0

Methods

Method Description
adc2amps() Convert current ADC word to amperage
adc2volts() Convert bus voltage ADC word to voltage
adc2watts() Convert power ADC word to wattage
current() Current measurement
current_data() Current ADC word
dev_id() Model-specific identification
opmode() Set operating mode
power() Power measurement
power_data() Power ADC word
reset() Reset device
voltage() Bus voltage measurement
voltage_data() Bus voltage ADC word

adc2amps(adc_wd)

Convert current ADC word to amperage

  • Parameters:
    • adc_wd: adc word
  • Returns:
    • current in microamperes

adc2volts()

Convert bus voltage ADC word to voltage

  • Parameters:
    • adc_wd: adc word
  • Returns:
    • voltage in microvolts

adc2watts(adc_wd)

Convert power ADC word to wattage

  • Parameters:
    • adc_wd: adc word
  • Returns:
    • power in microwatts

current()

Current measurement

  • Parameters: none
  • Returns: current in microamperes

current_data()

Current ADC word

  • Parameters: none
  • Returns: ADC word representing current

dev_id()

Device identification

  • Parameters: n/a
  • Returns: model-specific identification

opmode(mode)

Set operating mode

  • Parameters:
    • mode: new operating mode
  • Returns:
    • current operating mode

power()

Power measurement

  • Parameters: none
  • Returns:
    • power measurement in microwatts

power_data()

Power ADC word

  • Parameters: none
  • Returns: ADC word representing power measurement

reset()

Reset device

  • Parameters: none
  • Returns: none NOTE: Some devices may require an additional I/O pin to perform a reset.

voltage()

Bus voltage measurement

  • Parameters: none
  • Returns: voltage in microvolts

voltage_data()

Bus voltage ADC word

  • Parameters: none
  • Returns: ADC word representing voltage

Notes:

  1. uA = microamperes, uV = microvolts, uW = microwatts
  2. Some devices may include additional methods (e.g., for interrupt support)

File Structure

sensor.power.model.spin2 - driver object
|-- #include: sensor.power.common.spin2h - provides standard API
|-- OBJ: HW-specific constants (core.con.model.spin)
|-- OBJ: Low-level communications engine (I2C, SPI, OneWire, etc)