add comments

This commit is contained in:
2023-10-12 22:15:24 +01:00
parent eb97dc0f60
commit a602f20e01
4 changed files with 50 additions and 31 deletions

View File

@@ -17,7 +17,7 @@
float adc_to_voltage(int n_adc);
float kelvin_to_c(float k);
float resistance_to_temperature(float r);
float voltage_to_resistance(float v);
float voltage_to_thermistor_resistance(float v);
float voltage_to_erc(float v);
void setup()
@@ -34,12 +34,12 @@ void loop()
thermistor_val = analogRead(ThermistorPin);
thermocouple_val = analogRead(TCpin)
// Calculate thermistor temperature in degrees C ( Part b, i,ii,iii & v)
thermistor_temp = kelvin_to_c(resistance_to_temperature(voltage_to_resistance(adc_to_voltage(thermistor_val))));
thermistor_temp = kelvin_to_c(resistance_to_temperature(voltage_to_thermistor_resistance(adc_to_voltage(thermistor_val))));
// Calculate thermocouple temperature in degrees C ( Part c, i - iv)
e_rc = 1000*voltage_to_erc(adc_to_voltage(thermocouple_val)); // convert to millivolts
e_comp = NISTdegCtoMilliVoltsKtype(thermistor_temp);
thermocouple_temp = NISTmilliVoltsToDegCKtype(e_rc + e_comp);
e_comp = NISTdegCtoMilliVoltsKtype(thermistor_temp); // eqn (6) lab prep sheet
thermocouple_temp = NISTmilliVoltsToDegCKtype(e_rc + e_comp); // eqn (7) lab prep sheet
/* Display results. Don't use printf or formatting etc., they don't work on the Arduino. Just use
the serial print statements given here, inserting your own code as needed */
@@ -55,7 +55,7 @@ void loop()
/* Write a function to convert ADC value to
voltage: put it here and use it in your code above*/
float adc_to_voltage(int n_adc) {
return (float)n_adc*V_REF/1024.0;
return (float)n_adc*V_REF/1024.0; // eqn (1) lab prep sheet
}
@@ -66,23 +66,29 @@ float kelvin_to_c(float k) {
}
float resistance_to_temperature(float r) {
// Convert Resistance (Ohms) to Temperature (Kelvin) (for thermistor)
float resistance_to_thermistor_temperature(float r) {
// Define Thermistor constants
float t_0 = 298.15;
float r_0 = 10000;
float b = 3975;
float t_0 = 298.15; // Kelvin
float r_0 = 10000; // Ohms
float b = 3975; // Kelvin
return 1.0 / ( (1.0/t_0) + (1.0/b)*log(r/r_0));
return 1.0 / ( (1.0/t_0) + (1.0/b)*log(r/r_0)); // eqn (3) lab prep sheet
}
float voltage_to_resistance(float v) {
return 1000*((10.0*3.3/v)-10.0);
// Convert Voltage (Volts) to Resistance (Ohms)
float voltage_to_thermistor_resistance(float v) {
float pull_down_resistance = 10; // kOhms
float v_hi = 3.3; // Volts
return 1000*((pull_down_resistance*v_hi/v)-10.0); // eqn (4) lab prep sheet
}
// Convert Voltage to E_RC
float voltage_to_erc(float v) {
return (v-0.35)/54.4;
return (v-0.35)/54.4; // eqn (5) lab prep sheet
}