-
Notifications
You must be signed in to change notification settings - Fork 0
/
pid_test.c
65 lines (59 loc) · 1.29 KB
/
pid_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#ifdef _WIN32
#include <time.h>
#endif
#ifdef linux
#include <unistd.h>
#endif
#include "my_pid.h"
int main(void)
{
#ifdef _WIN32
printf("windows platform!\n");
#endif
#ifdef linux
printf("linux platform!\n");
#endif
/* 1. Init the PID params */
PID_Init();
/* 2. Set tarTemp */
for (uint8_t i = 0; i < PID_CH_NUM; i++)
{
tempCtrl[i].tarTemp = 60;
}
/* 3. According the tarTemp to decide the pidCtrlDir, if have the pidCtrlDir control */
#if PID_ENABLE_CTRL_DIR_SPLIT
for (uint8_t i = 0; i < PID_CH_NUM; i++)
{
if (GET_CUR_TEMP(i) < tempCtrl[i].tarTemp)
{
tempCtrl[i].pidCtrlDir = PID_CTRL_DIR_HEAT;
}
else
{
tempCtrl[i].pidCtrlDir = PID_CTRL_DIR_COLD;
}
}
#endif /* PID_ENABLE_CTRL_DIR_SPLIT */
/* 4. Enable the PID control */
for (uint8_t i = 0; i < PID_CH_NUM; i++)
{
tempCtrl[i].pidCtrlSta = PID_CTRL_STA_ENABLE;
}
/* 5. start PID control */
while (1)
{
for (uint8_t i = 0; i < PID_CH_NUM; i++)
{
PID(i, &tempCtrl[i]);
}
printf("\r\n");
#ifdef _WIN32
_sleep(1000); /* delay in ms */
#endif
#ifdef linux
usleep(1000000); /* delay in us*/
#endif
}
return 0;
}