1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-18 04:11:53 +02:00
This commit is contained in:
me
2021-04-21 08:59:20 -07:00
parent 104eddedf5
commit 9d16064c38
3 changed files with 49 additions and 20 deletions

View File

@@ -61,19 +61,6 @@ namespace Spindles {
grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"sending dir: state: %d",mode);
}
/*
void L510::start_command(ModbusCommand& data){
data.tx_length = 6;
data.rx_length = 6;
data.msg[1] = 0x06;
data.msg[2] = 0x25;
data.msg[3] = 0x01;
data.msg[4] = 0x00;
data.msg[5] = 0x01;
}
*/
void L510::set_speed_command(uint32_t rpm, ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
@@ -100,7 +87,9 @@ namespace Spindles {
data.msg[4] = uint8_t(speed >> 8); // RPM
data.msg[5] = uint8_t(speed & 0xFF);
#ifdef VFD_DEBUG_MODE2
grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"setting speed to: %d",speed);
#endif
}
uint16_t L510::rpm_to_frequency(uint32_t rpm){
auto max_rpm = this->_max_rpm;
@@ -138,7 +127,7 @@ namespace Spindles {
//TODO also get max_frequency
vfd->_max_rpm = rpm;
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 spindle max_rpm %d ", vfd->_max_rpm);
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 initialized: spindle max_rpm %d ", vfd->_max_rpm);
return true;
};
@@ -146,6 +135,30 @@ namespace Spindles {
return nullptr;
}
}
VFD::response_parser L510::get_status_ok(ModbusCommand& data){
// NOTE: data length is excluding the CRC16 checksum.
data.tx_length = 6;
data.rx_length = 5;
// Send:
data.msg[1] = 0x03; // READ
data.msg[2] = 0x25; // 0x2520 = Get state
data.msg[3] = 0x20;
data.msg[4] = 0x00; // Read 1 value
data.msg[5] = 0x01;
return [](const uint8_t* response, Spindles::VFD* vfd) -> bool {
uint32_t vfd_state = (response[3] << 8) | response[4];
//TODO also get max_frequency
if(bitRead(vfd_state,3)){
grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"L510 Fault detected");
return false;
}
return true;
};
}
VFD::response_parser L510::get_current_rpm(ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
@@ -158,11 +171,9 @@ namespace Spindles {
data.msg[3] = 0x24;
data.msg[4] = 0x00; // Read 1 value
data.msg[5] = 0x01;
//grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"get_rpm");
return [](const uint8_t* response, Spindles::VFD* vfd) -> bool {
uint16_t freq = (response[3] << 8) | response[4];
grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"current frequency: %d",freq);
auto l510 = static_cast<L510*>(vfd);
@@ -172,6 +183,7 @@ namespace Spindles {
}
VFD::response_parser L510::get_current_direction(ModbusCommand& data) {
// does this run ever??
// NOTE: data length is excluding the CRC16 checksum.
data.tx_length = 6;
data.rx_length = 5;
@@ -186,11 +198,9 @@ namespace Spindles {
// Receive: 01 03 00 02 00 02
// ----- status
// TODO: this doesn't seem to do anything in H2A
return [](const uint8_t* response, Spindles::VFD* vfd) -> bool {
uint16_t got = (uint16_t(response[3]) << 8) | uint16_t(response[4]);
bool dir = bitRead(got,1);
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 dir %d", int(dir));
return true;
};
}

View File

@@ -30,11 +30,11 @@ namespace Spindles {
response_parser initialization_sequence(int index, ModbusCommand& data) override;
response_parser get_current_rpm(ModbusCommand& data) override;
response_parser get_current_direction(ModbusCommand& data) override;
response_parser get_status_ok(ModbusCommand& data) override { return nullptr; }
// what is this, what should it do?
bool supports_actual_rpm() const override { return true; }
bool safety_polling() const override { return false; }
bool safety_polling() const override { return true; }
response_parser get_status_ok(ModbusCommand& data) override;
uint16_t rpm_to_frequency(uint32_t rpm);
uint32_t freq_to_rpm(uint16_t);
//uint32_t set_rpm(uint32_t rpm) override;

View File

@@ -0,0 +1,19 @@
# VFD setup
Change these values:
1) 00-02, Main Run Command Source Selection, Default = 0 Change to 2
2) 00-05, Main Freq Command Source Selection, Default = 0 Change to 5
Check that these are set to the default factory values:
3) 00-07, Main and Alternative Freq Cmnd Source Selection, Default = 0
4) 09-00, Assigned Communication Number, Default = 1 this is defined as VFD_RS485_ADDR
5) 09-01, RTU/ASCII Code Selection, Default = 0 Should be 0 (We are using hex "RTU" commands, not ASCII commands)
6) 09-02, Baud Rate Setting, Default = 1 Should be 1 (9600 baud) but can be changed in the TecoL510.cpp
7) 09-03, Stop Bit Selection, Default = 0 Should be 0 (1 stop bit)
8) 09-04, Parity Selection, Default = 0 Should be 0 (Without parity)
9) 09-05, Data Format Selection, Default = 0 Should be 0 (8 data bits)
# Implementation details
not sure how to detect and parse error messages
max frequency is currenly hardcode