peltier with 2 fans

Dependencies:   mbed TextLCD

Revision:
4:5213bee8158e
Parent:
3:0ef2ced1f02d
--- a/peltier/peltier.cpp	Sat Apr 12 20:07:15 2014 +0000
+++ b/peltier/peltier.cpp	Mon Apr 14 02:15:32 2014 +0000
@@ -1,9 +1,23 @@
 #include "mbed.h"
 
 #include "TextLCD.h"
-#include "DS18B20.h"
+//#include "DS18B20.h"
 #include "peltier.h"
-//Serial pc(USBTX, USBRX); // tx, rx
+//----------------------------------
+#include "DS18B20.h"
+#include "OneWireDefs.h"
+
+#define THERMOMETER DS18B20
+
+float temp;
+float dsen_temp_in;
+float dsen_temp_out;
+// device( mbed pin )
+THERMOMETER device(PTE0);
+
+
+//-----------------------------------
+Serial pc(USBTX, USBRX); // tx, rx
 
 unsigned int peltier_hot_pulsewidth=1000;
 unsigned int peltier_cold_pulsewidth=1000;
@@ -17,7 +31,7 @@
 bool alarm_lo_temp_out=false;
 
 TextLCD lcd(PTE29, PTE30, PTC12, PTD0, PTD5, PTA13, TextLCD::LCD20x2);   // rs, e, d4-d7 ok
-
+//DigitalOut backlight(PTD6);
 //unsigned int peltier_hot_pulsewidth=1000;
 //unsigned int peltier_cold_pulsewidth=1000;
 //unsigned int peltier_period =1000;
@@ -29,6 +43,21 @@
 //bool alarm_lo_temp_out=false;
 float dsen_temp;
 
+void readTemp(int deviceNum)
+{
+    temp = device.readTemperature(deviceNum);
+    // pc.printf("Device %d is %f\n\r",deviceNum, temp);
+    wait(0.5);
+}
+void tempinit(void)
+{
+    while (!device.initialize());    // keep calling until it works
+
+    int deviceCount = device.getDeviceCount();
+    pc.printf("Found %d sensors\n\r",deviceCount);
+
+    device.setResolution(twelveBit);
+}
 unsigned int pwm_cold_peltier(int brightness )
 {
     if (brightness==1) {
@@ -55,8 +84,10 @@
 }
 void peltier(bool fan_in,bool fan_out,bool cold,bool hot,int pwm_procent)
 {
-    sensor.mode(PullUp);
-    dsen_temp=mytemp();
+    //tempinit();
+    //sensor.mode(PullUp);
+   // readTemp(1);
+   // dsen_temp_in=temp;
     //  ROM_Code_t ROM_Code = ReadROM();
     //  lcd.setCursor(TextLCD::CurOff_BlkOn);
     //  lcd.locate(0,0);
@@ -92,10 +123,15 @@
         peltier_hot_pulsewidth=pwm_procent*10;
         peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
     }
-    //pc.printf("Temp is %2.1fC,dsen temp= %d \n\r", dsen_temp,10);
-            lcd.cls();
-        lcd.locate(0,1);
-        lcd.printf("Temp is %2.1fC\n\r", dsen_temp);
+
+        readTemp(1);
+        dsen_temp_in=temp;
+        readTemp(0);
+        dsen_temp_out=temp;
+        pc.printf("inside Temp is %2.1fC, outside temp plate is %2.1fC\n\r", dsen_temp_in,dsen_temp_out);
+    lcd.cls();
+    lcd.locate(0,1);
+    lcd.printf("Temp is %2.1fC\n\r", dsen_temp_in);
 
 }
 void pel_c(int pwm)
@@ -111,27 +147,30 @@
     peltier_hot_pulsewidth=pwm*10;
     peltier_hot.pulsewidth_us(peltier_hot_pulsewidth);
 }
-void peltier_auto(int degree)
-{
-    sensor.mode(PullUp);
+void peltier_auto(float degree){
+//tempinit();
+
+   // backlight=1;
+
     en_drv1=1;
     en_drv2=1;
     fan_in_peltier=1;//enable
     fan_out_peltier=1;//enable
     while(1) {
 
-        dsen_temp=mytemp();
+        readTemp(1);
+        dsen_temp_in=temp;
 
-        if (degree>dsen_temp) {
+        /* (degree>dsen_temp) {
             pel_h(0);
-            pel_c(100);
-        }
-        if (degree<dsen_temp) {
+            pel_c(90);
+        }*/
+        if (degree<dsen_temp_in) {
             pel_c(0);
-            pel_h(100);
+            pel_h(90);
 
         }
-        if (degree==dsen_temp) {
+        if (degree==dsen_temp_in) {
             pel_c(0);
             pel_h(0);
 
@@ -139,8 +178,13 @@
 
         lcd.cls();
         lcd.locate(0,1);
-        //pc.printf("Temp is %2.1fC,dsen temp= %d \n\r", dsen_temp,degree);
-        lcd.printf("Temp is %2.1fC\n\r", dsen_temp);
+
+        readTemp(1);
+        dsen_temp_in=temp;
+        readTemp(0);
+        dsen_temp_out=temp;
+        pc.printf("Temp is %2.1fC,dsen temp= %2.1f , outchamber plate temp =%2.1fC\n\r", dsen_temp_in,degree,dsen_temp_out);
+        // lcd.printf("Temp is %2.1fC\n\r", dsen_temp);