4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
30 * All Rights Reserved.
33 * \brief NTC hardware-specific definition
36 * \author Francesco Sacchi <batt@develer.com>
38 * A NTC acts as a variable resistor, whose resistance changes as a
39 * function of the temperature it measures. To sample it correctly, it is
40 * usually parallelized and serialized with two fixed resistor. The following diagram shows
41 * what is the exact disposition of the components, as handled by this
55 * -----------|------| Amp |-------------| |
57 * ----- ----- ----- ---------
67 * Amp is an amplifier that amplify of AMP times the signal.
68 * If we indicate Rp as the parallel of NTC with Rpar, ADCBITS as the bits of the ad converter
69 * and ADCVAL as the result from the adc convertion (Not Vadc but just the value read
70 * from the adc register), after various calculation, the expression of Rp is:
75 * Rp = ------------------------
80 * And after that NTC obvisiously is:
88 * The function ntc_hw_read() compute the resistence using these formulas above.
96 #include <cfg/debug.h>
101 #warning TODO:This is an example implementation, you must implement it!
103 extern const res_t NTC_RSER[NTC_CNT];
104 extern const res_t NTC_RPAR[NTC_CNT];
105 extern const amp_t NTC_AMP[NTC_CNT];
106 extern const NtcHwInfo* NTC_INFO[NTC_CNT];
110 * Read the resistence of ntc device \a dev.
111 * Return the result in res_t type.
113 INLINE res_t ntc_hw_read(NtcDev dev)
115 ASSERT(dev < NTC_CNT);
116 // See above for formula explanation.
117 adcread_t adcval = adc_read((uint16_t)dev);
118 float rp = (adcval * NTC_RSER[dev] ) / ((1 << adc_bits()) * NTC_AMP[dev] - adcval);
120 //kprintf("Rp[%f], Rntc[%f]\n", rp/100, ((NTC_RPAR[dev] * rp) / (NTC_RPAR[dev] - rp)) / 100.0);
122 return ( (NTC_RPAR[dev] * rp) / (NTC_RPAR[dev] - rp) );
127 * Return the info (aka the table) associated with ntc device \a dev.
129 INLINE const NtcHwInfo* ntc_hw_getInfo(NtcDev dev)
131 return NTC_INFO[dev];
134 #define NTC_HW_INIT do { /* Implement me! */ } while(0)
136 #endif /* HW_NTC_H */