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,
34 uint8_t dsp[2] = {0, 0};
39 volatile int oticks = 0;
42 volatile char pstate = 0;
45 volatile char sstate = 0;
48 volatile char tstate = 0;
49 volatile char tlock = 0;
52 unsigned long ttimea = 10000;
57 /* Zero-cross detector*/
58 volatile char zok = 0;
59 volatile char ztime = 0;
64 volatile char trdelay = 0;
69 * Timer 0 cycles the Triac
70 * Timer 1 is used for global timing
71 * Timer 2 cycles the LED display
86 * B0..2 = Pulse sensor
105 * D3 = NTC Op-amp (INT1)
115 unsigned char bindisp(unsigned char num)
139 void display(char num)
141 dsp[0] = font[(num / 10) % 10];
142 dsp[1] = font[num % 10];
145 void disphex(unsigned char num)
147 dsp[0] = font[(num & 0xf0) >> 4];
148 dsp[1] = font[num & 0x0f];
151 unsigned long getticks(void)
153 return(TCNT1 + (((unsigned long)oticks) << 16));
165 if(dsp[ledc] & (1 << leda)) {
171 d = 0x10 << (leda - 6);
178 PORTD = (PORTD & 0x0f) | d;
184 if((PIND & 8) && (tlock == 0)) {
191 } else if(tstate == 1) {
192 if(mnow - tstart > 1000) {
206 ttimea = ((ttimea * 15) + ttime) >> 4;
214 static char state = 0;
215 static unsigned long last = 0;
216 static float a, ra, l, t;
220 * t = RC * ln(2) => R = t / (C * ln(2))
221 * R = A * exp(B / T) => T = B / ln(R / A)
222 * T = B / ln(R / (A * C * ln(2)))
224 * a = ttimea as float
225 * C = 1e6 / (A * C * ln(2))
229 * Note, temperature is in Kelvin
234 if((mnow - last > 200000) && tavgok) {
240 } else if(state == 1) {
243 } else if(state == 2) {
246 } else if(state == 3) {
249 } else if(state == 4) {
278 /* Display temperature */
281 if((tempk >= 273) && (tempk <= 372)) {
282 display(tempk - 273);
284 dsp[0] = dsp[1] = SEGG;
299 } else if(state == 1) {
312 if(mnow - utime > 1000000) {
319 } else if(state == 2) {
321 display((ttimea / 100) % 100);
326 display(ttimea / 1000);
335 dsp[0] = bindisp((ttimea & 0xff00) >> 8);
336 dsp[1] = bindisp(ttimea & 0x00ff);
339 disphex((ttimea & 0xff000) >> 12);
346 display((ttimea / 100) % 100);
351 display(ttimea / 1000);
390 Pulse counter display
428 ttime = now - tstart;
435 ISR(SIG_OUTPUT_COMPARE0A)
439 if(tron && (ztime >= trdelay)) {
444 } else if(trstate == 1) {
453 ISR(SIG_OUTPUT_COMPARE2A)
466 if((sstate == 0) && !(PINB & 4)) {
470 if((sstate == 1) && (PINB & 4)) {
471 stime = oticks - stime;
475 if((PINB & 2) == 0) {
477 } else if((PINB & 1) == 0) {
480 } else if(pstate == 1) {
481 if((PINB & 1) == 0) {
487 } else if(pstate == 2) {
488 if((PINB & 2) == 0) {
495 if((PINB & 2) && (PINB & 1))