add comments
This commit is contained in:
@@ -9,8 +9,8 @@ float NISTmilliVoltsToDegCKtype(float tcEMFmV); // returns temp in degC assumin
|
||||
|
||||
float adc_to_voltage(float v_ref, int n_adc);
|
||||
float kelvin_to_c(float k);
|
||||
float resistance_to_temperature(float r);
|
||||
float voltage_to_resistance(float v);
|
||||
float resistance_to_thermistor_temperature(float r);
|
||||
float voltage_to_thermistor_resistance(float v);
|
||||
float voltage_to_erc(float v);
|
||||
|
||||
int main()
|
||||
@@ -23,12 +23,12 @@ int main()
|
||||
scanf("%d %d", &thermistor_val, &thermocouple_val);
|
||||
|
||||
// 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(v_ref, thermistor_val))));
|
||||
thermistor_temp = kelvin_to_c(resistance_to_thermistor_temperature(voltage_to_thermistor_resistance(adc_to_voltage(v_ref, thermistor_val))));
|
||||
|
||||
// Calculate thermocouple temperature in degrees C ( Part c, i - iv)
|
||||
e_rc = 1000*voltage_to_erc(adc_to_voltage(v_ref, 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
|
||||
|
||||
|
||||
// Output results
|
||||
@@ -42,7 +42,7 @@ int main()
|
||||
/* Write a function here to convert ADC value to voltages. (Part a, equation 1)
|
||||
Call it from the main() function above */
|
||||
float adc_to_voltage(float v_ref, int n_adc) {
|
||||
return (float)n_adc*v_ref/1024.0;
|
||||
return (float)n_adc*v_ref/1024.0; // eqn (1) lab prep sheet
|
||||
}
|
||||
|
||||
|
||||
@@ -54,23 +54,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
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user