Temperaturabhängige Lüftersteuerung

Aus Ethersex_Wiki
Version vom 31. Mai 2011, 12:34 Uhr von Mgue (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „<source lang="c"> CONTROL_START THREAD(mainloop) ON ONCE (1) DO dnl 0.425: x/600*255 (60° will result in 255 => maximum fan speed) …“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche
CONTROL_START
THREAD(mainloop)
        ON ONCE (1) DO
                dnl 0.425: x/600*255 (60° will result in 255 => maximum fan speed)
                double newvalue=0.425*(ONEWIRE_GET(28a4aae002000017));
                dnl Set fan to maximum
                if (newvalue > 255)
                        OCR2A = 0;
                dnl Disable the fan, cooling makes no sense
                else if(newvalue < 120)
                        OCR2A = 255;
                dnl Set the fan to the dynamic value
                else
                        OCR2A = 255-(uint8_t) newvalue;
        END
THREAD_END(mainloop)

ON STARTUP DO
        dnl PD7 has to be output
        DDRD |= 0b10000000;
        dnl FastPWM
        TCCR2A = (1 << COM2A1) | (1 << COM2A0) | (1 << WGM21) | (1 << WGM20);
        dnl Prescaler: 256
        TCCR2B = (1 << CS22) | (1 << CS21);
        dnl Maximum Speed
        OCR2A = 0;
        THREAD_START(mainloop)
END
CONTROL_END