API for analog to digital converter device drivers
Object filename description:
signal.adc.model.spin2
model indicates the manufacturer's model number of the ADC
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:
-
For SPI-connected sensors:
startx(CS_PIN, SCK_PIN, MOSI_PIN, MISO_PIN, SPI_FREQ): status
SPI_FREQ
defaults to 1MHz, if unspecified.- For some devices, a
MODEL_SPI_BC
variant exists, which directs the driver to use a bytecode-based engine that while much slower, doesn't use another cog. - For SPI-connected sensors: 4-wire SPI is used by default. If supported by the device,
3-wire SPI can be chosen by setting
MOSI_PIN
andMISO_PIN
to the same I/O pin. Thestartx()
method will check for this and set the device's 3-wire SPI mode register.
-
For I2C-connected sensors:
startx(SCL_PIN, SDA_PIN, I2C_FREQ, ADDR_BITS): status
- For some devices, a
MODEL_I2C_BC
variant exists, which directs the driver to use a bytecode-based engine that while much slower, doesn't use another cog. - Not all devices support alternate I2C addresses.
-
startx()
returns the launched cog number+1 of com engine used on success. -
startx()
returnsFALSE
(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
-
defaults()
may simply callreset()
, if sensible, as opposed to calling several other driver methods, in order to reduce memory usage. -
Drivers may have one or more
preset_()
methods, that establish a set of pre-set settings. -
stop()
performs the following tasks:- Stop any extra cogs that were started (if applicable)
- Clear all global variable space used to 0
Method | Description |
---|---|
adc_channel() |
Get currently set ADC channel |
adc_data() |
Bus voltage ADC word |
adc2volts() |
Convert bus voltage ADC word to voltage |
set_adc_channel() |
Set ADC channel for subsequent reads |
voltage() |
Bus voltage measurement |
Get currently set ADC channel
- Parameters: none
- Returns: currently set ADC channel
Bus voltage ADC word
- Parameters: none
- Returns: ADC word representing voltage
Convert bus voltage ADC word to voltage
- Parameters:
adc_wd
: ADC word representing voltage - Returns: voltage in microvolts
Set ADC channel for subsequent reads
- Parameters:
ch
: new channel number - Returns: none
Bus voltage measurement
- Parameters: none
- Returns: voltage in microvolts
Notes:
- uV = microvolts
- Some devices may include additional methods (e.g., for interrupt support)
signal.adc.model.spin - driver object
|-- #include: signal.adc.common.spinh - provides standard API
|-- OBJ: HW-specific constants (core.con.model.spin)
|-- OBJ: Low-level communications engine (I2C, SPI, OneWire, etc)