ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Среда
27 ноября
839845 Топик полностью
VLLV (11.05.2018 23:35, просмотров: 115) ответил Vit на Upd. Я так меряю. Slope ADC в реальном применении сделан на опоре и компараторе STM32L151. 16-бит таймер, соответственно выбран конденсатор. Насчет разрешения, КМК, всё наоборот
угу #include "include_ports.h" #include "def.h" #include "Typedef.h" #include "ADCe.h" #include "Temperature.h" #include "Areas.h" #include "Errors.h" int temper[TEMPER_QTY]; char t_error[TEMPER_QTY]; long resistance[ADCE_QTY]; char temperature_error; #define REF_RESISTANCE 1000000LL #define REF_VOLTAGE 0xfffffL #define SENSORS_5K #define MIN_T 0 //(-1000) // minimum temperature to be calculated #define MAX_T 8000 // maximum temperature #define MAX_V (REF_VOLTAGE-REF_VOLTAGE/20) // maximum voltage to be processed #define MAX_R REF_RESISTANCE*20LL #ifdef SENSORS_10K long __flash R_VALUE[] = { /* 5529800, 5238000, 4963300, 4704700, 4461000, 4231500, 4015000, 3810900, 3618300, 3436600, //-10 */ 3265080, 3103040, 2950010, 2805420, 2668760, 2539550, 2417270, 2301600, 2192170, 2088520, //0 1990350, 1897360, 1809260, 1725740, 1646510, 1571400, 1500120, 1432460, 1368260, 1305280, //10 1249370, 1194330, 1142000, 1092270, 1044990, 1000000, 957200, 916470, 877700, 840770, //20 805600, 772090, 740170, 709720, 680700, 653010, 626610, 601420, 577370, 554410, //30 532490, 511560, 491550, 472430, 454160, 436690, 419990, 404010, 388720, 374110, //40 360100, 346690, 333860, 321560, 309790, 298510, 287690, 277320, 267390, 257850, //50 248710, 239940, 231520, 223470, 215670, 208230, 201080, 194210, 187600, 181260, //60 175160, 169300, 163663, 158241, 153028, 148012, 143187, 138537, 134068, 129764, //70 125617 //80 /* , 121623, 117775, 114071, 110499, 107058, 103740, 100540, 97456, 94481, 91611, 88841, 86170, 83593, 81103, 78699, 76379, 74138, 71974, 69882, //90 67863 //100 */ }; #endif #ifdef SENSORS_5K long __flash R_VALUE[] = { /* 2768000, 2621500, 2483600, 2353800, 2231700, 2116600, 2008200, 1906000, 1809700, 1718800, //-10 */ 1633000, 1551800, 1475100, 1402700, 1334300, 1269600, 1208400, 1150600, 1095900, 1044100, // 0 995080, 948530, 904420, 862630, 823020, 785470, 749850, 716050, 683970, 653520, //10 624600, 597080, 570940, 546090, 522470, 500000, 478610, 458250, 438880, 420440, //20 402870, 386120, 370160, 354960, 340460, 326630, 313440, 300860, 288850, 277390, //30 266450, 255980, 245990, 236430, 227300, 218580, 210230, 202250, 194620, 187310, //40 180320, 173620, 167210, 161060, 155180, 149540, 144140, 138960, 133990, 129230, //50 124660, 120280, 116070, 112030, 108160, 104430, 100860, 97419, 94117, 90943, //60 87892, 84962, 82143, 79433, 76824, 74315, 71900, 69575, 67336, 65181, //70 63104 //80 }; #endif // NTC M891-10k 5% B57-891-M103-J long __flash EPCOS_VALUE[]= { /* 5430800, //-10.0 4150500, //-5.0 */ 3201400, //0.0 2501100, //5.0 1969100, //10.0 1561800, //15.0 1247400, //20.0 1000000, //25.0 808000, //30.0 656900, //35.0 537200, //40.0 442400, //45.0 366100, //50.0 303900, //55.0 253600, //60.0 212800, //65.0 179400, //70.0 151800, //75.0 129000 /*, //80.0 // 110000 //85.0 */ }; #define R_COUNT (sizeof (R_VALUE)/ sizeof(R_VALUE[0])) #define EPCOS_COUNT (sizeof (EPCOS_VALUE)/ sizeof(EPCOS_VALUE[0])) long GetResistance(long volt) { long resist; long voltage; voltage=volt&0xfffff; if (voltage>MAX_V) return MAX_R; resist = (voltage * REF_RESISTANCE / (REF_VOLTAGE - voltage)); return resist; } char GetTemperatureError(void) { return temperature_error; } int GetTemper( long res ) { char left = 0; long resist; resist=res; if (resist > R_VALUE[0]) { resist=R_VALUE[0]; temperature_error=erSensorDisconnected; } else { if (resist < R_VALUE[R_COUNT - 1]) { resist=R_VALUE[R_COUNT - 1]; temperature_error=erSensorShorted; } else { temperature_error=0; for (left=0; left<R_COUNT-2; left++) { if (resist>R_VALUE[left+1]) break; } } } return 100*left + 100 * (R_VALUE[left] - resist) / (R_VALUE[left] - R_VALUE[left + 1]); } int GetTemperEpcos( long res) { char left = 0; long resist; resist=res; if (resist > EPCOS_VALUE[0]) resist= EPCOS_VALUE[0]; if (resist < EPCOS_VALUE[EPCOS_COUNT - 1]) resist= EPCOS_VALUE[EPCOS_COUNT - 1]; for (left=0; left<EPCOS_COUNT-2; left++) { if (resist>EPCOS_VALUE[left+1]) break; } return 500* left + 500 * (EPCOS_VALUE[left] - resist) / (EPCOS_VALUE[left] - EPCOS_VALUE[left + 1]); } #define s1 ((long)se.point1_disp) #define s2 ((long)se.point2_disp) #define a1 ((long)se.point1_real-(long)se.point1_disp) #define a2 ((long)se.point2_real-(long)se.point2_disp) signed int GetAdjustment(signed int my_temper) { // adjustment = (X*sensor_temper)/factor + Y static long factor=1000; static long corr; static long X; static int Y; X = (signed int) ( ( factor * (a1-a2) ) / (s1-s2) ); Y = (signed int) ( (10*(s2*a1 - s1*a2))/(s2-s1) ); corr= ((long)my_temper * X)/factor + Y; return (int)corr; } void TemperService1s(void) { resistance[ADCE_WATER]=GetResistance(adce_results[ADCE_WATER]); temper[SENSOR_TEMPER]=GetTemper(resistance[ADCE_WATER]); temper[ACTUAL_TEMPER]=temper[SENSOR_TEMPER]+GetAdjustment(temper[SENSOR_TEMPER]); /* temper[AMBIENT_TEMPER]=se.ambient*10; temper[ACTUAL_TEMPER]=temper[ADJUSTED_TEMPER]+ ( (long)(temper[AMBIENT_TEMPER]-temper[ADJUSTED_TEMPER])* se.temper_slope )/1000; */ if (adce_qty>ADCE_PCB) { resistance[ADCE_PCB]=GetResistance(adce_results[ADCE_PCB]); temper[PCB_TEMPER]=GetTemperEpcos(resistance[ADCE_PCB]); } if (adce_qty>ADCE_ST4) resistance[ADCE_ST4]=GetResistance(adce_results[ADCE_ST4]); else resistance[ADCE_ST4]=0; }