19 Aug 2007

The program like the following output values on the hyper terminal shows all the results and analysis in test1.txt file.

#include <16F77.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

long t1, t2;
long cnt;

//bluetooth parani
void promi_init()
{
// Promi Initializing Started
putc (0x41); // AT(cr) Check the presence of Promi
putc (0x54);
putc (0x0D);
delay_ms(500);

putc (0x41); // AT+BTMODE,3(cr) Set Operation Mode
putc (0x54); // For Mode 3, the device will connect automatically
putc (0x2B);
putc (0x42);
putc (0x54);
putc (0x4D);
putc (0x4F);
putc (0x44);
putc (0x45);
putc (0x2C);
putc (0x33);
putc (0x0D);
delay_ms(500);
}

void promi_scanmode()
{
putc (0x41); // AT+BTSCAN(cr) Inquiry scan & page scan alternately
putc (0x54); // This is to make the SD discoverable from other BT devices
putc (0x2B);
putc (0x42);
putc (0x54);
putc (0x53);
putc (0x43);
putc (0x41);
putc (0x4E);
putc (0x0D);
delay_ms(500);
}

float calTemp(long t1, long t2){
float temp;
temp = 235 - 400*(float)t1/(float)t2;
return temp;

}

void getCycle(){
float temp;
cnt = 0;
while(input(pin_D1)){;}
while(!input(pin_D1)){;}
while(input(pin_D1)){
cnt = cnt + 1;
delay_us(1);
}
t1 = cnt;
cnt = 0;
while(!input(pin_D1)){
cnt = cnt + 1;
delay_us(1);
}
t2 = cnt;
printf("\nt1 is %ld and t2 is %ld at ", t1, t2);
temp = calTemp(t1, t2);
//output_B((int)temp);

if (temp < 28.0){
printf(time);
printf(" (1). temp < 28 and temp is %f", temp);
output_bit(pin_d3, 1);
}
else if(temp > 33.0){
printf(time);
printf(" (2). temp > 33 and temp is %f", temp);
output_bit(pin_d3, 0);
}
else {
printf(time);
printf(" (3). 28 < temp < 33, and temp is %f", temp);
}
}

void main()
{

set_tris_d(0x03); //input pins D0 and D1
//set_tris_c(0x00); //output pins
set_tris_b(0x00); //output pins

output_d(0b00000000);
output_b(0b00000000);
delay_ms(2000);
promi_init();
promi_scanmode();
output_b(0b00001111);

while(true){
//printf("NOw it is in the loop");
delay_ms(3000);
output_B(0b11110000);
getCycle();

}
}

I did another test trying to track a more accurate temperature difference between oscilloscope (t1 and t2 ) and the program counting t1 and t2. I did it in a way that immediately when I saw the output from the hyper-terminal I pressed stop button on the oscilloscope, even this might still cause some time difference between the two, but I can roughly tell whether the program count time is close to that of the oscilloscope which is the real output showing of the temperature sensor. The result I got is like this:
Hyperterminal output is t1 = 2771 us, t2 = 5243 us => temp = 23.5943
Oscilloscope output is t1 = 8.905 ms, t2 = 16.755ms => temp = 22.4067
So there is like a difference of 1. sth degree of difference. As the oscilloscope is pressed after the hyperterminal, the real temp(shown by oscilloscope) at the time of hyperterminal output should be even lower than 22.4067, which would cause slightly bigger difference.

Another problem to solve is where to put the temperature sensor on the element where could be the most accurate of measurement? As because the whole nichrome wire was attached to the cloth by pasting the tape, once the temperature sensor is also put between the nichrome wire and the tape, it would cause the area where the tape and the cloth does not have a proper contact to have a lower temperature. Therefore, in the program this temperature difference caused by the allocation of temperature sensor in the element should also be considered, and it might need to add 2 degree from the result of the temperature calculated from the program. In order to test whether it has a bigger impact on the other color, an element with two thermochromic ink needs to be printed.

Problem with above program is that the when the temp(in the program) reaches above 33, then it will output 0, meaning to cut of the supply to the heating element. And when it drops back to between 28 and 33 degree, the program will do nothing, which will only give the supply again after the temperature drop below 28. This is not able to maintain the color change on the heating element. I modified the program a bit, just to change the 28.0 to 31.0 which will give a more appropriate temperature range (31-33) so that the heating element could maintain the color after it has been changed. But the temperature maintainance is still not very good, then I changed it to 31.5, and the upper range also have to be adjusted a bit to 33.5 as at 33 the element will not completely change color yet. However, the most important thing is not about this upper bound because it has to be reconsidered when another color is printed. As when a 2nd color's activation temperature is 37 degree, it might start to change at 34 degree, and if we put the upper bound of the first color at 34, at that upper bound, we might also see the 2nd color start to change. Therefore, it is still better to print both colors first. One more thing to mention is the range 31.5-33.5 is of difference 2 degree which is too big and the element will have a obvious color changing back within the range, so probably, I will make it 32-33.5 next time.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.