Hello, I am looking to communicate with an Allen Bradley Powerflex 4 VFD, using my Arduino Uno and Modbus communication. I am currently using the SimpleModbusMaster library from Juan B. I have tried changing my code several times and I made sure the VFD's parameters were set to communicate over the com ports. Does anyone have experience with this sort of project? Any help would be greatly appreciated. I will post my code below and here is the link to the VFD manual:
#include <SimpleModbusMaster.h>
#include <TimerOne.h>
//#include <SoftwareSerial.h>
//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 600
#define retry_count 10
#define TxEnablePin 2
#define TOTAL_NO_OF_REGISTERS 1
//////////////////// Assembly of the Modbus packets ///////////////
int LED = 13;
enum
{
PACKET1,
PACKET2,
PACKET3,
TOTAL_NO_OF_PACKETS // Leave this last entry. It tells the library how many packets are to be sent out.
};
Packet packets[TOTAL_NO_OF_PACKETS]; //Leave this line in here.
enum {
Master_CommandWord,
Master_SetSpeed,
Regs_Size
};
// Masters register array
unsigned int regs[Regs_Size];
/////////////////////////VFD READS//////////////////////////////
Packet* statusWordVSD = &packets[PACKET1];
/////////////////////////VFD WRITES/////////////////////////////
Packet* commandWordVSD = &packets[PACKET2];
Packet* userSetSpeedVSD = &packets[PACKET3];
void setup()
{
//modbus_construct(statusWordVSD, 2, READ_HOLDING_REGISTERS, 8448, 1, 0);
modbus_construct(commandWordVSD, 2, PRESET_SINGLE_REGISTER, 8192, 1, 0);
modbus_construct(userSetSpeedVSD, 2, PRESET_SINGLE_REGISTER, 8193, 1, 1);
modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
pinMode(LED, OUTPUT);
}
void loop()
{
modbus_update();
regs[Master_CommandWord] = 1;
regs[Master_SetSpeed] = 200;
//if (packets[TOTAL_NO_OF_PACKETS].failed_requests >= 4) {
//digitalWrite(LED,HIGH);
//}
}