diff --git a/.vs/TE_Controller/v14/.atsuo b/.vs/TE_Controller/v14/.atsuo index 9cb040c..f67343c 100644 Binary files a/.vs/TE_Controller/v14/.atsuo and b/.vs/TE_Controller/v14/.atsuo differ diff --git a/TE_Controller/TE_Controller.cproj b/TE_Controller/TE_Controller.cproj index 209b33d..786d9f4 100644 --- a/TE_Controller/TE_Controller.cproj +++ b/TE_Controller/TE_Controller.cproj @@ -30,330 +30,330 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.atmel.avrdbg.tool.atmelice J41800067100 @@ -371,6 +371,7 @@ Atmel-ICE 2000000 + true @@ -671,7 +672,7 @@ True - -Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam0/utils/linker_scripts/samd21/gcc/samd21e16b_flash.ld + -Wl,--entry=Reset_Handler -Wl,--cref -mthumb -Wl,-u,vfprintf -T../src/ASF/sam0/utils/linker_scripts/samd21/gcc/samd21e16b_flash.ld ../src diff --git a/TE_Controller/src/include/ntc.h b/TE_Controller/src/include/ntc.h index 38890db..b952a5c 100644 --- a/TE_Controller/src/include/ntc.h +++ b/TE_Controller/src/include/ntc.h @@ -19,7 +19,7 @@ float NTC_R2T(float R); // Read ADC and calculate temperature in Cenlsius. - float NTC_MCU_get_temp(void); + float NTC_MCU_get_temp(uint16_t *p_adc_val); float NTC_TEC_get_temp(uint16_t *p_value, float *p_R); diff --git a/TE_Controller/src/main.c b/TE_Controller/src/main.c index 8e1ebcf..3ea5eff 100644 --- a/TE_Controller/src/main.c +++ b/TE_Controller/src/main.c @@ -42,10 +42,12 @@ //#include #include "realsence.h" #include "ntc.h" +#include #define PORT_STDIO 0 #define PORT_DATA 1 +uint16_t adc_value = 100; //char rcvBuff[128] = {0}; char str[128] = {0}; UBaseType_t uxHighWaterMark_cdc_rx_check; @@ -173,18 +175,22 @@ void Task_led_blink(void *parameters) } void Task_mesure(void *parameters) -{ +{ uxHighWaterMark_mesure = uxTaskGetStackHighWaterMark( NULL ); for (;;) { - Controller.temps.MCU_Temp = NTC_MCU_get_temp(); + Controller.temps.MCU_Temp = NTC_MCU_get_temp(NULL); if (main_b_cdc_enable && udi_cdc_multi_is_tx_ready(PORT0)) - printf(">%f\n\r", Controller.temps.MCU_Temp); + { + if(fpclassify(Controller.temps.MCU_Temp) == FP_NAN) + printf(">NTC_TEMP = NAN\n\r"); + else + printf(">NTC_TEMP = %d\n\r", (int)Controller.temps.MCU_Temp ); + } LED_Toggle(LED_PIN); uxHighWaterMark_mesure = uxTaskGetStackHighWaterMark( NULL ); vTaskDelay(1000); - } - + } } void InitTask_led_blink(void) diff --git a/TE_Controller/src/source/adc_user.c b/TE_Controller/src/source/adc_user.c index 0b8844e..20a1bb2 100644 --- a/TE_Controller/src/source/adc_user.c +++ b/TE_Controller/src/source/adc_user.c @@ -11,6 +11,12 @@ struct adc_module adc_instance; void configure_adc(void) { struct adc_config config_adc; + /*ADC_GAINCORR_Type gainCorr = { + .bit.GAINCORR = 1 + }; + ADC_OFFSETCORR_Type offsetCorr = { + .reg = -52 + };*/ adc_get_config_defaults(&config_adc); config_adc.positive_input = ADC_POSITIVE_INPUT_PIN1; @@ -19,22 +25,34 @@ void configure_adc(void) config_adc.resolution = ADC_RESOLUTION_12BIT; config_adc.gain_factor = ADC_GAIN_FACTOR_1X; + config_adc.freerunning = true; + config_adc.correction.correction_enable = true; + config_adc.correction.offset_correction = -16;//ADC_OFFSETCORR_OFFSETCORR(offsetCorr.reg);// + config_adc.correction.gain_correction = (1<<11);//1.0ADC_GAINCORR_GAINCORR(gainCorr.reg);// + config_adc.gain_factor = ADC_GAIN_FACTOR_DIV2; config_adc.clock_prescaler = ADC_CLOCK_PRESCALER_DIV512; // prescaler influence to accuracy of measures. Don't set less then 32 adc_init(&adc_instance, ADC, &config_adc); adc_enable(&adc_instance); + adc_start_conversion(&adc_instance); } -uint16_t adc_read_value(void){ +uint16_t adc_read_value(void) +{ + uint16_t result = 0xFFFF; + adc_read(&adc_instance, &result); + return result; +} +/*uint16_t adc_read_value(void){ adc_start_conversion(&adc_instance); uint16_t result; do { - /* Wait for conversion to be done and read out result */ + } while (adc_read(&adc_instance, &result) == STATUS_BUSY); return result; -} +}*/ uint16_t adc_read_value_spec(ADC_chan_t chan) { diff --git a/TE_Controller/src/source/adn8831.c b/TE_Controller/src/source/adn8831.c index 282a4db..6af6c49 100644 --- a/TE_Controller/src/source/adn8831.c +++ b/TE_Controller/src/source/adn8831.c @@ -34,7 +34,7 @@ void ADN8831_control(void){ TEC_set_TEMPSET_volt(0.9); // MCU temp - float t = NTC_MCU_get_temp(); + float t = NTC_MCU_get_temp(NULL); make_float2str(t_MCU_str, MAX_STR_FLOAT, (float)t); diff --git a/TE_Controller/src/source/ntc.c b/TE_Controller/src/source/ntc.c index 8a12b83..ada63e0 100644 --- a/TE_Controller/src/source/ntc.c +++ b/TE_Controller/src/source/ntc.c @@ -5,11 +5,20 @@ * Author: Lexus */ #include "ntc.h" -#include +#include #define MCU_CONTROL // ADC value to R +/*float NTC_MCU_value2R(uint16_t value) +{ + float R10 = 17800.0; + float R11 = 7680.0; + + float Vadc = value*3.3/1.48/4096; + float res = (Vadc*(R10+R11) -3.3*R11)/(3.3-Vadc); + return res; +}*/ float NTC_MCU_value2R(uint16_t value) { float R10 = 17800.0; @@ -17,7 +26,8 @@ float NTC_MCU_value2R(uint16_t value) float Q = adc_get_Q(value); - return ((R10*Q)/(1 - Q) - R11); + float res = (R10*Q)/(1 - Q)-R11; + return res; } float NTC_TEC_value2R(uint16_t value) @@ -41,21 +51,24 @@ float NTC_TEC_value2R(uint16_t value) // Resistance to Temp float NTC_R2T(float R) { - float K0 = 273.15; - float T0 = 25.0 + K0; + float K0 = 273.15; + float invT0 = 0.003354;//float T0 = 25.0 + K0; float R0 = 10000.0; float B = 3863.737706; - return (1.0/((log(R/R0)/B) + (1/T0)) - K0); + return (1.0/((logf(R/R0)/B) + invT0) - K0); } // Read ADC and calculate temperature in Cenlsius. -float NTC_MCU_get_temp(void) +float NTC_MCU_get_temp(uint16_t *p_adc_val) { - uint16_t adc_val = adc_read_value_spec(chan_NTC_MCU); - - float R = NTC_MCU_value2R(adc_val); - float t = NTC_R2T(R); + uint16_t adc_val=0; + if (p_adc_val) + adc_val = *p_adc_val; + else + adc_val = adc_read_value_spec(chan_NTC_MCU); + float R = NTC_MCU_value2R(adc_val); + float t = NTC_R2T(R); return t; }