esp-sdr-zephyr
Raw I/Q receive and transmit on the ESP32-S3/C6 Wi-Fi radio, for Zephyr
Loading...
Searching...
No Matches
Crystal calibration

The crystal's error measured against an LTE cell and kept in flash (esp_sdr_cal.h; CONFIG_ESP_SDR_LTE_CAL measures, CONFIG_ESP_SDR_CALSTORE stores). More...

Data Structures

struct  esp_sdr_cal_point
struct  esp_sdr_cal_record
struct  esp_sdr_lte_scan
struct  esp_sdr_lte_result

Macros

#define ESP_SDR_CAL_TEMP_UNKNOWN   INT16_MIN
#define ESP_SDR_CAL_POINTS   8
#define ESP_SDR_CAL_POINT_MERGE_DC   20
#define ESP_SDR_CAL_EXTRAPOLATE_DC   100
#define ESP_SDR_CAL_QUADRATIC_SPAN_DC   100
#define ESP_SDR_LTE_SCAN_DEFAULT

Functions

static void esp_sdr_cal_add_point (struct esp_sdr_cal_record *rec, int16_t temp_dc, int32_t ppb)
 Add a measurement to a record's points.
static int esp_sdr_cal_eval (const struct esp_sdr_cal_record *rec, int16_t temp_dc, int32_t *ppb)
 The crystal's error at a temperature, from a record's points.
int esp_sdr_set_freq_corr_model (const struct esp_sdr_cal_record *rec)
 Correct tuning with a record's temperature model.
void esp_sdr_get_freq_corr_model (struct esp_sdr_cal_record *rec)
 The calibration in force: the record esp_sdr_set_freq_corr_model() took, or for a constant correction (esp_sdr_set_freq_corr_ppb()) a record without points of that ppb.
int esp_sdr_cal_update (const struct esp_sdr_cal_record *meas, struct esp_sdr_cal_record *out)
 Take a measured crystal error into the correction in force, and store it.
int esp_sdr_lte_calibrate (const struct esp_sdr_lte_scan *scan, struct esp_sdr_lte_result *res)
 Measure the crystal's error against an LTE cell and apply it.

Detailed Description

The crystal's error measured against an LTE cell and kept in flash (esp_sdr_cal.h; CONFIG_ESP_SDR_LTE_CAL measures, CONFIG_ESP_SDR_CALSTORE stores).

Guide: Crystal calibration.

Macro Definition Documentation

◆ ESP_SDR_CAL_EXTRAPOLATE_DC

#define ESP_SDR_CAL_EXTRAPOLATE_DC   100

The model is not extrapolated further than this beyond its points, 0.1 degC.

◆ ESP_SDR_CAL_POINT_MERGE_DC

#define ESP_SDR_CAL_POINT_MERGE_DC   20

A measurement replaces a point this close in temperature, 0.1 degC.

◆ ESP_SDR_CAL_POINTS

#define ESP_SDR_CAL_POINTS   8

Calibration points (temperature, error) a record keeps for the temperature model.

◆ ESP_SDR_CAL_QUADRATIC_SPAN_DC

#define ESP_SDR_CAL_QUADRATIC_SPAN_DC   100

The points must span this much for a quadratic fit (with 3 or more), 0.1 degC.

◆ ESP_SDR_CAL_TEMP_UNKNOWN

#define ESP_SDR_CAL_TEMP_UNKNOWN   INT16_MIN

No temperature known for a record.

◆ ESP_SDR_LTE_SCAN_DEFAULT

#define ESP_SDR_LTE_SCAN_DEFAULT
Value:
{ \
.start_mhz = 2110, .stop_mhz = 2170, .candidates = 6, .tries = 12, .estimates = 5, \
.gain = -1, \
}

Scan defaults: LTE band 1 downlink (2110 to 2170 MHz).

Function Documentation

◆ esp_sdr_cal_add_point()

void esp_sdr_cal_add_point ( struct esp_sdr_cal_record * rec,
int16_t temp_dc,
int32_t ppb )
inlinestatic

Add a measurement to a record's points.

A point within ESP_SDR_CAL_POINT_MERGE_DC of temp_dc is replaced; with all points in use the oldest goes. The new point is the newest.

Parameters
recRecord.
temp_dcChip temperature in 0.1 degC.
ppbThe crystal's error measured there.

◆ esp_sdr_cal_eval()

int esp_sdr_cal_eval ( const struct esp_sdr_cal_record * rec,
int16_t temp_dc,
int32_t * ppb )
inlinestatic

The crystal's error at a temperature, from a record's points.

One point gives a constant, two the line through them, three or more a least-squares quadratic when they span ESP_SDR_CAL_QUADRATIC_SPAN_DC (else a least-squares line). The temperature is clamped to ESP_SDR_CAL_EXTRAPOLATE_DC beyond the points.

Parameters
recRecord.
temp_dcChip temperature in 0.1 degC.
ppbSet to the error there.
Return values
0on success.
-ENOENTif the record has no points.

◆ esp_sdr_cal_update()

int esp_sdr_cal_update ( const struct esp_sdr_cal_record * meas,
struct esp_sdr_cal_record * out )

Take a measured crystal error into the correction in force, and store it.

With a temperature the measurement becomes a point of the model in force (esp_sdr_cal_add_point()), without one the constant correction (the points go). The result is applied (esp_sdr_set_freq_corr_model()) and, with CONFIG_ESP_SDR_CALSTORE, stored. esp_sdr_lte_calibrate() ends with it; a host that measures the error itself (the WHY2025 badge's P4 for its C6) hands its measurement over the same way.

Parameters
measThe measurement: ppb, spread_ppb, carrier_khz, cell_id, estimates and temp_dc (ESP_SDR_CAL_TEMP_UNKNOWN for none); its points are not used.
outSet to the record now in force, or NULL.
Return values
0if applied and stored.
-ENOTSUPif applied, without CONFIG_ESP_SDR_CALSTORE.
-EINVALbeyond ESP_SDR_FREQ_CORR_MAX_PPB: nothing changes.
othernegative errno if applied but not stored.

◆ esp_sdr_get_freq_corr_model()

void esp_sdr_get_freq_corr_model ( struct esp_sdr_cal_record * rec)

The calibration in force: the record esp_sdr_set_freq_corr_model() took, or for a constant correction (esp_sdr_set_freq_corr_ppb()) a record without points of that ppb.

Parameters
recFilled with it.

◆ esp_sdr_lte_calibrate()

int esp_sdr_lte_calibrate ( const struct esp_sdr_lte_scan * scan,
struct esp_sdr_lte_result * res )

Measure the crystal's error against an LTE cell and apply it.

Steps the LO across the scan range by 1 MHz (steps the LO does not reach are left out: the S3 reaches down to about 1865 MHz, the C6 to about 1775), ranks the steps by received power, then captures at the strongest ones until a cell decodes (esp_sdr_lte_detect()), and collects estimates from that cell, each against where the LO is (esp_sdr_get_lo_residual_hz()). Their median, added to the correction in force, goes to esp_sdr_cal_update(): a point of the temperature model, applied and, with CONFIG_ESP_SDR_CALSTORE, stored. Takes the radio for seconds to minutes and gives it back with the frequency and gain it had. The S3 and the C5 capture 1 to 2 ms at a time, the C6 0.2 ms (80 MS/s only), so the C6 needs many more captures to catch the synchronization signals (every 5 ms). Needs CONFIG_ESP_SDR_LTE_CAL, and about 9 KiB of stack in the calling thread (rfprobe's shell thread peaks at 11.6 KiB with it on the S3).

Parameters
scanWhat to search; NULL for ESP_SDR_LTE_SCAN_DEFAULT.
resFilled with the outcome.
Return values
0on success.
-ENOENTif no cell decoded, -ERANGE if the estimates disagree.
-ENOMEMwithout the heap for the work memory.
othernegative errno from the radio.

◆ esp_sdr_set_freq_corr_model()

int esp_sdr_set_freq_corr_model ( const struct esp_sdr_cal_record * rec)

Correct tuning with a record's temperature model.

With points, the correction follows the chip's temperature: every retune evaluates the model at the die temperature (esp_sdr_get_temp_dc()). Without points, or without a temperature, the record's ppb is the correction. esp_sdr_set_freq_corr_ppb() drops the model again. Retunes now.

Parameters
recRecord (copied).
Return values
0on success, also before esp_sdr_init().
-ERANGEas for esp_sdr_set_freq().