/** * Copyright, 2015, SoftPLC Corporation ************************************************************************ * */ #ifndef TDK_H_ #define TDK_H_ /* This header is a "ticket to use" rather than an implementation header. An implementation header would expose details about the implemenation, whereas a ticket to use only exposes enough information on how to use the TLM from other logic in the control program, either ladder or C++. Because write serial commands are supported by setting bits in a trigger word, they can be set either from C++ in another TLM or using ladder. Reads are done continuously on a paced basis. There are 4 memory windows that each TDK FSM uses. Since this TLM currently supports two TDKs, this means 8 memory windows. Amoung the 4 for each, there are two INT blocks and two FLOAT blocks. Within the two INT blocks they are named WRITES and READS, likewise for the FLOAT blocks. This pertains to the direction of information flow wrt the TDKs. Only the public API to the TLM is exposed in here, the full implementation is largely private to the tdk.cc file, except for the stuff exposed in this header. */ #include /// These get put into TDK_INT_READS::Running_State enum RUNNING_STATES { RS_UNKNOWN = -1, // TDK manual made no mention of values leading to this conclusion RS_OFF_STATE, RS_CHARGE_STATE, RS_DISCHARGE_STATE, }; /// These get put into TDK_INT_READS::Alarm_State enum ALARM_STATES { AS_UNKNOWN = -1, // TDK manual made no mention of values leading to this conclusion AS_NO_ALARM, AS_LIGHT_ALARM, AS_HEAVY_ALARM, }; /// These get put into TDK_INT_READS::Op_Mode enum OP_MODES { OP_UNKNOWN = -1, // TDK manual made no mention of values leading to this conclusion OP_WAITING, OP_HETERONOMY_CV, OP_BATTERY_AUTONOMY, OP_GRID_AUTONOMY, }; /// These get put into TDK_INT_READS::Grid enum GRID_STATES { GRID_UNKNOWN = -1, // TDK manual made no mention of values leading to this conclusion GRID_NO_ALARM, GRID_OVERV, GRID_UNDERV, GRID_OVERCURRENT, }; /// These get put into TDK_INT_READS::Battery enum BATTERY_STATES { BATTERY_UNKNOWN = -1, // TDK manual made no mention of values leading to this conclusion BATTERY_NO_ALARM, BATTERY_OVERV, BATTERY_UNDERV, BATTERY_OVERCURRENT, }; /* The TDK TLM uses 4 datatable memory windows, per slave TDK. They are paritioned on datatype and directionality of the data. PLCFLOATs are grouped together and PLCINTs are grouped together so they can be positioned within a datatable file type of that matches for access by an HMI which knows how to read & write these types. Only backgroud READs happen normally. If you want to perform a WRITE, then set a bit in Write_Trigger after setting up the data in either write block associated with the trigger bit. After completion of the write, the trigger bit will be reset by the TLM. For this handshake to operate properly, you cannot stand on the trigger bit, you must either latch it or oneshot set it per write. */ /** * Struct TDK_INT_WRITES * are PLCINT values that get written to a TDK. */ struct TDK_INT_WRITES { PLCINT Write_Trigger; // 0 Bits in here fire TDK serial writes // bit no: #define WT_CHANGE_OP_MODE 0 // set this bit to send Write_Op_Mode. #define WT_WRITE_BAT_CONF1 1 // write battery config1, set Target_Module_V first #define WT_WRITE_BAT_CONF2 2 // write battery config2 #define WT_CV_DCHARGE 3 // set this bit to send CV_DISCHARGE. #define WT_CV_CHARGE 4 // set this bit to send CV_CHARGE. #define WT_WRITE_PROTECTION 5 // send CMD_PROTECTION_LIMITS #define WT_ALARM_CLEAR 6 // send CMD_ALARM_CLEAR PLCINT Write_Op_Mode; // CMD_CHANGE_OP_MODE, see page P.16/41 for legal values: // 0x0000 Waiting // 0x0001 Heteronomy CV Charging // 0x0002 Heteronomy CV Discharging // 0x0022 Heteronomy Discharging (CV with LVCD CC mode) // 0x0004 Battery Autonomy Mode // 0x0014 Grid Autonomy Mode // 0x0034 Grid Autonomy Discharging (CV with LVDC CC mode) }; /** * Struct TDK_INT_READS * are PLCINT values that are read from a TDK. */ struct TDK_INT_READS { PLCINT Running_State; // Charge/Discharge state from DCDC, enum RUNNING STATES PLCINT Alarm_State; // Alarm state from DCDC, enum ALARM_STATES PLCINT Op_Mode; // Current operating mode from DCDC, enum OP_MODES PLCINT Battery; // Battery state, enum BATTERY_STATES PLCINT Grid; // Grid state, enum GRID_STATES PLCINT Alarms; // bitmapped alarms, bits are: // bit number: #define ALRM_HW_OVERCURRENT 0 // from CMD_ALARM_STATUS #define ALRM_WAITING_EXTERNAL 1 // from CMD_ALARM_STATUS #define ALRM_PRI_HEATSINK_TEMP 2 // from CMD_ALARM_STATUS #define ALRM_SEC_HEATSINK_TEMP 3 // from CMD_ALARM_STATUS #define ALRM_DEVICE_TEMP 4 // from CMD_ALARM_STATUS #define ALRM_BATTERY_EMPTY 5 // from CMD_ALARM_STATUS #define ALRM_SYSTEM_FAULT 6 // from CMD_ALARM_STATUS #define ALRM_VOLTAGE_UPPER_LIMIT_WARNING 7 // from CMD_READ_STATUS #define ALRM_VOLTAGE_LOWER_LIMIT_WARNING 8 // from CMD_READ_STATUS // from CMD_READ_METER2: PLCINT FAN1; PLCINT FAN2; PLCINT FAN3; PLCINT FAN4; PLCINT FAN5; // counters for this driver, not info coming from TDK, all reset to zero on // change to RUN mode. PLCINT Tx_Count; // how many frames sent PLCINT Rx_Count; // how many replies receieved PLCINT Rx_Timeouts; // how many timeouts from this TDK. PLCINT Rx_Checksum_Errors; // how many checksum errors. PLCINT Rx_NAK_Count; // how many NAKs received. }; /** * Struct TDK_FLOAT_READS * are PLCFLOATS that are read from a TDK. */ struct TDK_FLOAT_READS { PLCFLOAT Grid_Voltage; // 0 ESS voltage from DCDC PLCFLOAT Grid_Current; // 1 ESS current from DCDC PLCFLOAT Grid_Watts; // 2 ESS power from DCDC PLCFLOAT Battery_Voltage; // 3 Module voltage from DCDC PLCFLOAT Battery_Current; // 4 Module current from DCDC PLCFLOAT Battery_Watts; // 5 Module power from DCDC PLCFLOAT Inverter_Temp; // 6 Converter temp - degC // from READ_METER2: PLCFLOAT V5S; }; /** * Struct TDK_FLOAT_COMMANDS * are PLCFLOATS that are written to a TDK. Three letter acronyms are from TDK * docs. Set some of these before setting the corresponding trigger bit. * Your SOFTPLC.APP should have sensible values pre-initialized in the datatable * even on disk. */ struct TDK_FLOAT_WRITES { PLCFLOAT CVB; // volts: range 32.0 - 62.0 CMD_BAT_CONF1 & CMD_CV_CHARGE PLCFLOAT DVG; // volts: range 260.0 - 390.0 CMD_CV_DCHARGE PLCFLOAT CIB; // amps : range 0.0 - 56.77 CMD_PROTECTION_LIMITS; PLCFLOAT CCR; // volts: range 0.0 - 12.0 CMD_BAT_CONF2 PLCFLOAT DDR; // volts: range 0.0 - 12.0 CMD_BAT_CONF2 }; ENABLE_DT_PTR( TDK_INT_WRITES ) ENABLE_DT_PTR( TDK_INT_READS ) ENABLE_DT_PTR( TDK_FLOAT_WRITES ) ENABLE_DT_PTR( TDK_FLOAT_READS ) /* To use the memory windows from a different TLM, 1) include this header in that other TLM. 2) add a set of these for each TDK to your TLM: DT_PTR tdk1_iw( "DCDC1_INT_WRITES" ); DT_PTR tdk1_ir( "DCDC1_INT_READS" ); DT_PTR tdk1_fw( "DCDC1_FLOAT_WRITES" ); DT_PTR tdk1_fr( "DCDC1_FLOAT_READS" ); *) Change the Tags to match those used in the TDK FSMs. *) Change the name of the variables themselves: tdk1_iw becomes tdk2_iw, etc. */ #endif // TDK_H_