Added ADC measurements
This commit is contained in:
@ -142,6 +142,7 @@ R0 = 10000
|
|||||||
|
|
||||||
ADC_BITS_16 = 65535
|
ADC_BITS_16 = 65535
|
||||||
ADC_BITS_12 = 4095
|
ADC_BITS_12 = 4095
|
||||||
|
STM32_ADC_PIN_VREF = 3.3
|
||||||
|
|
||||||
U3V3_COEFF = 1.221e-3
|
U3V3_COEFF = 1.221e-3
|
||||||
U5V_COEFF = 1.8315e-3
|
U5V_COEFF = 1.8315e-3
|
||||||
|
|||||||
@ -14,6 +14,7 @@ from .constants import (
|
|||||||
RREF,
|
RREF,
|
||||||
BETA_INTERNAL, BETA_EXTERNAL, T0_K, R0,
|
BETA_INTERNAL, BETA_EXTERNAL, T0_K, R0,
|
||||||
ADC_BITS_16, ADC_BITS_12,
|
ADC_BITS_16, ADC_BITS_12,
|
||||||
|
STM32_ADC_PIN_VREF,
|
||||||
U3V3_COEFF, U5V_COEFF, U7V_COEFF,
|
U3V3_COEFF, U5V_COEFF, U7V_COEFF,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -112,3 +113,14 @@ def voltage_5v_n_to_v(n: int) -> float:
|
|||||||
def voltage_7v_n_to_v(n: int) -> float:
|
def voltage_7v_n_to_v(n: int) -> float:
|
||||||
"""Convert 7V rail ADC count to volts."""
|
"""Convert 7V rail ADC count to volts."""
|
||||||
return n * U7V_COEFF
|
return n * U7V_COEFF
|
||||||
|
|
||||||
|
|
||||||
|
def stm32_adc_pin_n_to_v(n: int) -> float:
|
||||||
|
"""
|
||||||
|
Convert a raw 12-bit STM32 ADC code from a direct MCU input pin to volts.
|
||||||
|
|
||||||
|
The new auxiliary telemetry channels are measured directly on PF3/PF4
|
||||||
|
without an external divider in the firmware path, so the conversion is a
|
||||||
|
plain ratio against the MCU analog reference rail.
|
||||||
|
"""
|
||||||
|
return n * STM32_ADC_PIN_VREF / ADC_BITS_12
|
||||||
|
|||||||
@ -26,6 +26,8 @@ def example_manual_mode(port: str = None):
|
|||||||
print(f" Temp2: {data.temp2:.2f} °C")
|
print(f" Temp2: {data.temp2:.2f} °C")
|
||||||
print(f" I1: {data.current1:.3f} mA")
|
print(f" I1: {data.current1:.3f} mA")
|
||||||
print(f" I2: {data.current2:.3f} mA")
|
print(f" I2: {data.current2:.3f} mA")
|
||||||
|
print(f" PF3: {data.adc_pf3_voltage:.3f} V")
|
||||||
|
print(f" PF4: {data.adc_pf4_voltage:.3f} V")
|
||||||
print(f" 3.3V: {data.voltage_3v3:.3f} V")
|
print(f" 3.3V: {data.voltage_3v3:.3f} V")
|
||||||
print(f" 5V: {data.voltage_5v1:.3f} V")
|
print(f" 5V: {data.voltage_5v1:.3f} V")
|
||||||
print(f" 7V: {data.voltage_7v0:.3f} V")
|
print(f" 7V: {data.voltage_7v0:.3f} V")
|
||||||
|
|||||||
@ -568,6 +568,8 @@ def build_status_group(owner) -> QGroupBox:
|
|||||||
("Температура 2", "_telemetry_temp2"),
|
("Температура 2", "_telemetry_temp2"),
|
||||||
("Фотодиод 1", "_telemetry_current1"),
|
("Фотодиод 1", "_telemetry_current1"),
|
||||||
("Фотодиод 2", "_telemetry_current2"),
|
("Фотодиод 2", "_telemetry_current2"),
|
||||||
|
("Напряжение PF3", "_telemetry_adc_pf3"),
|
||||||
|
("Напряжение PF4", "_telemetry_adc_pf4"),
|
||||||
("Внешняя температура 1", "_telemetry_temp_ext1"),
|
("Внешняя температура 1", "_telemetry_temp_ext1"),
|
||||||
("Внешняя температура 2", "_telemetry_temp_ext2"),
|
("Внешняя температура 2", "_telemetry_temp_ext2"),
|
||||||
("Питание 3.3 В", "_telemetry_3v3"),
|
("Питание 3.3 В", "_telemetry_3v3"),
|
||||||
|
|||||||
@ -603,6 +603,8 @@ class MainWindow(QMainWindow):
|
|||||||
self._telemetry_temp2.setText(f"{measurements.temp2:.2f} °C")
|
self._telemetry_temp2.setText(f"{measurements.temp2:.2f} °C")
|
||||||
self._telemetry_current1.setText(f"{measurements.current1:.3f} мА")
|
self._telemetry_current1.setText(f"{measurements.current1:.3f} мА")
|
||||||
self._telemetry_current2.setText(f"{measurements.current2:.3f} мА")
|
self._telemetry_current2.setText(f"{measurements.current2:.3f} мА")
|
||||||
|
self._telemetry_adc_pf3.setText(f"{measurements.adc_pf3_voltage:.3f} В")
|
||||||
|
self._telemetry_adc_pf4.setText(f"{measurements.adc_pf4_voltage:.3f} В")
|
||||||
self._telemetry_temp_ext1.setText(f"{measurements.temp_ext1:.2f} °C")
|
self._telemetry_temp_ext1.setText(f"{measurements.temp_ext1:.2f} °C")
|
||||||
self._telemetry_temp_ext2.setText(f"{measurements.temp_ext2:.2f} °C")
|
self._telemetry_temp_ext2.setText(f"{measurements.temp_ext2:.2f} °C")
|
||||||
self._telemetry_3v3.setText(f"{measurements.voltage_3v3:.3f} В")
|
self._telemetry_3v3.setText(f"{measurements.voltage_3v3:.3f} В")
|
||||||
|
|||||||
@ -35,6 +35,8 @@ class Measurements:
|
|||||||
current2: float
|
current2: float
|
||||||
temp1: float
|
temp1: float
|
||||||
temp2: float
|
temp2: float
|
||||||
|
adc_pf3_voltage: float = 0.0
|
||||||
|
adc_pf4_voltage: float = 0.0
|
||||||
temp_ext1: float | None = None
|
temp_ext1: float | None = None
|
||||||
temp_ext2: float | None = None
|
temp_ext2: float | None = None
|
||||||
voltage_3v3: float = 0.0
|
voltage_3v3: float = 0.0
|
||||||
@ -42,8 +44,6 @@ class Measurements:
|
|||||||
voltage_5v2: float = 0.0
|
voltage_5v2: float = 0.0
|
||||||
voltage_7v0: float = 0.0
|
voltage_7v0: float = 0.0
|
||||||
message_id: int | None = None
|
message_id: int | None = None
|
||||||
to6_counter_lsb: int | None = None
|
|
||||||
to6_counter_msb: int | None = None
|
|
||||||
timestamp: datetime = field(default_factory=datetime.now)
|
timestamp: datetime = field(default_factory=datetime.now)
|
||||||
|
|
||||||
def to_dict(self) -> dict[str, Any]:
|
def to_dict(self) -> dict[str, Any]:
|
||||||
@ -51,6 +51,8 @@ class Measurements:
|
|||||||
return {
|
return {
|
||||||
"current1": self.current1,
|
"current1": self.current1,
|
||||||
"current2": self.current2,
|
"current2": self.current2,
|
||||||
|
"adc_pf3_voltage": self.adc_pf3_voltage,
|
||||||
|
"adc_pf4_voltage": self.adc_pf4_voltage,
|
||||||
"temp1": self.temp1,
|
"temp1": self.temp1,
|
||||||
"temp2": self.temp2,
|
"temp2": self.temp2,
|
||||||
"temp_ext1": self.temp_ext1,
|
"temp_ext1": self.temp_ext1,
|
||||||
@ -60,8 +62,6 @@ class Measurements:
|
|||||||
"voltage_5v2": self.voltage_5v2,
|
"voltage_5v2": self.voltage_5v2,
|
||||||
"voltage_7v0": self.voltage_7v0,
|
"voltage_7v0": self.voltage_7v0,
|
||||||
"message_id": self.message_id,
|
"message_id": self.message_id,
|
||||||
"to6_counter_lsb": self.to6_counter_lsb,
|
|
||||||
"to6_counter_msb": self.to6_counter_msb,
|
|
||||||
"timestamp": self.timestamp.isoformat(),
|
"timestamp": self.timestamp.isoformat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,6 +56,7 @@ from .constants import (
|
|||||||
from .conversions import (
|
from .conversions import (
|
||||||
current_ma_to_n,
|
current_ma_to_n,
|
||||||
current_n_to_ma,
|
current_n_to_ma,
|
||||||
|
stm32_adc_pin_n_to_v,
|
||||||
temp_c_to_n,
|
temp_c_to_n,
|
||||||
temp_ext_n_to_c,
|
temp_ext_n_to_c,
|
||||||
temp_n_to_c,
|
temp_n_to_c,
|
||||||
@ -456,6 +457,8 @@ class Protocol:
|
|||||||
return Measurements(
|
return Measurements(
|
||||||
current1=current_n_to_ma(words[1]),
|
current1=current_n_to_ma(words[1]),
|
||||||
current2=current_n_to_ma(words[2]),
|
current2=current_n_to_ma(words[2]),
|
||||||
|
adc_pf3_voltage=stm32_adc_pin_n_to_v(words[3]),
|
||||||
|
adc_pf4_voltage=stm32_adc_pin_n_to_v(words[4]),
|
||||||
temp1=temp_n_to_c(words[5]),
|
temp1=temp_n_to_c(words[5]),
|
||||||
temp2=temp_n_to_c(words[6]),
|
temp2=temp_n_to_c(words[6]),
|
||||||
temp_ext1=temp_ext_n_to_c(words[7]),
|
temp_ext1=temp_ext_n_to_c(words[7]),
|
||||||
@ -465,8 +468,6 @@ class Protocol:
|
|||||||
voltage_5v2=voltage_5v_n_to_v(words[11]),
|
voltage_5v2=voltage_5v_n_to_v(words[11]),
|
||||||
voltage_7v0=voltage_7v_n_to_v(words[12]),
|
voltage_7v0=voltage_7v_n_to_v(words[12]),
|
||||||
message_id=words[13],
|
message_id=words[13],
|
||||||
to6_counter_lsb=words[3],
|
|
||||||
to6_counter_msb=words[4],
|
|
||||||
timestamp=datetime.now(),
|
timestamp=datetime.now(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user