Added NTC_TEMP mesurement
This commit is contained in:
parent
f7613b61f7
commit
8c00c02a3a
Binary file not shown.
|
|
@ -353,7 +353,7 @@
|
|||
</dependencies>
|
||||
<project id="common.services.usb.class.cdc.device.example.samd21_xpro" value="Add" config="" content-id="Atmel.ASF" />
|
||||
<board id="board.samd21_xplained_pro" value="Add" config="" content-id="Atmel.ASF" />
|
||||
</framework-data>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
|
||||
<avrtoolserialnumber>J41800067100</avrtoolserialnumber>
|
||||
|
|
@ -371,6 +371,7 @@
|
|||
<ToolName>Atmel-ICE</ToolName>
|
||||
</com_atmel_avrdbg_tool_atmelice>
|
||||
<avrtoolinterfaceclock>2000000</avrtoolinterfaceclock>
|
||||
<TriggerUpgrade>true</TriggerUpgrade>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
|
|
@ -671,7 +672,7 @@
|
|||
</armgcc.linker.libraries.LibrarySearchPaths>
|
||||
<armgcc.linker.optimization.GarbageCollectUnusedSections>True</armgcc.linker.optimization.GarbageCollectUnusedSections>
|
||||
<armgcc.linker.memorysettings.ExternalRAM />
|
||||
<armgcc.linker.miscellaneous.LinkerFlags>-Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam0/utils/linker_scripts/samd21/gcc/samd21e16b_flash.ld</armgcc.linker.miscellaneous.LinkerFlags>
|
||||
<armgcc.linker.miscellaneous.LinkerFlags>-Wl,--entry=Reset_Handler -Wl,--cref -mthumb -Wl,-u,vfprintf -T../src/ASF/sam0/utils/linker_scripts/samd21/gcc/samd21e16b_flash.ld</armgcc.linker.miscellaneous.LinkerFlags>
|
||||
<armgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>../src</Value>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,10 +42,12 @@
|
|||
//#include <stdlib.h>
|
||||
#include "realsence.h"
|
||||
#include "ntc.h"
|
||||
#include <arm_math.h>
|
||||
|
||||
#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;
|
||||
|
|
@ -177,14 +179,18 @@ 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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,20 @@
|
|||
* Author: Lexus
|
||||
*/
|
||||
#include "ntc.h"
|
||||
#include <arm_math.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#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)
|
||||
|
|
@ -42,18 +52,21 @@ float NTC_TEC_value2R(uint16_t value)
|
|||
float NTC_R2T(float R)
|
||||
{
|
||||
float K0 = 273.15;
|
||||
float T0 = 25.0 + K0;
|
||||
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);
|
||||
|
||||
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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue