Skip to content

Commit

Permalink
Use AD8494 Thermocouple Amplifier for temperature
Browse files Browse the repository at this point in the history
We are no longer using a Type K thermocouple.
  • Loading branch information
AlexanderWells-diamond committed Mar 19, 2024
1 parent fd851c6 commit fa26359
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/psc_datalogger/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pyvisa.resources import Resource, SerialInstrument

from .statusbar import StatusBar
from .thermocouple.thermocouple import volts_to_celcius
from .temperature.converter import volts_to_celcius


class ConnectionManager:
Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions src/psc_datalogger/temperature/converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Handles converting millivolt readings into degrees Celcius for an Analog Devices
# AD8494 Thermocouple Amplifier
"""
The equation governing this is specified as:
V_OUT = (T_MJ * 5 mV/°C) + V_REF
where
- T_MJ is the thermocouple measurement junction temperature.
- V_OUT is the measured output voltage
- V_REF is the reference voltage, which has been configured to 0 on the hardware.
Substituting V_REF=0 and rearranging this equation gives:
T_MJ = V_OUT / 5 mV
i.e. every 5 mV gives 1 degree celcius increase
"""


def volts_to_celcius(volts: str) -> float:
# Convert to millivolts
mv = float(volts) * 1000
temp = mv / 5.0
# Check the result is at least vaguely sensible
assert -10.0 <= temp <= 60.0
return temp
54 changes: 0 additions & 54 deletions src/psc_datalogger/thermocouple/thermocouple.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def test_query_instruments_temperature(
address = 22
worker.instrument_addresses[1] = InstrumentConfig(address, convert_to_temp=True)
voltage_str = "1E-03"
temperature = "24.993219514361623" # degrees Celcius, calculated
temperature = "0.2" # degrees Celcius, calculated from voltage_str
mocked_write = MagicMock()
mocked_query = MagicMock(return_value=voltage_str)
worker.connection = MagicMock()
Expand Down
18 changes: 9 additions & 9 deletions tests/test_thermocouple.py → tests/test_temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from psc_datalogger.thermocouple.thermocouple import volts_to_celcius
from psc_datalogger.temperature.converter import volts_to_celcius

# Tests for the thermocouple voltage -> degrees Celcius conversion.

Expand All @@ -11,24 +11,24 @@


@pytest.mark.parametrize(
"input_millivolts, expected_temp",
"input_volts, expected_temp",
[
(-0.392 * 10**-3, -10),
(0.0 * 10**-3, 0.0),
(1.203 * 10**-3, 30),
(2.395 * 10**-3, 59),
(0.2, 40.0),
(-0.01, -2.0),
(0.0, 0.0),
(0.11, 22.0),
],
)
def test_volts_to_celcius_valid(input_millivolts, expected_temp):
def test_volts_to_celcius_valid(input_volts, expected_temp):
"""Test that a handful of millivolt readings produce the correct output temperature
to within TOLERANCE."""
calculated_temp = volts_to_celcius(input_millivolts)
calculated_temp = volts_to_celcius(input_volts)
assert math.isclose(expected_temp, calculated_temp, abs_tol=TOLERANCE)


@pytest.mark.parametrize(
"invalid_value",
[-1 * 10**-3, -0.393 * 10**-3, 2.396 * 10**-3, 3 * 10**-3, 10 * 10**-3],
[-5.1 * 10**-2, 3.1 * 10**-1],
)
def test_volts_to_celcius_invalid_values(invalid_value):
"""Test that various values are all invalid i.e. outside modelled range"""
Expand Down

0 comments on commit fa26359

Please sign in to comment.