LogDetector

class rfblocks.LogDetector(cs: str | None = None)[source]

Create an instance of LogDetector.

Parameters:

cs (str) – The detector board chip select (~CS) controller pin.

Documentation for the LTC5582 and LT5537 power detector rfblocks modules can be found here: LTC5582 and LT5537 Power Detectors

Note

The default detector type is set to be the LTC5582. This is updated by initialize as read from the detector firmware register.

RAW_TO_MILLIVOLTS = 2.5

The ADC is 10-bits using a ref. voltage range of 0 to 2.56

property frequency_range: Tuple[float, float]

Returns the frequency range of the connected detector.

This assumes that :py:meth:initialize has been called.

initialize(ser: Serial) None[source]

Initialize the detector type and calibration data.

Parameters:

ser (serial.Serial) – serial device to write commands to

Raises:

DetectorReadError

intercept(freq: float) float[source]

Return the Vout vs RFin log intercept for a given frequency (in MHz).

Parameters:

freq (float) – frequency in MHz

Returns:

the log intercept (in dB) at the given frequency

is_connected(ser: Serial) bool[source]

Test if there is a connected detector.

Tests the value in the detector’s CAL_RECORD_COUNT_REG. If it isn’t the expected value of CAL_RECORD_COUNT then it is assumed that no detector is connected at that controller pin.

Parameters:

ser (serial.Serial) – serial device to write commands to

Returns:

True if a valid detector is connected, False otherwise.

linear_range(freq: float) Tuple[float, float][source]

The detectors linear response range (in dBm).

Parameters:

freq (float) – frequency in MHz

Returns:

A tuple containing the minimum and maximum input signal powers for which the detector provides a linear response. If no calibration data is available the rfblocks.CalibrationDataError is raised.

pin_config() str[source]

Initialize controller pin configuration.

Returns:

The command string required to configure the device controller pins.

power(ser: Serial, freq: float, avg: int = 1) float[source]

Read the current detector power.

This method will return the measured input signal power corrected using the calibration parameters stored in the detector’s on-board EEPROM.

Parameters:
  • ser (serial.Serial) – serial device to write commands to

  • freq (float) – the frequency of the signal being measured (in MHz)

  • avg (int) – the number of readings to average over. The default value is 1.

Returns:

The current detector power (in dBm) with calibration factor applied.

property power_range: Tuple[float, float]

Returns the power range of the connected detector.

This assumes that :py:meth:initialize has been called.

raw_pwr(corrected_pwr: float, freq: float) int[source]

Convert a know ‘corrected’ input power to a measured ‘raw’ power.

read_cal_data(ser: Serial) None[source]

Read calibration data from the detector board.

Initializes self.cal_data with a dictionary containing the calibration data values keyed with the frequencies at which they were measured. This calibration data is used to calculate the corrected power as measured by the detector (see power()).

Also populates the self.min_limit_coeffs and self.max_limit_coeffs which are used to calculate the linear range of the detector (see linear_range()).

Parameters:

ser (serial.Serial) – serial device to write commands to

read_detector_type(ser: Serial) None[source]

Read the detector type from the detector board.

This sets the self.detector_type attribute.

Parameters:

ser (serial.Serial) – serial device to write commands to

read_raw(ser: Serial) int[source]

Read a raw 10 bit ADC value from the detector board.

Parameters:

ser (serial.Serial) – serial device to write commands to

Returns:

The raw detector ADC value.

read_reg_byte(ser: Serial, reg: int) int[source]

Read an 8-bit integer from a specified register.

Note that it is assumed that SPI is initialized.

Parameters:
  • ser (serial.Serial) – serial device to write commands to

  • reg (int) – the register to read from

Returns:

the 8-bit integer stored in reg.

read_reg_float(ser: Serial, reg: int) float[source]

Read a 32 bit float from the specified register quad.

Note that it is assumed that SPI is initialized.

Parameters:
  • ser (serial.Serial) – serial device to write commands to

  • reg (int) – the first of the quad of registers to read from

Returns:

the 32 bit float stored in reg, reg+1, reg+2, reg+3. The float is calculated using:

b = [0x85, 0x4f, 0x6b, 0x2e]
f = struct.unpack('f', bytes(b))

read_reg_word(ser: Serial, reg: int) int[source]

Read a 16 bit integer from the specified register pair.

Note that it is assumed that SPI is initialized.

Parameters:
  • ser (serial.Serial) – serial device to write commands to

  • reg (int) – the first of the pair of registers to read from

Returns:

the 16 bit integer stored in reg, reg+1. The integer is calculated as [reg] + [reg+1]*256

set_cal_data(data: Dict[str, List[float]]) None[source]

Set the detector calibration data.

Parameters:

data (Dict[str, List[float]]) – a dict containing the calibration data. The data are the slope and log intercept of the linear portion of the detector response indexed with a string representing their frequency at which the fit was made.

Example cal. data:

{'0.0': [30.6677827385478, -82.38328220135256],
'250.0': [30.6677827385478, -82.38328220135256],
'500.0': [30.67172619194942, -82.12740330035196],
...
'3500.0': [31.015178572555065, -77.42265310955872],
'3750.0': [31.226428574568747, -76.5568104298865],
'6000.0': [31.96632362294561, -69.4423167171135]}
slope(freq: float) float[source]

Return the Vout vs RFin slope for a given frequency (in MHz).

Parameters:

freq (float) – frequency in MHz

Returns:

the slope (in mV/dB) at the given frequency

vout(ser: Serial, avg: int = 1) float[source]

Read the current detector output voltage.

Parameters:

ser (serial.Serial) – serial device to write commands to

Returns:

The current detector output voltage in millivolts.