![](/media/cache/profiles/a7921ea22e084f4c3f660b30749325c3.jpg.50x50_q85.jpg)
TechshopReflow
Fork of max31855Sample by
main.cpp@2:d3e63bd08832, 2017-02-21 (annotated)
- Committer:
- Info
- Date:
- Tue Feb 21 11:37:49 2017 +0000
- Revision:
- 2:d3e63bd08832
- Parent:
- 1:6bed4f6f7b35
- Child:
- 3:adc7ee7569d2
RevA 2017 02 21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Stavlin | 0:c50a2801c243 | 1 | #include "mbed.h" |
Stavlin | 0:c50a2801c243 | 2 | #include "max31855.h" |
Stavlin | 0:c50a2801c243 | 3 | |
Stavlin | 0:c50a2801c243 | 4 | DigitalOut myled(LED1); |
Stavlin | 0:c50a2801c243 | 5 | |
Stavlin | 0:c50a2801c243 | 6 | //---------------------------------------------------------- |
Stavlin | 0:c50a2801c243 | 7 | //SPI Interfaces |
Info | 2:d3e63bd08832 | 8 | //SPI testSPI(p11,p12,p13);//MOSI MISO SCK for LPC1768 |
Info | 2:d3e63bd08832 | 9 | SPI testSPI(P0_26,P0_25,P0_24);//MOSI MISO SCK for LPC824MAX |
Stavlin | 0:c50a2801c243 | 10 | //---------------------------------------------------------- |
Stavlin | 0:c50a2801c243 | 11 | |
Stavlin | 0:c50a2801c243 | 12 | //---------------------------------------------------------- |
Stavlin | 0:c50a2801c243 | 13 | //Thermocouples |
Info | 2:d3e63bd08832 | 14 | //max31855 max1(testSPI,p21); |
Info | 2:d3e63bd08832 | 15 | max31855 max1(testSPI,P0_15);//Digital Out LPC824MAX |
Info | 2:d3e63bd08832 | 16 | //---------------------------------------------------------- |
Info | 2:d3e63bd08832 | 17 | |
Info | 2:d3e63bd08832 | 18 | //---------------------------------------------------------- |
Info | 2:d3e63bd08832 | 19 | //Reflow Oven |
Info | 2:d3e63bd08832 | 20 | DigitalOut oOven(P0_27); |
Info | 2:d3e63bd08832 | 21 | //FUN |
Info | 2:d3e63bd08832 | 22 | DigitalOut oFan(P0_13); |
Info | 2:d3e63bd08832 | 23 | |
Stavlin | 0:c50a2801c243 | 24 | //---------------------------------------------------------- |
Stavlin | 0:c50a2801c243 | 25 | |
Info | 2:d3e63bd08832 | 26 | float getTemp(void){ |
Info | 2:d3e63bd08832 | 27 | float fvalue = 0.0; |
Info | 2:d3e63bd08832 | 28 | if (max1.ready()==1){ |
Info | 2:d3e63bd08832 | 29 | //Get the reading |
Info | 2:d3e63bd08832 | 30 | fvalue = max1.read_temp(); |
Info | 2:d3e63bd08832 | 31 | //fvalue = fvalu; |
Info | 2:d3e63bd08832 | 32 | //fvalue = fvalue *2 -160.0; //calibration here |
Info | 2:d3e63bd08832 | 33 | //fvalue = fvalue; //calibration here |
Info | 2:d3e63bd08832 | 34 | if((fvalue >= 2000)&&(fvalue <= 2010)){ |
Info | 2:d3e63bd08832 | 35 | printf("Plobe error : maybe wire is cut.\r\n"); |
Info | 2:d3e63bd08832 | 36 | }else{ |
Info | 2:d3e63bd08832 | 37 | printf("Temp: %4.2f\n\r", fvalue); |
Info | 2:d3e63bd08832 | 38 | myled = !myled; |
Info | 2:d3e63bd08832 | 39 | return fvalue; |
Info | 2:d3e63bd08832 | 40 | } |
Info | 2:d3e63bd08832 | 41 | }else{ |
Info | 2:d3e63bd08832 | 42 | printf("Can not get Temp\n\r"); |
Info | 2:d3e63bd08832 | 43 | return -1;//error can not get temp |
Info | 2:d3e63bd08832 | 44 | |
Info | 2:d3e63bd08832 | 45 | } |
Info | 2:d3e63bd08832 | 46 | } |
Info | 2:d3e63bd08832 | 47 | |
Info | 2:d3e63bd08832 | 48 | void keepCool(void){ |
Info | 2:d3e63bd08832 | 49 | oOven = 0; |
Info | 2:d3e63bd08832 | 50 | oFan = 1; |
Info | 2:d3e63bd08832 | 51 | |
Info | 2:d3e63bd08832 | 52 | for(int i=0;i<60;++i){ |
Info | 2:d3e63bd08832 | 53 | printf("cooling t:%d ",i); |
Info | 2:d3e63bd08832 | 54 | getTemp(); |
Info | 2:d3e63bd08832 | 55 | wait(1); |
Info | 2:d3e63bd08832 | 56 | |
Info | 2:d3e63bd08832 | 57 | }//1 min wait for cool |
Info | 2:d3e63bd08832 | 58 | } |
Info | 2:d3e63bd08832 | 59 | |
Info | 2:d3e63bd08832 | 60 | int stage1(void){ //upto 150 degree Celsius |
Info | 2:d3e63bd08832 | 61 | float nowTemp = 0; |
Info | 2:d3e63bd08832 | 62 | |
Info | 2:d3e63bd08832 | 63 | oOven = 1; |
Info | 2:d3e63bd08832 | 64 | oFan = 0; |
Info | 2:d3e63bd08832 | 65 | |
Info | 2:d3e63bd08832 | 66 | while(1){ |
Info | 2:d3e63bd08832 | 67 | printf("stage1 "); |
Info | 2:d3e63bd08832 | 68 | nowTemp = getTemp(); |
Info | 2:d3e63bd08832 | 69 | if(nowTemp >= 150){ |
Info | 2:d3e63bd08832 | 70 | oOven = 0;//stop oven |
Info | 2:d3e63bd08832 | 71 | return 1; |
Info | 2:d3e63bd08832 | 72 | } |
Info | 2:d3e63bd08832 | 73 | wait(0.5); |
Info | 2:d3e63bd08832 | 74 | } |
Info | 2:d3e63bd08832 | 75 | } |
Info | 2:d3e63bd08832 | 76 | |
Info | 2:d3e63bd08832 | 77 | int stage2(void){ //keep 180 degree Celsius for 100 sec |
Info | 2:d3e63bd08832 | 78 | int time = 0; |
Info | 2:d3e63bd08832 | 79 | float nowTemp = 0; |
Info | 2:d3e63bd08832 | 80 | |
Info | 2:d3e63bd08832 | 81 | oOven = 0; |
Info | 2:d3e63bd08832 | 82 | oFan = 1; |
Info | 2:d3e63bd08832 | 83 | |
Info | 2:d3e63bd08832 | 84 | for(time = 0; time < (100.0 / 0.3); ++time){ |
Info | 2:d3e63bd08832 | 85 | printf("stage2 time=%4.2lf",(time*0.3)); |
Info | 2:d3e63bd08832 | 86 | nowTemp = getTemp(); |
Info | 2:d3e63bd08832 | 87 | |
Info | 2:d3e63bd08832 | 88 | if(nowTemp > 180.0){ |
Info | 2:d3e63bd08832 | 89 | oOven = 0; |
Info | 2:d3e63bd08832 | 90 | oFan = 0; |
Info | 2:d3e63bd08832 | 91 | wait(0.05);; |
Info | 2:d3e63bd08832 | 92 | oOven = 0; |
Info | 2:d3e63bd08832 | 93 | oFan = 1; |
Info | 2:d3e63bd08832 | 94 | wait(0.1); |
Info | 2:d3e63bd08832 | 95 | oOven = 0; |
Info | 2:d3e63bd08832 | 96 | oFan = 0; |
Info | 2:d3e63bd08832 | 97 | wait(0.05);; |
Info | 2:d3e63bd08832 | 98 | oOven = 0; |
Info | 2:d3e63bd08832 | 99 | oFan = 1; |
Info | 2:d3e63bd08832 | 100 | wait(0.1); |
Info | 2:d3e63bd08832 | 101 | }else{ |
Info | 2:d3e63bd08832 | 102 | oOven = 1; |
Info | 2:d3e63bd08832 | 103 | oFan = 1; |
Info | 2:d3e63bd08832 | 104 | wait(0.05); |
Info | 2:d3e63bd08832 | 105 | oOven = 1; |
Info | 2:d3e63bd08832 | 106 | oFan = 0; |
Info | 2:d3e63bd08832 | 107 | wait(0.1); |
Info | 2:d3e63bd08832 | 108 | oOven = 1; |
Info | 2:d3e63bd08832 | 109 | oFan = 1; |
Info | 2:d3e63bd08832 | 110 | wait(0.05); |
Info | 2:d3e63bd08832 | 111 | oOven = 1; |
Info | 2:d3e63bd08832 | 112 | oFan = 0; |
Info | 2:d3e63bd08832 | 113 | wait(0.1); |
Info | 2:d3e63bd08832 | 114 | } |
Info | 2:d3e63bd08832 | 115 | } |
Info | 2:d3e63bd08832 | 116 | |
Info | 2:d3e63bd08832 | 117 | return 1; |
Info | 2:d3e63bd08832 | 118 | } |
Info | 2:d3e63bd08832 | 119 | |
Info | 2:d3e63bd08832 | 120 | |
Info | 2:d3e63bd08832 | 121 | int stage3(void){ //Go to 260 degree Celsius! |
Info | 2:d3e63bd08832 | 122 | int time = 0; |
Info | 2:d3e63bd08832 | 123 | float nowTemp = 0; |
Info | 2:d3e63bd08832 | 124 | |
Info | 2:d3e63bd08832 | 125 | |
Info | 2:d3e63bd08832 | 126 | oOven = 0; |
Info | 2:d3e63bd08832 | 127 | oFan = 1; |
Info | 2:d3e63bd08832 | 128 | while(1){ |
Info | 2:d3e63bd08832 | 129 | printf("stage3 "); |
Info | 2:d3e63bd08832 | 130 | nowTemp = getTemp(); |
Info | 2:d3e63bd08832 | 131 | |
Info | 2:d3e63bd08832 | 132 | if(nowTemp >= 260.0){ |
Info | 2:d3e63bd08832 | 133 | return 1; |
Info | 2:d3e63bd08832 | 134 | }else{ |
Info | 2:d3e63bd08832 | 135 | oOven = 1; |
Info | 2:d3e63bd08832 | 136 | oFan = 1; |
Info | 2:d3e63bd08832 | 137 | wait(0.05); |
Info | 2:d3e63bd08832 | 138 | oOven = 1; |
Info | 2:d3e63bd08832 | 139 | oFan = 0; |
Info | 2:d3e63bd08832 | 140 | wait(0.75); |
Info | 2:d3e63bd08832 | 141 | |
Info | 2:d3e63bd08832 | 142 | } |
Info | 2:d3e63bd08832 | 143 | } |
Info | 2:d3e63bd08832 | 144 | return -1;//error |
Info | 2:d3e63bd08832 | 145 | } |
Info | 2:d3e63bd08832 | 146 | |
Stavlin | 0:c50a2801c243 | 147 | int main() { |
Stavlin | 0:c50a2801c243 | 148 | //Initialise chip (starts internal timer) |
Stavlin | 0:c50a2801c243 | 149 | max1.initialise(); |
Stavlin | 0:c50a2801c243 | 150 | |
Stavlin | 0:c50a2801c243 | 151 | //Float value to hold temperature returned |
Stavlin | 0:c50a2801c243 | 152 | float fvalue = 0; |
Stavlin | 0:c50a2801c243 | 153 | |
Info | 2:d3e63bd08832 | 154 | //keepCool(); |
Info | 2:d3e63bd08832 | 155 | stage1(); |
Info | 2:d3e63bd08832 | 156 | stage1(); |
Info | 2:d3e63bd08832 | 157 | stage1(); |
Info | 2:d3e63bd08832 | 158 | stage2(); |
Info | 2:d3e63bd08832 | 159 | stage3(); |
Info | 2:d3e63bd08832 | 160 | stage3(); |
Info | 2:d3e63bd08832 | 161 | stage3(); |
Info | 2:d3e63bd08832 | 162 | keepCool(); |
Info | 2:d3e63bd08832 | 163 | keepCool(); |
Info | 2:d3e63bd08832 | 164 | keepCool(); |
Info | 2:d3e63bd08832 | 165 | printf("end of Process! Thank you for Using Techshop Reflow.\r\n"); |
Info | 2:d3e63bd08832 | 166 | |
Stavlin | 0:c50a2801c243 | 167 | } |