luefter_fsm.c
1 | #define TABLE_SIZE 5
| 2 |
| 3 | int kennlinie[TABLE_SIZE][3] = {
| 4 | // Lüfterleistung % , Schaltschwelle hoch, Schaltschwelle runter
| 5 | { 0, 20, 0 },
| 6 | { 20, 25, 15},
| 7 | { 40, 30, 20},
| 8 | { 50, 35, 25},
| 9 | {100, 0, 30},
| 10 | };
| 11 |
| 12 | int get_temperature(void) {
| 13 |
| 14 | int temp=0;
| 15 | // temperatur auslesen und rückliefern
| 16 | return temp;
| 17 | };
| 18 |
| 19 | void set_fan(int power) {
| 20 | // Lüfter einstellen, PWM und so
| 21 | }
| 22 |
| 23 | int main(void) {
| 24 |
| 25 | int fan_index=0;
| 26 | int temperature;
| 27 |
| 28 | while (1) {
| 29 | temperature = get_temperature();
| 30 |
| 31 | // Lüfter regeln
| 32 | if ((fan_index <(TABLE_SIZE-2)) && temperature >=kennlinie[fan_index][1]) { // zu warm, hochchalten
| 33 | fan_index++;
| 34 | set_fan(kennlinie[fan_index][0]);
| 35 | } else if((fan_index > 0) && temperature <=kennlinie[fan_index][2]) { // zu kalt, runter schalten
| 36 | fan_index--;
| 37 | set_fan(kennlinie[fan_index][0]);
| 38 | }
| 39 |
| 40 | }
| 41 |
| 42 | }
|
|