dsp[1] = font[num & 0x0f];
}
-/*
- * This version is used outside interrupts.
- * It spins until no overflow has happened.
- */
unsigned long getticks(void)
{
uint16_t v;
unsigned long r;
- do {
- v = oticks;
- r = TCNT1 + (((unsigned long)oticks) << 16);
- } while(v != oticks);
- return(r);
-}
-
-/*
- * This version is used in interrupts
- */
-unsigned long getticks2(void)
-{
- uint16_t v;
- unsigned long r;
-
+ cli();
v = TCNT1;
r = v + (((unsigned long)oticks) << 16);
if((TIFR1 & 0x01) && !(v & 0x8000))
- return(r + 0x10000);
- else
- return(r);
+ r += 0x10000;
+ sei();
+ return(r);
}
void ledcycle(void)
int main(void)
{
- int state, cur, run;
+ int state, cur, run, rstate, delta;
unsigned long utime;
state = 0;
cur = 100;
run = 0;
+ rstate = 0;
init();
sei();
display(0);
* Set Triac to match temperature
*/
if(run) {
- if(tempk - 273 < cur) {
- tron = 1;
- if(cur - (tempk - 273) > 5) {
- /* For some reason, the Triac currently doesn't
- * trigger on one of the AC half-cycles below 0.7
- * ms. */
- trdelay = 7;
- } else if(cur - (tempk - 273) >= 3) {
- trdelay = 20;
- } else if(cur - (tempk - 273) >= 2) {
- trdelay = 40;
+ delta = cur - (tempk - 273);
+ if(rstate == 0) {
+ if(delta > 0) {
+ tron = 1;
+ if(delta > 8) {
+ /* For some reason, the Triac currently doesn't
+ * trigger on one of the AC half-cycles below 0.7
+ * ms. */
+ trdelay = 7;
+ } else {
+ trdelay = 79 - (delta * 9);
+ }
} else {
- trdelay = 70;
+ tron = 0;
+ rstate = 1;
}
- } else {
+ } else if(rstate == 1) {
tron = 0;
+ if(delta >= 2)
+ rstate = 0;
}
} else {
tron = 0;
{
unsigned long now;
- now = getticks2();
+ now = getticks();
if(tstate == 0) {
tstate = 1;
if(tlock != 2)