1 |
#include "reflow.h" |
1 |
#include "reflow.h" |
- |
|
2 |
#include "process.h" |
2 |
#include <math.h> |
3 |
#include <math.h> |
3 |
|
4 |
|
4 |
// nastaveni teplot a casu |
5 |
// nastaveni teplot a casu |
5 |
#define TEPLOTA_PREDEHREVU 120 |
6 |
#define TEPLOTA_PREDEHREVU 120 |
6 |
#define DOBA_PREDEHREVU 60 |
7 |
#define DOBA_PREDEHREVU 60 |
7 |
|
8 |
|
8 |
#define TEPLOTA_VRCHOLU 210 |
9 |
#define TEPLOTA_VRCHOLU 210 |
9 |
#define DOBA_VRCHOLU 5 |
10 |
#define DOBA_VRCHOLU 5 |
10 |
|
11 |
|
11 |
// CPU IO rozhrani |
12 |
// CPU IO rozhrani |
12 |
#define LCD_RS PIN_C1 // rizeni registru LCD displeje |
13 |
#define LCD_RS PIN_C1 // rizeni registru LCD displeje |
13 |
#define LCD_E PIN_C2 // enable LCD displeje |
14 |
#define LCD_E PIN_C2 // enable LCD displeje |
14 |
#define LCD_DATA_LSB PIN_D0 // data LCD |
15 |
#define LCD_DATA_LSB PIN_D0 // data LCD |
15 |
#include "lcd.c" |
16 |
#include "lcd.c" |
16 |
|
17 |
|
17 |
#define TL1 PIN_B3 // tlacitko S1 |
18 |
#define TL1 PIN_B3 // tlacitko S1 |
18 |
#define TL2 PIN_B2 // tlacitko S2 |
19 |
#define TL2 PIN_B2 // tlacitko S2 |
19 |
#define TL3 PIN_B1 // tlacitko S3 |
20 |
#define TL3 PIN_B1 // tlacitko S3 |
20 |
#define TL4 PIN_B0 // tlacitko S4 |
21 |
#define TL4 PIN_B0 // tlacitko S4 |
21 |
|
22 |
|
22 |
#define POWER_T3 PIN_A6 // ovladani optotriaku T3 |
23 |
#define POWER_T3 PIN_A3 // ovladani optotriaku T3 |
23 |
#define POWER_T4 PIN_A5 // ovladani optotriaku T4 |
24 |
#define POWER_T4 PIN_A5 // ovladani optotriaku T4 |
24 |
#define POWER_T5 PIN_A4 // ovladani optotriaku T5 |
25 |
#define POWER_T5 PIN_A4 // ovladani optotriaku T5 |
25 |
|
26 |
|
26 |
#define ADC_PIN PIN_A0 //info, nelze menit - pin pouzit jako input analog |
27 |
#define ADC_PIN PIN_A0 //info, nelze menit - pin pouzit jako input analog |
27 |
#define ADC_PIN_NC PIN_A1 //info, nelze menit - pin pouzit jako input analog |
28 |
#define ADC_PIN_NC PIN_A1 //info, nelze menit - pin pouzit jako input analog |
28 |
#define REF_PIN PIN_A3 //info, nelze menit - pin pouzit jako input reference 2.5V |
29 |
#define REF_PIN PIN_A3 //info, nelze menit - pin pouzit jako input reference 2.5V |
29 |
|
30 |
|
30 |
// interni |
31 |
// interni |
31 |
#define PowerOn() output_low(POWER_T4);output_low(POWER_T5) |
32 |
#define PowerOn() output_low(POWER_T4);output_low(POWER_T5) |
32 |
#define PowerOff() output_high(POWER_T4);output_high(POWER_T5) |
33 |
#define PowerOff() output_high(POWER_T4);output_high(POWER_T5) |
33 |
|
34 |
|
34 |
// globalni promenne |
35 |
// globalni promenne |
35 |
struct time |
36 |
struct time |
36 |
{ |
37 |
{ |
37 |
volatile unsigned int8 hod; |
38 |
volatile unsigned int8 hod; |
38 |
volatile unsigned int8 min; |
39 |
volatile unsigned int8 min; |
39 |
volatile unsigned int8 sec; |
40 |
volatile unsigned int8 sec; |
40 |
}cas; |
41 |
}cas; |
41 |
|
42 |
|
- |
|
43 |
unsigned int top_heat_power=0; // range 0-200% nad 100% je ale teleso jiz pretizene |
- |
|
44 |
unsigned int bottom_heat_power=0; // contains heating power range 0-100% |
42 |
// funkce |
45 |
unsigned int period; |
- |
|
46 |
|
- |
|
47 |
float temp_last=0; |
- |
|
48 |
|
43 |
void GeneralCpuInit() |
49 |
void GeneralCpuInit() // inicializace |
44 |
{ |
50 |
{ |
45 |
output_high(POWER_T4); |
51 |
output_high(POWER_T4); |
46 |
output_high(POWER_T5); |
52 |
output_high(POWER_T5); |
47 |
port_b_pullups(true); |
53 |
port_b_pullups(true); |
48 |
|
54 |
|
49 |
setup_psp(PSP_DISABLED); |
55 |
setup_psp(PSP_DISABLED); |
50 |
setup_spi(SPI_SS_DISABLED); |
56 |
setup_spi(SPI_SS_DISABLED); |
51 |
|
57 |
|
52 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); //nepouzit |
58 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); //nepouzit |
53 |
setup_timer_1(T1_DISABLED); //nepouzit |
59 |
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); // rizeni |
54 |
setup_timer_2(T2_DIV_BY_16,249,10); //rtc 40ms |
60 |
setup_timer_2(T2_DIV_BY_16,249,10); //rtc 40ms |
55 |
|
61 |
|
56 |
setup_comparator(NC_NC_NC_NC); |
62 |
setup_comparator(NC_NC_NC_NC); |
57 |
setup_vref(FALSE); |
63 |
setup_vref(FALSE); |
58 |
|
64 |
|
59 |
enable_interrupts(GLOBAL); |
65 |
enable_interrupts(GLOBAL); |
60 |
enable_interrupts(INT_TIMER2); |
66 |
enable_interrupts(INT_TIMER2); |
61 |
|
67 |
|
62 |
setup_adc_ports(AN0_AN1_VSS_VREF); //A0 vstup cidla, A1 nepozit, A3 - ref. 2.5V |
68 |
setup_adc_ports(AN0_AN1_VSS_VREF); //A0 vstup cidla, A1 nepozit, A3 - ref. 2.5V |
63 |
setup_adc(ADC_CLOCK_DIV_8); |
69 |
setup_adc(ADC_CLOCK_DIV_8); |
64 |
SET_ADC_CHANNEL(0); //AN0, PIN_A0 |
70 |
SET_ADC_CHANNEL(0); //AN0, PIN_A0 |
65 |
} |
71 |
} |
66 |
|
72 |
|
67 |
unsigned int16 adc(void) |
73 |
unsigned int16 adc(void) |
68 |
{ |
74 |
{ |
69 |
unsigned int16 analog; |
75 |
unsigned int16 analog; |
70 |
unsigned int8 a; |
76 |
unsigned int8 a; |
71 |
|
77 |
|
72 |
analog = 0; |
78 |
analog = 0; |
73 |
for (a=0;a<32;a++) |
79 |
for (a=0;a<32;a++) |
74 |
{ |
80 |
{ |
75 |
analog += read_adc(); |
81 |
analog += read_adc(); |
76 |
delay_us(50); |
82 |
delay_us(50); |
77 |
} |
83 |
} |
78 |
return (analog >> 5 ); // prumer = analog/32 |
84 |
return (analog >> 5 ); // prumer = analog/32 |
79 |
} |
85 |
} |
80 |
|
86 |
|
81 |
float teplota(void) |
87 |
float teplota(void) |
82 |
{ |
88 |
{ |
83 |
return (0.674201*adc() - 294.35); |
89 |
return (0.674201*adc() - 294.35); |
84 |
} |
90 |
} |
85 |
|
91 |
|
- |
|
92 |
void top_heating() |
- |
|
93 |
{ |
- |
|
94 |
if (period <= top_heat_power){ |
- |
|
95 |
output_low(POWER_T4); |
- |
|
96 |
output_low(POWER_T5); |
- |
|
97 |
} |
- |
|
98 |
else{ |
- |
|
99 |
output_high(POWER_T4); |
- |
|
100 |
output_high(POWER_T5); |
- |
|
101 |
} |
- |
|
102 |
} |
- |
|
103 |
|
- |
|
104 |
void bottom_heating() |
- |
|
105 |
{ |
- |
|
106 |
|
- |
|
107 |
if (period <= 2*bottom_heat_power){ |
- |
|
108 |
output_low(POWER_T3); |
- |
|
109 |
} |
- |
|
110 |
else{ |
- |
|
111 |
output_high(POWER_T3); |
- |
|
112 |
} |
- |
|
113 |
|
- |
|
114 |
} |
- |
|
115 |
|
- |
|
116 |
#int_TIMER1 |
- |
|
117 |
void heating_control() //rizeni topnych teles pri preteceni casovace |
- |
|
118 |
{ |
- |
|
119 |
|
- |
|
120 |
top_heating(); |
- |
|
121 |
bottom_heating(); |
- |
|
122 |
|
- |
|
123 |
if (period <= 200) period++; |
- |
|
124 |
else period=0; |
- |
|
125 |
} |
- |
|
126 |
|
86 |
|
127 |
|
87 |
#int_TIMER2 |
128 |
#int_TIMER2 |
88 |
void Rtc(void) //40ms |
129 |
void Rtc(void) //40ms |
89 |
{ |
130 |
{ |
90 |
static unsigned int8 ms40=0; |
131 |
static unsigned int8 ms40=0; |
91 |
struct time* time; |
132 |
struct time* time; |
92 |
|
133 |
|
93 |
time=&cas; |
134 |
time=&cas; |
94 |
if ( ++ms40 < 25) return; |
135 |
if ( ++ms40 < 25) return; |
95 |
|
136 |
|
96 |
ms40=0; |
137 |
ms40=0; |
97 |
if (++(time->sec) >= 60) |
138 |
if (++(time->sec) >= 60) |
98 |
{ |
139 |
{ |
99 |
time->sec=0; //1min |
140 |
time->sec=0; //1min |
100 |
if (++(time->min) >= 60) |
141 |
if (++(time->min) >= 60) |
101 |
{ |
142 |
{ |
102 |
time->min = 0; //1hod |
143 |
time->min = 0; //1hod |
103 |
(time->hod)++; |
144 |
(time->hod)++; |
104 |
} |
145 |
} |
105 |
} |
146 |
} |
106 |
} |
147 |
} |
107 |
|
148 |
|
- |
|
149 |
void slope_control(float ramp, unsigned int balance) // P proporcionalni rizeni narustu teploty predpoklada periodicke volani 1x/s |
- |
|
150 |
{ |
- |
|
151 |
float slope_deviation; |
- |
|
152 |
|
- |
|
153 |
slope_deviation = (teplota() - temp_last) - ramp; // vypocet strmosti a odchylky od pozadovane strmosti |
- |
|
154 |
|
- |
|
155 |
if(slope_deviation < 0) |
- |
|
156 |
{ |
- |
|
157 |
top_heat_power= slope_deviation*(-10) + balance; |
- |
|
158 |
bottom_heat_power= slope_deviation*(-10); |
- |
|
159 |
} |
- |
|
160 |
else{ |
- |
|
161 |
top_heat_power=0; |
- |
|
162 |
bottom_heat_power=0; |
- |
|
163 |
} |
- |
|
164 |
|
- |
|
165 |
temp_last = teplota(); |
- |
|
166 |
} |
- |
|
167 |
|
- |
|
168 |
void level_control(float level) // P proporcionalni rizeni teploty |
- |
|
169 |
{ |
- |
|
170 |
|
- |
|
171 |
teplota(); |
- |
|
172 |
|
- |
|
173 |
} |
- |
|
174 |
|
- |
|
175 |
|
108 |
void nullcas(struct time* time) |
176 |
void nullcas(struct time* time) |
109 |
{ |
177 |
{ |
110 |
disable_interrupts(INT_TIMER2); |
178 |
disable_interrupts(INT_TIMER2); |
111 |
|
179 |
|
112 |
time->sec=0; |
180 |
time->sec=0; |
113 |
time->hod=0; |
181 |
time->hod=0; |
114 |
time->min=0; |
182 |
time->min=0; |
115 |
|
183 |
|
116 |
enable_interrupts(INT_TIMER2); |
184 |
enable_interrupts(INT_TIMER2); |
117 |
} |
185 |
} |
118 |
|
186 |
|
- |
|
187 |
void reflow_solder() |
- |
|
188 |
{ |
- |
|
189 |
|
- |
|
190 |
// preheat |
- |
|
191 |
nullcas(&cas); |
- |
|
192 |
|
- |
|
193 |
do { |
- |
|
194 |
slope_control(PREHEAT_SLOPE, 0); // hlida strmost predehrevu |
- |
|
195 |
|
- |
|
196 |
lcd_gotoxy(1,1); |
- |
|
197 |
printf(lcd_putc,"%3.1f\21C ",teplota()); |
- |
|
198 |
|
- |
|
199 |
lcd_gotoxy(9,1); |
- |
|
200 |
printf(lcd_putc,"%2u:%02u:%02u",cas.hod,cas.min,cas.sec); |
- |
|
201 |
|
- |
|
202 |
delay_ms(1000); |
- |
|
203 |
} |
- |
|
204 |
while (teplota() < SOAK_TEMP); |
- |
|
205 |
|
119 |
// start |
206 |
// soak |
- |
|
207 |
nullcas(&cas); |
- |
|
208 |
while (cas.min*60+cas.sec <= SOAK_TIME) |
- |
|
209 |
{ |
- |
|
210 |
level_control(SOAK_TEMP); |
- |
|
211 |
|
- |
|
212 |
lcd_gotoxy(1,1); |
- |
|
213 |
printf(lcd_putc,"%3.1f\21C ",teplota()); |
- |
|
214 |
|
- |
|
215 |
lcd_gotoxy(9,1); |
- |
|
216 |
printf(lcd_putc,"%2u:%02u:%02u",cas.hod, SOAK_TIME/60 - cas.min, SOAK_TIME - cas.min*60 - cas.sec); |
- |
|
217 |
delay_ms(1000); |
- |
|
218 |
} |
- |
|
219 |
|
- |
|
220 |
// solder |
- |
|
221 |
|
- |
|
222 |
} |
- |
|
223 |
|
- |
|
224 |
|
120 |
void main() |
225 |
void main() // main loop |
121 |
{ |
226 |
{ |
122 |
int8 tmp; |
- |
|
123 |
GeneralCpuInit(); |
227 |
GeneralCpuInit(); |
124 |
PowerOff(); |
228 |
PowerOff(); |
125 |
|
229 |
|
126 |
lcd_init(); |
230 |
lcd_init(); |
127 |
lcd_define_char(1,LCD_CHAR_STUPEN); |
231 |
lcd_define_char(1,LCD_CHAR_STUPEN); |
128 |
|
232 |
|
129 |
nullcas(&cas); |
233 |
nullcas(&cas); |
130 |
|
234 |
|
131 |
while(true) |
235 |
while(true) |
132 |
{ |
236 |
{ |
133 |
delay_ms(300); |
237 |
delay_ms(300); |
134 |
|
- |
|
135 |
if (cas.sec != tmp){ |
- |
|
136 |
tmp=cas.sec; |
- |
|
137 |
lcd_gotoxy(9,1); |
- |
|
138 |
printf(lcd_putc,"%2u:%02u:%02u",cas.hod,cas.min,cas.sec); |
- |
|
139 |
} |
- |
|
140 |
|
238 |
|
141 |
lcd_gotoxy(1,2); |
239 |
|
142 |
printf(lcd_putc,"teplota: %3.1f\21C ",teplota()); |
240 |
reflow_solder(); |
- |
|
241 |
|
143 |
} |
242 |
} |
144 |
} |
243 |
} |