Sign in to follow this  
Followers 0
Roze

Need help with RS485 comm for CP1L

3 posts in this topic

Hi,
I'm trying to build a very simple communications module for talking to a Danfoss FC51 Inverter, however, I'm stuck and is getting error on trying to change the speed...
Anyone familiar with how to use the Serial Comms that could help with how its done? Rewrite in ladder is OK too, I'm just not good enough to do this heavy things in ladder.



//Kind regards.

(*
Internal Vars: 
Modbus_CommandData_Port1  =  WORD[50] @ D32200
TempHi = WORD
TempLow = WORD
Modbus_Port1_Executing_Bit = BOOL @ A641.00
Modbus_Port1_Executing_ErrorFlag = BOOL @ A641.02
Busy = BOOL
Modbus_ReceiveData_Port1 = WORD[50] @ D32250
InternalStartState = BOOL
InternalSpeed = REAL

Inputs:
EN = BOOL
SlaveID = INT
Speed = REAL
Start = BOOL
ErrorClear = BOOL

Output:
ENO = BOOL
Done = BOOL
Error = BOOL

*)

(* 
enum{
ReadCoils = 0x1;
ReadHoldingRegisters = 0x3;
WriteSingleCoil = 0x5;
WriteSingleRegister = 0x6;
WriteMultipleCoils = 0xF;
WriteMultipleRegisters = 0x10;
Diagnostics = 0xB;
ReportSlaveID = 0x11;
}
//DiagnosticSubNumbers:
enum{
RestartCommunications = 1;
ReturnDiagnosticsRegister = 2;
ClearCountersAndDigitalRegisters = 10;
ReturnBusMessageCount = 11;
ReturnBusCommunicationsCount = 12;
ReturnBusExceptionErrorCount = 13;
ReturnSlaveMessageCount = 14;
}
Coil 0 1
01 Preset reference LSB
02 Preset reference MSB
03 DC brake No DC brake
04 Coast stop No coast stop
05 Quick stop No quick stop
06 Freeze outp No freeze outp
07 Ramp stop Start
08 No function Reset
09 No jog Jog
10 Ramp 1 Ramp 2
11 Data not valid Data valid
12 Relay 1 off Relay 1 on
13 Not used Not used
14 Setup 1 Setup 2
15 Not used Not used
16 No reversing Reversing

33 Control not ready Control ready
34 Unit not ready Unit ready
35 Coasted Not coasted
36 Error, tripped
37 Error, no trip
38 Not used Not used
39 Error, trip locked
40 No warning Warning
41 Not on reference On reference
42 Hand mode Auto mode
43 Out of freq. range In frequency range
44 Not running Running
45 No res. brake fault Resistor brake fault
46 No voltage warning Voltage warning
47 Not in current limit Current limit
48 No thermal warning Thermal warning

Register number Description
00001 – 00006 Reserved
00007 Last error code. See sectionException and Error Codes.
00008 Reserved
00009 Parameter index*
00100 – 00999 000 parameter group (parameters 001 through 099)
01000 – 01999 100 parameter group (parameters 100 through 199)
02000 – 02999 200 parameter group (parameters 200 through 299)
03000 – 03999 300 parameter group (parameters 300 through 399)
04000 – 04999 400 parameter group (parameters 400 through 499)
… …
49000 – 49999 4900 parameter group (parameters 4900 through 4999)
50000 Input data: Frequency converter control word register (CTW).
50010 Input data: Bus reference register (REF).
… …
50200 Output data: Frequency converter status word register (STW).
50210 Output data: Frequency converter main actual value register (MAV).
*)

IF EN THEN
IF NOT Busy AND InternalSpeed <> Speed THEN
InternalSpeed := Speed;
Busy:= TRUE;
Modbus_ReceiveData_Port1[4]:= INT_TO_WORD(0);
Modbus_CommandData_Port1[0] := INT_TO_WORD(SlaveID);
Modbus_CommandData_Port1[1] := INT_TO_WORD(16#0F);
Modbus_CommandData_Port1[2] := INT_TO_WORD(16#00);
Modbus_CommandData_Port1[3] := INT_TO_WORD(16#10);
Modbus_CommandData_Port1[4] := INT_TO_WORD(16#00);
Modbus_CommandData_Port1[5] := INT_TO_WORD(16#10);
Modbus_CommandData_Port1[6] := INT_TO_WORD(16#02);
TempHi:= INT_TO_WORD(REAL_TO_INT(InternalSpeed / INT_TO_REAL(256)));
TempLo:= INT_TO_WORD(REAL_TO_INT(InternalSpeed - INT_TO_REAL(WORD_TO_INT(TempHi) *  256)));
Modbus_CommandData_Port1[7] := TempHi;
Modbus_CommandData_Port1[8] := TempHi;
Modbus_Port1_Executing_Bit:= true;
END_IF;
IF NOT Busy AND InternalStartState <> Start THEN
InternalStartState:= Start;
Busy:= TRUE;
Modbus_ReceiveData_Port1[4]:= INT_TO_WORD(0);
Modbus_CommandData_Port1[0] := INT_TO_WORD(SlaveID);
Modbus_CommandData_Port1[1] := INT_TO_WORD(16#05);
Modbus_CommandData_Port1[2] := INT_TO_WORD(16#00);
Modbus_CommandData_Port1[3] := INT_TO_WORD(16#07);
IF(Start)THEN
Modbus_CommandData_Port1[4] := INT_TO_WORD(16#FF);
ELSE
Modbus_CommandData_Port1[4] := INT_TO_WORD(16#00);
END_IF;
Modbus_CommandData_Port1[5] := INT_TO_WORD(16#00);
Modbus_Port1_Executing_Bit:= true;
END_IF;
IF Modbus_Port1_Executing_ErrorFlag OR ( Busy AND Modbus_ReceiveData_Port1[2] <> 0) THEN
Error:= TRUE;
END_IF;
IF Busy AND Modbus_ReceiveData_Port1[4] = 16#0004 THEN
Done:= TRUE;
Busy:= FALSE;
END_IF;
IF ErrorClear AND Error THEN
Error:= false;
END_IF;
END_IF;
Edited by Roze

Share this post


Link to post
Share on other sites

Thank you for the links. I had missed the fact that its 3 words and then the message in bytes.... :P

In any case, here is my work in case anyone else wants it. VERY simple communications, no feedback or status checking.
https://anonfile.com/Z6pdU8c6b9/VFD_FC51.cxf

//Kind regards

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0