2 #include <avr/interrupt.h>
16 SEGA | SEGB | SEGC | SEGD | SEGE | SEGF,
18 SEGA | SEGB | SEGD | SEGE | SEGG,
19 SEGA | SEGB | SEGC | SEGD | SEGG,
20 SEGB | SEGC | SEGF | SEGG,
21 SEGA | SEGC | SEGD | SEGF | SEGG,
22 SEGA | SEGC | SEGD | SEGE | SEGF | SEGG,
24 SEGA | SEGB | SEGC | SEGD | SEGE | SEGF | SEGG,
25 SEGA | SEGB | SEGC | SEGD | SEGF | SEGG,
26 SEGA | SEGB | SEGC | SEGE | SEGF | SEGG,
27 SEGC | SEGD | SEGE | SEGF | SEGG,
28 SEGA | SEGD | SEGE | SEGF,
29 SEGB | SEGC | SEGD | SEGE | SEGG,
30 SEGA | SEGD | SEGE | SEGF | SEGG,
31 SEGA | SEGE | SEGF | SEGG,
35 uint8_t dsp[2] = {0, 0};
40 volatile int oticks = 0;
43 volatile char pstate = 0;
46 volatile char sstate = 0;
49 volatile char tstate = 0;
50 volatile char tlock = 0;
53 unsigned long ttimea = 10000;
58 /* Zero-cross detector*/
59 volatile char zok = 0;
65 unsigned short trdelay = 0;
75 * B0..2 = Pulse sensor
94 * D3 = NTC Op-amp (INT1)
104 unsigned char bindisp(unsigned char num)
128 void display(char num)
130 dsp[0] = font[(num / 10) % 10];
131 dsp[1] = font[num % 10];
134 void disphex(unsigned char num)
136 dsp[0] = font[(num & 0xf0) >> 4];
137 dsp[1] = font[num & 0x0f];
140 unsigned long getticks(void)
142 return(TCNT1 + (((unsigned long)oticks) << 16));
147 static uint16_t last = 0;
150 if(TCNT1 - last > LCDELAY) {
157 if(dsp[ledc] & (1 << leda)) {
163 d = 0x10 << (leda - 6);
170 PORTD = (PORTD & 0x0f) | d;
177 if((PIND & 8) && (tlock == 0)) {
182 } else if(tstate == 1) {
183 if(mnow - tstart > 1000) {
195 ttimea = ((ttimea * 15) + ttime) >> 4;
203 static char state = 0;
204 static unsigned long last = 0;
205 static float a, ra, l, t;
209 * t = RC * ln(2) => R = t / (C * ln(2))
210 * R = A * exp(B / T) => T = B / ln(R / A)
211 * T = B / ln(R / (A * C * ln(2)))
213 * a = ttimea as float
214 * C = 1e6 / (A * C * ln(2))
218 * Note, temperature is in Kelvin
223 if((mnow - last > 200000) && tavgok) {
228 } else if(state == 1) {
231 } else if(state == 2) {
234 } else if(state == 3) {
237 } else if(state == 4) {
244 void triaccycle(void)
247 if(tron && zok && (mnow > ztime + trdelay)) {
253 } else if(trstate == 1) {
254 if(mnow > trtime + 500) {
285 /* Display temperature */
288 if((tempk >= 273) && (tempk <= 372)) {
289 display(tempk - 273);
291 dsp[0] = dsp[1] = SEGG;
306 } else if(state == 1) {
316 trdelay = 10000 - ((unsigned short)cur * 100);
319 if(mnow - utime > 1000000) {
326 } else if(state == 2) {
328 display((ttimea / 100) % 100);
333 display(ttimea / 1000);
342 dsp[0] = bindisp((ttimea & 0xff00) >> 8);
343 dsp[1] = bindisp(ttimea & 0x00ff);
346 disphex((ttimea & 0xff000) >> 12);
353 display((ttimea / 100) % 100);
358 display(ttimea / 1000);
383 trdelay = 10000 - ((unsigned short)cur * 100);
397 Pulse counter display
435 ttime = now - tstart;
450 if((sstate == 0) && !(PINB & 4)) {
454 if((sstate == 1) && (PINB & 4)) {
455 stime = oticks - stime;
459 if((PINB & 2) == 0) {
461 } else if((PINB & 1) == 0) {
464 } else if(pstate == 1) {
465 if((PINB & 1) == 0) {
471 } else if(pstate == 2) {
472 if((PINB & 2) == 0) {
479 if((PINB & 2) && (PINB & 1))