forked from thecooltool/UNI-PRINT-3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thermistor_check.comp
134 lines (128 loc) · 4.27 KB
/
thermistor_check.comp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/******************************************************************************
*
* Copyright (C) 2014 Alexander Rössler
*
*
* This module checks the functionality of thermistors
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
* THE AUTHORS OF THIS PROGRAM ACCEPT ABSOLUTELY NO LIABILITY FOR
* ANY HARM OR LOSS RESULTING FROM ITS USE. IT IS _EXTREMELY_ UNWISE
* TO RELY ON SOFTWARE ALONE FOR SAFETY. Any machinery capable of
* harming persons must have provisions for completely removing power
* from all motors, etc, before persons enter any danger area. All
* machinery must be designed to comply with local and national safety
* codes, and the authors of this software can not, and do not, take
* any responsibility for such compliance.
*
* This code was written as part of the LinuxCNC project. For more
* information, go to www.linuxcnc.org.
*
******************************************************************************/
component thermistor_check "LinuxCNC HAL component for checking functionality of thermistors";
pin in float temp "Temperature input";
pin in float min_temp "The minimum temperature change that should count";
pin in float pid "Output of PID control";
pin in float min_pid "The minimum PID control output to react to";
pin in float bias "Bias for the PID input. Can be used to correct errors due to cooling.";
pin in float wait "Time to wait before triggering an error in secods";
pin in bit enable "Enables or disables the component, out is TRUE when disabled";
pin out bit no_error "Output value -> TRUE when the thermistor works as exspected";
pin out bit error "Error value -> FALSE when the thermistor works as exspected";
function _ fp "Update the output value";
description """
Component for checking functionality of thermistors
.LP
TODO
""";
license "GPL";
variable hal_float_t last_temp = 0.0;
variable hal_bit_t last_enable = 0;
variable hal_float_t oldwait = 0.0;
variable int t_secs = 0;
variable int t_nsecs = 0;
variable int c_secs = 0;
variable int c_nsecs = 0;
variable hal_bit_t start = 0;
;;
FUNCTION(_) {
float temp_change;
float time;
if (wait != oldwait)
{
time = wait;
if (time < 0) time = 0; // no negative timeout periods
// new timeout, convert to secs/ns
oldwait = time;
t_secs = time;
time -= t_secs;
t_nsecs = (1e9 * time);
if (enable) {
// reset
start = 1;
}
}
if ((enable) && (pid >= (min_pid+bias)))
{
if (start == 1)
{
// reset
c_secs = t_secs;
c_nsecs = t_nsecs;
last_temp = temp;
start = 0;
}
else
{
c_nsecs -= period;
if (c_nsecs < 0)
{
c_nsecs += 1000000000;
if (c_secs > 0)
{
c_secs--;
}
else
{
start = 1; // restart
}
}
if (start == 1)
{
temp_change = temp - last_temp;
if (temp_change >= min_temp) // correct
{
no_error = 1;
error = 0;
}
else
{
no_error = 0;
error = 1;
}
}
}
}
else
{
start = 1;
no_error = 1;
error = 0;
}
}