-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhal2mbvfd.comp
32 lines (28 loc) · 1.25 KB
/
hal2mbvfd.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
component hal2mbvfd "exchange HAL pins for mb2hal values, Fuling DZB300 series VFD";
pin in float RpmIn "RPM set value, in";
pin out s32 PercentOut "RPM percent value, out";
pin in bit VfdFwd "Run VFD in Forward Direction";
pin in bit VfdRev "Run VFD in Reverse Direction";
pin out s32 VfdCtrlOut "send the VFD control signal to MB2HAL pin";
pin in float VfdRunFreqIn "running Frequency of VFD/Motor";
pin out float VfdRunRpsOut "RPS conversion of VFD/Motor RPM";
pin out float VfdRunRpmOut "VFD/Motor RPM";
pin out bit SpindFan "turn on the spindle cooling fan";
pin in float SpinTempC "spindle temp in C";
pin out float SpinTempF "spindle temp out F";
function _;
license "GPL";
author "Travis Farmer";
;;
double map(double x, double in_min, double in_max, double out_min, double out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
FUNCTION(_) {
PercentOut = (int)map(RpmIn,0,24000,0,10000);
if (VfdFwd == true) {VfdCtrlOut = 0x0001; SpindFan = true;}
else if (VfdRev == true) {VfdCtrlOut = 0x0002; SpindFan = true;}
else {VfdCtrlOut = 0x0005; SpindFan = false;}
VfdRunRpmOut = (120 * (VfdRunFreqIn / 10)) / 4;
VfdRunRpsOut = VfdRunRpmOut / 60;
SpinTempF = (SpinTempC / 1000);
}