Testing KTY10-6 on AnalogIn
.
The KTY10-6 is a low cost PTC that I found in my stock. So I thought, why not use it to control temperature of some rooms.
First some calculations:
In the Handbook of mbed, I found,that the resolution of a analog/digital converter is 12Bit. This gives us 4095 possible results for one sample.
3,3V / 4096 = 0,81 mV/div. The function we use to get a sample is input.read_u16() and gives us a result of 16Bit. This means, that for every 0,81mV that we have more on the entry of the analog/digital converter, we will get a a 16 bit greater result.
mV | Result of AnalogIn |
0 | 0 |
0.8 | 16 |
0.16 | 32 |
.... | .... |
3300 | .65535 |
By Datasheet, KTY10-6 has (around 20 degrees Celsius) about 15 Ohms per Kelvin and seems to be nearly linear between ~10 and 20 deg. Celsius, which will be enough for our needs. The resistances for 10, 20 and 30 degrees, I found in the datasheet of the KTY10-6. So I calculated a table with the resistances and the samples between.
The difference of the resistance between two samples:
Diff = (R20-R10) / n
Diff = (1922-1772) / 10 =15 (between 10 and 20 degrees).
When we want to show 0,5 degrees difference, we use n = 20.
Between 20 and 30, Diff = 15,8. (Remember, KTY10 is not exactly linear)
The voltage at KTYcalculated:
U(KTY) = U(Ref) - U(Rv)
U(KTY) = U(Ref) - Rv * I(temp)
U(KTY) = U(Ref) - Rv * U(Ref) / (R(KTY)+Rv))
U(KTY)=3.3V-(Rv*3.3V/(Rv+R(KTY))
Temp. | R(KTY) [Ohms] | Approx. Linear | U(KTY) [V] | AD |
10 | 1772 | 1772 | 1,47220544 | 29216 |
11 | 1787 | 1,47908202 | 29360 | |
12 | 1802 | 1,48590705 | 29488 | |
13 | 1817 | 1,49268111 | 29632 | |
14 | 1832 | 1,49940476 | 29760 | |
15 | 1847 | 1,50607858 | 29888 | |
16 | 1862 | 1,5127031 | 30032 | |
17 | 1877 | 1,51927888 | 30160 | |
18 | 1892 | 1,52580645 | 30288 | |
19 | 1907 | 1,53228634 | 30416 | |
20 | 1922 | 1922 | 1,53871907 | 30544 |
21 | 1937,8 | 1,54544444 | 30672 | |
22 | 1953,6 | 1,55211864 | 30816 | |
23 | 1969,4 | 1,55874227 | 30944 | |
24 | 1985,2 | 1,56531587 | 31072 | |
25 | 2000 (!) | 2001 | 1,57184004 | 31200 |
26 | 2016,8 | 1,57831531 | 31328 | |
27 | 2032,6 | 1,58474224 | 31456 | |
28 | 2048,4 | 1,59112136 | 31584 | |
29 | 2064,2 | 1,59745322 | 31712 | |
30 | 2080 | 2080 | 1,60373832 | 31840 |
Here my first try:
In the forum, we can see, that there are problems with the analog inputs.
I tried to solved it by reading 255 samples and just showing the one that appears most.
/* Testing low cost temperature sensor KTY10-6 on analog in. */ #include "mbed.h" // Serial over USB (need driver for Windoes) Serial pc(USBTX, USBRX); // tx, rx // AnalogIn AnalogIn input(p20); DigitalOut led1(LED1); int main() { unsigned short samples[255] , mostsample; // 16 bit 0-65535 unsigned int appears, count; pc.printf("\r\n\r\n"); pc.printf(" ==================================================\r\n"); // I need CR (\r) in HyperTerminal pc.printf(" = Michel`s KTY10-6 Temperature Measuring System. =\r\n"); pc.printf(" ==================================================\r\n"); pc.printf("\r\n\r\n"); while (1) { // wait for a certain time between measurements wait_ms(300000); // flash Led1 led1 = 1; wait_ms(250); led1 = 0; // get analog in for(int i=0; i<255; i++) { samples[i] = input.read_u16(); wait_ms(10); } // Find the most appearing sample mostsample=0; appears=0; for(int i=0; i<255; i++) { count = 0; for(int j=0; j<255; j++) { if(samples[i] == samples[j]) { count++; } } if (count > appears) { mostsample = samples[i]; appears = count; } } // put to serial pc.printf("Analog In on Pin20: %d \r\n", mostsample); } }
2. Using constant current for measuring:
Fixing current to 1mA with R1=1250.
R(Temp) =U(KTY10) / 1mA
U measured on AIN ; I = Const. we can calculate R, and then Temperature with the formula from datasheet:
0 comments
You need to log in to post a comment