Line 30... |
Line 30... |
30 |
#define HALFDUTY (int16)MAXDUTY/2 |
30 |
#define HALFDUTY (int16)MAXDUTY/2 |
31 |
//#define DIVISOR 199 // 10 kHz |
31 |
//#define DIVISOR 199 // 10 kHz |
32 |
#define DIVISOR 99 // 20 kHz |
32 |
#define DIVISOR 99 // 20 kHz |
33 |
//#define DIVISOR 39 // 50 kHz |
33 |
//#define DIVISOR 39 // 50 kHz |
34 |
|
34 |
|
35 |
#define MAX_OUTPUT 1000 |
35 |
#define MAX_OUTPUT 530 |
- |
|
36 |
#define raw_step 50 |
- |
|
37 |
#define fine_step 5 |
- |
|
38 |
|
- |
|
39 |
|
36 |
|
40 |
|
37 |
/// Linear interpolation parameters |
41 |
/// Linear interpolation parameters |
38 |
// |
42 |
// |
39 |
|
43 |
|
40 |
#define k 0.333961 |
44 |
#define k 0.333961 |
Line 84... |
Line 88... |
84 |
|
88 |
|
85 |
void main() |
89 |
void main() |
86 |
{ |
90 |
{ |
87 |
unsigned int1 button_press; // semafor pro cteni tlacitek |
91 |
unsigned int1 button_press; // semafor pro cteni tlacitek |
88 |
float output_voltage; |
92 |
float output_voltage; |
- |
|
93 |
float voltage_setpoint = 300; |
89 |
|
94 |
|
90 |
setup_adc_ports(sAN0|VSS_VREF); |
95 |
setup_adc_ports(sAN0|VSS_VREF); |
91 |
setup_adc(ADC_CLOCK_DIV_32); |
96 |
setup_adc(ADC_CLOCK_DIV_32); |
92 |
setup_spi(SPI_SS_DISABLED); |
97 |
setup_spi(SPI_SS_DISABLED); |
93 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
98 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
Line 133... |
Line 138... |
133 |
|
138 |
|
134 |
lcd_gotoxy(1,1); |
139 |
lcd_gotoxy(1,1); |
135 |
printf(lcd_putc,"%3.0f",output_voltage); |
140 |
printf(lcd_putc,"%3.0f",output_voltage); |
136 |
lcd_gotoxy(1,2); |
141 |
lcd_gotoxy(1,2); |
137 |
|
142 |
|
- |
|
143 |
voltage_setpoint = setpoint * k + q; |
- |
|
144 |
|
138 |
if(input(OUTPUT_ENABLE))printf(lcd_putc,"Set:%lu "setpoint); |
145 |
if(input(OUTPUT_ENABLE))printf(lcd_putc,"Set:%3.0f ", voltage_setpoint); |
139 |
else printf(lcd_putc,"DISABLED"); |
146 |
else printf(lcd_putc,"DISABLED"); |
140 |
|
147 |
|
141 |
if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta. |
148 |
if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta. |
142 |
{ |
149 |
{ |
- |
|
150 |
|
143 |
if(!input(S1)) |
151 |
if(!input(S1)) |
144 |
{ |
152 |
{ |
145 |
delay_ms(20); |
153 |
delay_ms(20); |
146 |
if(!input(S1)) |
154 |
if(!input(S1)) |
147 |
{ |
155 |
{ |
148 |
button_press=true; |
156 |
button_press=true; |
149 |
sound_beep(100,700); |
157 |
sound_beep(100,700); |
150 |
if(setpoint < (MAX_OUTPUT-5) )setpoint+=5; |
158 |
if(voltage_setpoint < (MAX_OUTPUT - raw_step) ) voltage_setpoint += raw_step; |
151 |
} |
159 |
} |
152 |
} |
160 |
} |
153 |
|
161 |
|
154 |
if(!input(S2)) |
162 |
if(!input(S2)) |
155 |
{ |
163 |
{ |
156 |
delay_ms(20); |
164 |
delay_ms(20); |
157 |
if(!input(S2)) |
165 |
if(!input(S2)) |
158 |
{ |
166 |
{ |
159 |
button_press=true; |
167 |
button_press=true; |
160 |
sound_beep(100,600); |
168 |
sound_beep(100,600); |
161 |
if(setpoint > 0x05 ) setpoint-=5; |
169 |
if(voltage_setpoint > raw_step ) voltage_setpoint -= raw_step; |
162 |
} |
170 |
} |
163 |
} |
171 |
} |
164 |
|
172 |
|
165 |
if(!input(S3)) |
173 |
if(!input(S3)) |
166 |
{ |
174 |
{ |
167 |
delay_ms(20); |
175 |
delay_ms(20); |
168 |
if(!input(S3)) |
176 |
if(!input(S3)) |
169 |
{ |
177 |
{ |
170 |
button_press=true; |
178 |
button_press=true; |
171 |
sound_beep(100,500); |
179 |
sound_beep(100,500); |
172 |
if(setpoint < MAX_OUTPUT )setpoint++; |
180 |
if(voltage_setpoint < MAX_OUTPUT - fine_step )voltage_setpoint += fine_step ; |
173 |
} |
181 |
} |
174 |
} |
182 |
} |
175 |
|
183 |
|
176 |
if(!input(S4)) |
184 |
if(!input(S4)) |
177 |
{ |
185 |
{ |
178 |
delay_ms(20); |
186 |
delay_ms(20); |
179 |
if(!input(S4)) |
187 |
if(!input(S4)) |
180 |
{ |
188 |
{ |
181 |
button_press=true; |
189 |
button_press=true; |
182 |
sound_beep(100,400); |
190 |
sound_beep(100,400); |
183 |
if(setpoint > 0x00 ) setpoint--; |
191 |
if(voltage_setpoint > 0 ) voltage_setpoint -= fine_step; |
184 |
} |
192 |
} |
185 |
} |
193 |
} |
- |
|
194 |
|
- |
|
195 |
setpoint =(int) ((voltage_setpoint - q) / k); |
186 |
} |
196 |
} |
187 |
|
197 |
|
188 |
if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false; |
198 |
if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false; |
189 |
output_toggle(LED1); |
199 |
output_toggle(LED1); |
190 |
} |
200 |
} |