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
  // Temperatur lesen und rückliefern
14
};
15
16
void set_fan(int power) {
17
  // Lüfter einstellen, PWM und so
18
}
19
20
int main(void) {
21
22
int fan_index=0;
23
int  temperature;
24
volatile int tmp;    // für simulation
25
26
  while (1) {
27
    //temperature = get_temperature();    // für simulation auskommentiert
28
    tmp;                  // hier breakpoint setzen und temperatur verändern
29
    
30
    // Lüfter regeln
31
    if ((fan_index <(TABLE_SIZE-1)) && temperature >=kennlinie[fan_index][1]) {  // zu warm, hochchalten
32
      fan_index++;
33
      set_fan(kennlinie[fan_index][0]);
34
    } else if((fan_index > 0) && temperature <=kennlinie[fan_index][2]) {    // zu kalt, runter schalten
35
      fan_index--;
36
      set_fan(kennlinie[fan_index][0]);
37
    }
38
39
  }
40
41
}