2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
9 #include "libs/Kernel.h"
12 #include "checksumm.h"
14 #include "ConfigValue.h"
15 #include "libs/Median.h"
17 #include "StreamOutputPool.h"
21 #include "MRI_Hooks.h"
25 #define AD8495_pin_checksum CHECKSUM("ad8495_pin")
26 #define AD8495_offset_checksum CHECKSUM("ad8495_offset")
38 // Get configuration from the config file
39 void AD8495::UpdateConfig(uint16_t module_checksum
, uint16_t name_checksum
)
41 // Thermistor pin for ADC readings
42 this->AD8495_pin
.from_string(THEKERNEL
->config
->value(module_checksum
, name_checksum
, AD8495_pin_checksum
)->required()->as_string());
43 this->AD8495_offset
= THEKERNEL
->config
->value(module_checksum
, name_checksum
, AD8495_offset_checksum
)->by_default(0)->as_number(); // Stated offset. For Adafruit board it is 250C. If pin 2(REF) of amplifier is connected to 0V then there is 0C offset.
45 THEKERNEL
->adc
->enable_pin(&AD8495_pin
);
49 float AD8495::get_temperature()
51 float t
= adc_value_to_temperature(new_AD8495_reading());
52 // keep track of min/max for M305
53 if(t
> max_temp
) max_temp
= t
;
54 if(t
< min_temp
) min_temp
= t
;
58 void AD8495::get_raw()
61 int adc_value
= new_AD8495_reading();
62 const uint32_t max_adc_value
= THEKERNEL
->adc
->get_max_value();
63 float t
=((float)adc_value
)/(((float)max_adc_value
)/3.3*0.005);
65 t
= t
- this->AD8495_offset
;
67 THEKERNEL
->streams
->printf("adc= %d, max_adc= %lu, temp= %f, offset = %f\n", adc_value
,max_adc_value
,t
, this->AD8495_offset
);
70 min_temp
= max_temp
= t
;
73 float AD8495::adc_value_to_temperature(uint32_t adc_value
)
75 const uint32_t max_adc_value
= THEKERNEL
->adc
->get_max_value();
76 if ((adc_value
>= max_adc_value
))
79 float t
=((float)adc_value
)/(((float)max_adc_value
)/3.3*0.005);
81 t
=t
-this->AD8495_offset
;
86 int AD8495::new_AD8495_reading()
88 // filtering now done in ADC
89 return THEKERNEL
->adc
->read(&AD8495_pin
);