ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Среда
27 ноября
149260 Топик полностью
Vladimir Ljaschko (25.02.2009 13:35, просмотров: 78) ответил yakuzaa на а можно посмотреть, пожалуйста?
Г. не жалко :  int current_temperature[5]; //int current_temperature; uchar temperature_channels=4; #define REF_RESISTANCE 1000000LL #define REF_VOLTAGE 0xfffffL #define R_OFFSET -10 #define SENSORS2 #define MIN_T -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 #ifdef SENSORS1 long __flash R_VALUE[] = { 5529800, 5238000, 4963300, 4704700, 4461000, 4231500, 4015000, 3810900, 3618300, 3436600, 3265080, 3103040, 2950010, 2805420, 2668760, 2539550, 2417270, 2301600, 2192170, 2088520, 1990350, 1897360, 1809260, 1725740, 1646510, 1571400, 1500120, 1432460, 1368260, 1305280, 1249370, 1194330, 1142000, 1092270, 1044990, 1000000, 957200, 916470, 877700, 840770, 805600, 772090, 740170, 709720, 680700, 653010, 626610, 601420, 577370, 554410, 532490, 511560, 491550, 472430, 454160, 436690, 419990, 404010, 388720, 374110, 360100, 346690, 333860, 321560, 309790, 298510, 287690, 277320, 267390, 257850, 248710, 239940, 231520, 223470, 215670, 208230, 201080, 194210, 187600, 181260, 175160, 169300, 163663, 158241, 153028, 148012, 143187, 138537, 134068, 129764, 125617, 121623, 117775, 114071, 110499, 107058, 103740, 100540, 97456, 94481, 91611, 88841, 86170, 83593, 81103, 78699, 76379, 74138, 71974, 69882, 67863 }; #endif #ifdef SENSORS2 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[]= { /*-10.0 */ 5430800, //0 /*-5.0*/ 4150500, //1 /*0.0*/ 3201400, //2 /*5.0 */ 2501100, //3 /*10.0 */ 1969100, //4 /*15.0*/ 1561800, //5 /*20.0 */ 1247400, //6 /*25.0*/ 1000000, //7 /*30.0*/ 808000, //8 /*35.0*/ 656900, //9 /*40.0 */ 537200, /*45.0*/ 442400, /*50.0*/ 366100, /*55.0*/ 303900, /*60.0 */ 253600, /*65.0*/ 212800, /*70.0*/ 179400, /*75.0*/ 151800, /*80.0*/ 129000, /*85.0*/ 110000 }; #define R_COUNT (sizeof (R_VALUE)/ sizeof(R_VALUE[0])) #define EPCOS_COUNT (sizeof (EPCOS_VALUE)/ sizeof(EPCOS_VALUE[0])) __flash char channel_codes[ACTIVE_ADC_CHANNELS] = // A1 B2 Cooler Heater //{ 0, 2, 1, 3}; //{ 2, 1, 3, 0}; { 0, 1, 3, 2 }; int GetTemperature( char i ) { long voltage; long resistance; char left = 0; if (i<ACTIVE_ADC_CHANNELS) { voltage=external_adc_values[channel_codes[i]]; voltage&=0xfffff; if (voltage>MAX_V) return MIN_T; resistance = (voltage * REF_RESISTANCE / (REF_VOLTAGE - voltage)); // resistance=64000L; if (resistance > R_VALUE[0]) return MIN_T; if (resistance < R_VALUE[R_COUNT - 1]) return MAX_T; for (left=0; left<R_COUNT-2; left++) { if (resistance>R_VALUE[left+1]) break; } return 100 * (R_OFFSET + left) + 100 * (R_VALUE[left] - resistance) / (R_VALUE[left] - R_VALUE[left + 1]); } else { voltage=adc_values[0]+30; voltage=voltage<<10; resistance = (voltage * REF_RESISTANCE / (REF_VOLTAGE - voltage)); if (resistance > EPCOS_VALUE[0]) return 100 * (R_OFFSET - 1); if (resistance < EPCOS_VALUE[EPCOS_COUNT - 1]) return 100 * (R_OFFSET + (int)EPCOS_COUNT - 1); for (left=0; left<EPCOS_COUNT-2; left++) { if (resistance>EPCOS_VALUE[left+1]) break; } return 100*R_OFFSET + 500* left + 500 * (EPCOS_VALUE[left] - resistance) / (EPCOS_VALUE[left] - EPCOS_VALUE[left + 1]); } ; } void TemperatureCalculationService(char tci) { tc[tci]->ctemp=GetTemperature(tci); }