Hi everyone,
I have a number of registers that I'm reading from my VFD (via modbus) that have some small scaling calculations done to them and eventually become values for a diagnostics tab in my screenset.
For some reason, only some of the code appears to be getting executed (the "Set target ROM and DRO" block). What am I missing here?
-- ************************* BrSp 02/22/23 **************************************
---------------------------------------------------------
-- set Target RPM and DRO
---------------------------------------------------------
RPM=mc.mcSpindleGetCommandRPM(inst); -- Use mcSpindleGetCommandRPM
local hRPM=mc.mcRegGetHandle(inst,"iRegs0/MbVFD/SetRPM");
mc.mcRegSetValue(hRPM,RPM);
--Spindle Override Check
local OVRenable=mc.mcSpindleGetOverrideEnable(inst);
if OVRenable then;
local OVR=mc.mcSpindleGetOverride(inst);
RPM=RPM*OVR;
end;
local range=mc.mcSpindleGetCurrentRange(inst)
if RPM>mc.mcSpindleGetMaxRPM(inst,range) then RPM=mc.mcSpindleGetMaxRPM(inst,range) end;
if RPM<mc.mcSpindleGetMinRPM(inst,range) then RPM=mc.mcSpindleGetMinRPM(inst,range) end;
-- Calc and set the frequency to the VFD
local freq=RPM/6*10; -- ie 24000 rpm /6 = 400Hz but WJ200VFD wants 4000 as input (no decimals)
local hsetHz=mc.mcRegGetHandle(inst,"iRegs0/MbVFD/SetHz");
mc.mcRegSetValue(hsetHz,freq);
local hfreq=mc.mcRegGetHandle(inst,"MbVFD/W_VFDSpd_Hz");
mc.mcRegSetValue(hfreq,freq);
-- Get the actual RPM from the VFD
local aFreq=mc.mcRegGetHandle(inst,"MbVFD/R_VFDRPM_Hz");
local hActRPM=mc.mcRegGetHandle(inst,"iRegs0/MbVFD/ActRPM");
local readBackRPM=aFreq/10*6;
mc.mcSpindleSetSensorRPM(inst,readBackRPM);
mc.mcRegSetValue(hActRPM,readBackRPM);
---------------------------------------------------------
-- scale VFD readbacks
---------------------------------------------------------
local iVolts=mc.mcRegGetHandle(inst,"MbVFD/R_VFDVolt_V");
local hVolts=mc.mcRegGetHandle(inst,"iRegs0/MbVFD/Volts_S");
local readBackVolts=iVolts/10;
mc.mcRegSetValue(hVolts,readBackVolts);
local iPwr=mc.mcRegGetHandle(inst,"MbVFD/R_VFDpwr_KW");
local hPwr=mc.mcRegGetHandle(inst,"iRegs0/MbVFD/KW_S");
local readBackPwr=iPwr/10;
mc.mcRegSetValue(hPwr,readBackPwr);
local iCur=mc.mcRegGetHandle(inst,"MbVFD/R_VFDcurr_A");
local hCur=mc.mcRegGetHandle(inst,"iRegs0/MbVFD/Curr_S");
local readBackCur=iCur/10;
mc.mcRegSetValue(hCur,readBackCur);
local iTemp=mc.mcRegGetHandle(inst,"MbVFD/R_VFDTemp_C");
local hTemp=mc.mcRegGetHandle(inst,"iRegs0/MbVFD/Temp_S");
local readBackTemp=iTemp/10;
mc.mcRegSetValue(hTemp,readBackTemp);
-- **************************************************************************
The Current value "R_VFDcurr_A" is a perfect example. The value coming back from the VFD is 0, as is the register it is stored in. But somehow, the Curr_S register is not being updated. The script posted above is being executed correctly for the "SetRPM" and "SetHz" values.
Any thoughts?
If I set the initial values for the Curr_S register to a value, that value is quickly overwritten by the value you see and then is static.