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;
60 volatile char ztime = 0;
65 volatile char trdelay = 0;
70 * Timer 0 cycles timing sensitive subsystems
71 * Timer 1 is used for global timing
82 * B0..2 = Pulse sensor
101 * D3 = NTC Op-amp (INT1)
111 unsigned char bindisp(unsigned char num)
135 void display(char num)
137 dsp[0] = font[(num / 10) % 10];
138 dsp[1] = font[num % 10];
141 void disphex(unsigned char num)
143 dsp[0] = font[(num & 0xf0) >> 4];
144 dsp[1] = font[num & 0x0f];
147 unsigned long getticks(void)
149 return(TCNT1 + (((unsigned long)oticks) << 16));
154 static uint16_t last = 0;
157 if(TCNT1 - last > LCDELAY) {
164 if(dsp[ledc] & (1 << leda)) {
170 d = 0x10 << (leda - 6);
178 PORTD = (PORTD & 0x0f) | d;
186 if((PIND & 8) && (tlock == 0)) {
193 } else if(tstate == 1) {
194 if(mnow - tstart > 1000) {
208 ttimea = ((ttimea * 15) + ttime) >> 4;
216 static char state = 0;
217 static unsigned long last = 0;
218 static float a, ra, l, t;
222 * t = RC * ln(2) => R = t / (C * ln(2))
223 * R = A * exp(B / T) => T = B / ln(R / A)
224 * T = B / ln(R / (A * C * ln(2)))
226 * a = ttimea as float
227 * C = 1e6 / (A * C * ln(2))
231 * Note, temperature is in Kelvin
236 if((mnow - last > 200000) && tavgok) {
242 } else if(state == 1) {
245 } else if(state == 2) {
248 } else if(state == 3) {
251 } else if(state == 4) {
281 /* Display temperature */
284 if((tempk >= 273) && (tempk <= 372)) {
285 display(tempk - 273);
287 dsp[0] = dsp[1] = SEGG;
302 } else if(state == 1) {
315 if(mnow - utime > 1000000) {
322 } else if(state == 2) {
324 display((ttimea / 100) % 100);
329 display(ttimea / 1000);
338 dsp[0] = bindisp((ttimea & 0xff00) >> 8);
339 dsp[1] = bindisp(ttimea & 0x00ff);
342 disphex((ttimea & 0xff000) >> 12);
349 display((ttimea / 100) % 100);
354 display(ttimea / 1000);
393 Pulse counter display
431 ttime = now - tstart;
438 ISR(SIG_OUTPUT_COMPARE0A)
442 if(tron && (ztime >= trdelay)) {
447 } else if(trstate == 1) {
464 if((sstate == 0) && !(PINB & 4)) {
468 if((sstate == 1) && (PINB & 4)) {
469 stime = oticks - stime;
473 if((PINB & 2) == 0) {
475 } else if((PINB & 1) == 0) {
478 } else if(pstate == 1) {
479 if((PINB & 1) == 0) {
485 } else if(pstate == 2) {
486 if((PINB & 2) == 0) {
493 if((PINB & 2) && (PINB & 1))