Sous Vide: Code Snippet

Writing code for the temperature sensor to work with our A3BU proved to be too difficult to be completed in the time allotted. However, code was written, using an empty read temperature function, to show how the sensor would be implemented in our design. Essentially, the user inputs a set temperature and the program uses the set temperature to approximate the power needed to reach that temperature. The sensor then reads a temperature in every second until the water is within two degrees of the set point. If the water temperature does not reach that interval within thirty minutes the power is increased. If the water temperature is greater than the interval the power will be decreased every five minutes until the set point is reached.

(Instructor note: this was a 1-Wire temp sensor. For high temperatures an analog thermocouple reader chip could be used with an ADC. The AD595 chip is user-friendly but it eats a large part of a $25 project budget)


//Decrements duty cycle if temperature is greater than two degrees of set point
if(temperature>(i_temp+2)){
d_c=d_c-1;//Increments duty cycle
s_flag=0;//Sets seconds flag to 0
}

//Enters loop while water temperature is greater than input temperature
while(temperature>(i_temp+2)){
temperature=ds18b20_gettemp();//Gets temperature
snprintf(prompt, OUTPUT_STR_SIZE, "Temperature: %4d",temperature);
gfx_mono_draw_string(prompt, 0, 12, &sysfont);//Display temperature
delay_s(1);
s_flag++;//Increments a seconds flag

if(s_flag==60){
m_flag++;//Increment minute flag
s_flag=0;//Sets seconds flag to 0
}

//Wait 5 minutes if water temperature is to high or temperature falls below set point
//Resets timers and breaks while loop
if(m_flag==5 || temperature<=(i_temp+2)){
s_flag=0;//Set seconds flag to 0
m_flag=0;//Set minute flag to 0
break;
}