Compare commits

...

3 Commits

Author SHA1 Message Date
e847304d23 Fixed indentation 2019-11-05 20:53:18 -07:00
9f20dee3ab Added plot of diode data 2019-11-04 16:44:56 -07:00
189313a53c Added some comments. 2019-11-04 16:44:49 -07:00
6 changed files with 351 additions and 31 deletions

11
lab_3/data/diode.dat Normal file
View File

@ -0,0 +1,11 @@
# Temperature (C) Diode Value
68 364
67 367
58 382
52 390
49 396
43 405
42 408
37 415
33 422
25 438

13
lab_3/data/diode.gplot Normal file
View File

@ -0,0 +1,13 @@
set key off
set xlabel 'Temperature (°C)'
set ylabel 'ADC Value'
f(x) = a*x +b
fit f(x) 'diode.dat' using 1:2 via a, b
set term pngcairo
set output 'diode.png'
p f(x) lt rgb "black" dt 2, \
'diode.dat' using 1:2 lc rgb "black"

BIN
lab_3/data/diode.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

288
lab_3/data/fit.log Normal file
View File

@ -0,0 +1,288 @@
*******************************************************************************
Mon Nov 4 15:58:15 2019
FIT: data read from 'diode.dat' using 1:2
format = x:z
#datapoints = 10
residuals are weighted equally (unit weight)
function used for fitting: f(x)
f(x) = a*x +b
fitted parameters initialized with current variable values
iter chisq delta/lim lambda a b
0 1.2400030000e+06 0.00e+00 3.48e+01 1.000000e+00 1.000000e+00
6 9.6489173663e+00 -2.10e-08 3.48e-05 -1.668582e+00 4.777908e+02
After 6 iterations the fit converged.
final sum of squares of residuals : 9.64892
rel. change during last iteration : -2.10241e-13
degrees of freedom (FIT_NDF) : 8
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.09823
variance of residuals (reduced chisquare) = WSSR/ndf : 1.20611
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -1.66858 +/- 0.02581 (1.547%)
b = 477.791 +/- 1.272 (0.2662%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.962 1.000
*******************************************************************************
Mon Nov 4 15:58:43 2019
FIT: data read from 'diode.dat' using 1:2
format = x:z
#datapoints = 10
residuals are weighted equally (unit weight)
function used for fitting: f(x)
f(x) = a*x +b
fitted parameters initialized with current variable values
iter chisq delta/lim lambda a b
0 1.2400030000e+06 0.00e+00 3.48e+01 1.000000e+00 1.000000e+00
6 9.6489173663e+00 -2.10e-08 3.48e-05 -1.668582e+00 4.777908e+02
After 6 iterations the fit converged.
final sum of squares of residuals : 9.64892
rel. change during last iteration : -2.10241e-13
degrees of freedom (FIT_NDF) : 8
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.09823
variance of residuals (reduced chisquare) = WSSR/ndf : 1.20611
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -1.66858 +/- 0.02581 (1.547%)
b = 477.791 +/- 1.272 (0.2662%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.962 1.000
*******************************************************************************
Mon Nov 4 15:59:43 2019
FIT: data read from 'diode.dat' using 1:2
format = x:z
#datapoints = 10
residuals are weighted equally (unit weight)
function used for fitting: f(x)
f(x) = a*x +b
fitted parameters initialized with current variable values
iter chisq delta/lim lambda a b
0 1.2400030000e+06 0.00e+00 3.48e+01 1.000000e+00 1.000000e+00
6 9.6489173663e+00 -2.10e-08 3.48e-05 -1.668582e+00 4.777908e+02
After 6 iterations the fit converged.
final sum of squares of residuals : 9.64892
rel. change during last iteration : -2.10241e-13
degrees of freedom (FIT_NDF) : 8
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.09823
variance of residuals (reduced chisquare) = WSSR/ndf : 1.20611
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -1.66858 +/- 0.02581 (1.547%)
b = 477.791 +/- 1.272 (0.2662%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.962 1.000
*******************************************************************************
Mon Nov 4 16:00:07 2019
FIT: data read from 'diode.dat' using 1:2
format = x:z
#datapoints = 10
residuals are weighted equally (unit weight)
function used for fitting: f(x)
f(x) = a*x +b
fitted parameters initialized with current variable values
iter chisq delta/lim lambda a b
0 1.2400030000e+06 0.00e+00 3.48e+01 1.000000e+00 1.000000e+00
6 9.6489173663e+00 -2.10e-08 3.48e-05 -1.668582e+00 4.777908e+02
After 6 iterations the fit converged.
final sum of squares of residuals : 9.64892
rel. change during last iteration : -2.10241e-13
degrees of freedom (FIT_NDF) : 8
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.09823
variance of residuals (reduced chisquare) = WSSR/ndf : 1.20611
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -1.66858 +/- 0.02581 (1.547%)
b = 477.791 +/- 1.272 (0.2662%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.962 1.000
*******************************************************************************
Mon Nov 4 16:00:31 2019
FIT: data read from 'diode.dat' using 1:2
format = x:z
#datapoints = 10
residuals are weighted equally (unit weight)
function used for fitting: f(x)
f(x) = a*x +b
fitted parameters initialized with current variable values
iter chisq delta/lim lambda a b
0 1.2400030000e+06 0.00e+00 3.48e+01 1.000000e+00 1.000000e+00
6 9.6489173663e+00 -2.10e-08 3.48e-05 -1.668582e+00 4.777908e+02
After 6 iterations the fit converged.
final sum of squares of residuals : 9.64892
rel. change during last iteration : -2.10241e-13
degrees of freedom (FIT_NDF) : 8
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.09823
variance of residuals (reduced chisquare) = WSSR/ndf : 1.20611
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -1.66858 +/- 0.02581 (1.547%)
b = 477.791 +/- 1.272 (0.2662%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.962 1.000
*******************************************************************************
Mon Nov 4 16:01:04 2019
FIT: data read from 'diode.dat' using 1:2
format = x:z
#datapoints = 10
residuals are weighted equally (unit weight)
function used for fitting: f(x)
f(x) = a*x +b
fitted parameters initialized with current variable values
iter chisq delta/lim lambda a b
0 1.2400030000e+06 0.00e+00 3.48e+01 1.000000e+00 1.000000e+00
6 9.6489173663e+00 -2.10e-08 3.48e-05 -1.668582e+00 4.777908e+02
After 6 iterations the fit converged.
final sum of squares of residuals : 9.64892
rel. change during last iteration : -2.10241e-13
degrees of freedom (FIT_NDF) : 8
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.09823
variance of residuals (reduced chisquare) = WSSR/ndf : 1.20611
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -1.66858 +/- 0.02581 (1.547%)
b = 477.791 +/- 1.272 (0.2662%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.962 1.000
*******************************************************************************
Mon Nov 4 16:01:25 2019
FIT: data read from 'diode.dat' using 1:2
format = x:z
#datapoints = 10
residuals are weighted equally (unit weight)
function used for fitting: f(x)
f(x) = a*x +b
fitted parameters initialized with current variable values
iter chisq delta/lim lambda a b
0 1.2400030000e+06 0.00e+00 3.48e+01 1.000000e+00 1.000000e+00
6 9.6489173663e+00 -2.10e-08 3.48e-05 -1.668582e+00 4.777908e+02
After 6 iterations the fit converged.
final sum of squares of residuals : 9.64892
rel. change during last iteration : -2.10241e-13
degrees of freedom (FIT_NDF) : 8
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.09823
variance of residuals (reduced chisquare) = WSSR/ndf : 1.20611
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -1.66858 +/- 0.02581 (1.547%)
b = 477.791 +/- 1.272 (0.2662%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.962 1.000
*******************************************************************************
Mon Nov 4 16:33:45 2019
FIT: data read from 'diode.dat' using 1:2
format = x:z
#datapoints = 10
residuals are weighted equally (unit weight)
function used for fitting: f(x)
f(x) = a*x +b
fitted parameters initialized with current variable values
iter chisq delta/lim lambda a b
0 1.2400030000e+06 0.00e+00 3.48e+01 1.000000e+00 1.000000e+00
6 9.6489173663e+00 -2.10e-08 3.48e-05 -1.668582e+00 4.777908e+02
After 6 iterations the fit converged.
final sum of squares of residuals : 9.64892
rel. change during last iteration : -2.10241e-13
degrees of freedom (FIT_NDF) : 8
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 1.09823
variance of residuals (reduced chisquare) = WSSR/ndf : 1.20611
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -1.66858 +/- 0.02581 (1.547%)
b = 477.791 +/- 1.272 (0.2662%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.962 1.000

View File

@ -25,10 +25,10 @@ void pin_init() {
} }
/** @brief Initializes ADC with required settings /** @brief Initializes ADC with required settings
*/ */
void adc_init() { void adc_init() {
/* ADC Settings /* ADC Settings
* Use AVcc as Vref * Use 1v1 reference as Vref
* Initially set input as GND * Initially set input as GND
* Data right-adjusted * Data right-adjusted
* No Interrupts * No Interrupts
@ -46,6 +46,10 @@ void adc_init() {
* *
* @note Blocks until conversion finishes, so speed of this function is dependant * @note Blocks until conversion finishes, so speed of this function is dependant
* on ADC prescaler. * on ADC prescaler.
*
* @param adc_selection Value from 0-5, selects from ADC[0-5]
*
* @return Raw value of ADC conversion
*/ */
uint16_t adc_run_conversion(uint8_t adc_selection) { uint16_t adc_run_conversion(uint8_t adc_selection) {
// Select ADC input, using // Select ADC input, using
@ -58,21 +62,27 @@ uint16_t adc_run_conversion(uint8_t adc_selection) {
while (!(ADCSRA & (1 << ADIF))); while (!(ADCSRA & (1 << ADIF)));
// Read out conversion value // Read out conversion value
// may not be correct
return ADC; return ADC;
} }
/** @brief Converts an ADC value from a measurement on an LM35 into a temperature. /** @brief Converts an ADC value from a measurement on an LM35 into a temperature.
*
* @param adc_reading Raw ADC measurement from LM35.
*
* @return Measured temperature, configure parameters in main.h
*/ */
int8_t lm35_convert(uint16_t adc_reading) { int8_t lm35_convert(uint16_t adc_reading) {
return (adc_reading * ADC_VREF / ADC_RESOLUTION) / LM35_SENSITIVITY; return (adc_reading * ADC_VREF / ADC_RESOLUTION) / LM35_SENSITIVITY;
} }
/** @brief Converts and ADC value from a measurement on a diode into a temperature. /** @brief Converts and ADC value from a measurement on a diode into a temperature.
*
* @param adc_reading Raw ADC measurement from diode.
*
* @return Measured temperature, configure parameters in main.h
*/ */
int8_t diode_convert(uint16_t adc_reading) { int8_t diode_convert(uint16_t adc_reading) {
// This could be collapsed but it doesn't really matter
int16_t value_diff = adc_reading - DIODE_VALUE_25C; int16_t value_diff = adc_reading - DIODE_VALUE_25C;
int16_t temp_diff = value_diff / DIODE_SENSITIVITY; int16_t temp_diff = value_diff / DIODE_SENSITIVITY;
return temp_diff + 25; return temp_diff + 25;
@ -113,6 +123,7 @@ int main() {
// Display diode info on LCD // Display diode info on LCD
lcd_puts((const char*) diode_string); lcd_puts((const char*) diode_string);
// Refreshing too fast can make the data appear weird
_delay_ms(500); _delay_ms(500);
} }

View File

@ -7,14 +7,11 @@
#include <stdio.h> #include <stdio.h>
#include "lcd.h" #include "lcd.h"
// Comment out to run in "normal" mode
#define CALIBRATION
#define ADC_VREF 1.1 #define ADC_VREF 1.1
#define ADC_RESOLUTION 1023 // (2^ 10 - 1, 10 bits resolution) #define ADC_RESOLUTION 1023 // (2^ 10 - 1, 10 bits resolution)
#define DIODE_VALUE_25C 436 // ADC value for diode at 0C #define DIODE_VALUE_25C 440 // ADC value for diode at 0C
#define DIODE_SENSITIVITY -1.85 // ADC value / degree C, tuneable #define DIODE_SENSITIVITY -1.66 // ADC value / degree C, tuneable
#define LM35_SENSITIVITY 0.01 // V / degree C, see LM35 datasheet #define LM35_SENSITIVITY 0.01 // V / degree C, see LM35 datasheet