Support RS485 control of Huanyang VFD (chinese spindles) #68
Comments
I can make a plugin. You can test as I do not own one? If so which driver to start with? |
Yes, i can test it :-) I guess the C driver from LinuxCNC should be safe bet: Or maybe you can try to merge this code from GRBL_ESP32: But there are drivers in other languages as well: There are also guys who tried to get this merged to original GRBL, but there was not enough space on atmega: |
For which processor/board then? I am not going to add this to all drivers even if it is going to be a plugin. A NucleoF411RE board and a Teensy 4.1 is in the mail so it could be one of those, but it will be at least a week before I have any chance of looking into this. |
grblHAL has a spindle_at_speed signal that is only partly implemented. Perhaps this could be a good opportunity to complete that? Again using LinuxCNC as a base specification, see here and here. Currently the MSP432 is the only driver that has spindle_at_speed support, from encoder input and defined as beeing within ±10% of the commanded speed. The grblHAL core will currently wait for a number of seconds before timing out and continuing, IMO an alarm should be issued if the speed is not achieved. What do you think? grblHAL/grbl/spindle_control.c Lines 70 to 91 in 0c0d6af
|
Is the interface just standard serial to an RS485 converter? Are there any other control signals needed? My T4.x boards have a serial out connector. |
Not if the converter has auto direction circuitry.
All drivers has at least one serial port available, those that has serial over USB (or network connectivity) as well may assign the serial port to a secondary function such as a MPG or ModBus. Since RS485 VFD plugins should not handle the serial port peripheral directly, I am considering adding a driver level HAL to let the driver allocate a port and provide a standardized interface. The main challenge could be how to handle the silence required around ModBus messages in a generic way, preferably in the plugin code... |
@Harvie Which pin mappings are you using for your board? I have started coding and are ready to start simulating but hit a snag as the messaging protocol is not ModBus, it is a chinese lookalike. This means my plan to code a ModBus emulation for the VFD is not possible, I have to write an emulation from scratch instead. I have a ModBus stack available so a real ModBus VFD emulator would be easy to write, but no luck with that... Also, error handling needs to be implemented - it seems to me that implementation for the @bdring ESP32 port is rather crude in that respect, it would silently continue on a timeout or on an exception returned from the VFD (assuming the chinese ModBus lookalike might return exceptions per the ModBus standard). Executing g-code that makes chips with a non-running spindle is IMO not a good idea... |
I think for tests we can use mapping of this board: https://www.tindie.com/products/33366583/grbl_esp32-cnc-development-board-v41/ It does use following pinout:
So i guess these pins can be reused for digital communication instead... Is the pinout user-configurable? (at least during compilation) if i later decide to change it? |
Yes, it uses RS485 physical layer, but the protocol might be rather chinese... Earlier i've sent links to code which implements the protocol. I am not sure how different from ModBus it can be, maybe there's some compatible subset, which might be enough for basic communication. But that's just guess.
What happens if you ignore this? I think there should be no collisions on the line as long as there is only VFD and ESP32, which is probably typical setup. I expect VFD to not actively send any status reports unless polled, but i am not sure... If such collisions are occuring, i think it might be enough to send every command 3 times with small random delay no matter if collision occured. |
Yes, there are board map files that may be changed or new ones created. I have to revisit the ESP32 code to see what limits apply. Note I am doing the initial coding for a processor that has a debugger.
It deviates enough to prompt me to make an emulator from scratch, I have the basics working now - I only need to add fault scenarioes to make it complete? The plugin also supports P2x Huanyang VFD's which seems to use a 100% ModBus compliant protocol. Error handling: Status reports has to be requested so no risk of collisions with a correctly configured setup. What I was thinking of is what to do if the VFD does not respond as expected or not at all. IMO that is a critical error. A complicating factor is that communication with the VFD can happen in an ISR context, and at least the dynamic RPM change in stepper.c is time critical. grblHAL has support for CSS (Constant Surface Speed) mode that uses this. Waiting for a response from the VFD in time critical code is a big no-no. Then there is the ESP32 that simply crashes if a float variable (RPM) is referenced in an ISR context, I see that Bart has changed rpm to an int in his port - I assume to avoid this. Another is that the spindle will be stopped on a reset (mc_reset) which also might happen in an ISR context, e.g. when a hard limit is triggered. All in all this is a harder task to get 100% right than I first thought... |
This manual seems to apply https://wiki.spoje.net/lib/exe/fetch.php/howto/mechanical_engineering/huanyang_vfd_inverter_manual.pdf Hardware i have available for testing looks like this, i am not sure which model exactly it is. But it is 1.5kW HuanYang. |
Also according to manual it seems that following stuff can be set:
|
I have reorganized the core grblHAL a bit code in order to avoid setting spindle parameters from an ISR context and have successfully tested functionality with my VFD emulator (on a TM4C123 board) and development board (MSP432). So am I now ready to add the plugin to the ESP32 driver. However the board you suggested does not have spindle direction pin available:
If I am not mistaken this uses the 3axis_v4 pin mapping file. An addtional pin is required for VFD comms, which one to sacrifice? The Mist pin? Note that I have not yet verified that the pins available are possible to use for serial comms. |
Yes, i think the mist might be sacrificed for now as i do not have misting device and i definitely do not plan to use it during the spindle communication test. |
The plugin code is now ready for testing in the development branch - only for the ESP32 driver for now. Settings can be found here: grblHAL/drivers/ESP32/bdring_v4_map.h Lines 98 to 103 in 9845e69
I have only tested with boosterpack_map.h which has different pin allocations. The plugin supports P2x spindles as well, but I have not yet made that an option in the CMakeLists.txt. Note that I am not yet 100% happy with the way ESP32 interacts with the plugin but with luck the core functionality should work. Among the issues I have with this driver is low polling frequency and the snowflake guru crashing the app if a float is encountered in an ISR context. To be resolved later. |
Sorry i was bit busy and totaly forgot to test this... Should be able to setup the test in few days... |
I am kinda confused about how to build grblHAL for ESP32... There does not seem to be I might use make or cmake until arduino IDE support is added for ESP32, but i am not sure how... |
It has to be built with ESP-IDF v3.2 or later - but not v4+. I do not use Arduino libraries so not sure it can be built using the Arduino IDE, or what it would take to convert it for that. The project is set up for cmake. https://github.com/terjeio/grblHAL/tree/master/drivers/ESP32 |
I guess i still miss something... I've just copied grbl and spindle plugin to the ESP32 driver as required in readme.
|
I beleive it's merely about providing the directory structure and library.properties file expected by arduino IDE, since the ESP32 support package for arduino is based on ESP-IDF and there's not really a reason to use the Arduino compatible API wrapper layer, because ESP-IDF API can be called directly from Arduino IDE as well... (given that you are compatible with ESP-IDF version bundled in Arduino IDE) |
Are you compiling with ESP-IDF?
You can do that then? |
Where do i put the ESP-IDF source code?
Perhaps i can try to make PR later to support this. Just checked and it seems that Arduino IDE uses ESP-IDF 3.2: https://github.com/espressif/arduino-esp32/releases BTW https://github.com/espressif/esp-idf/blob/master/SUPPORT_POLICY.md As previously announced, Espressif will stop supporting v3.1 and v3.2 releases after October 2020. For more information please see the ESP-IDF Support Policy. Customers who are using v3.2 release series are encouraged to migrate to more recent releases. ESP-IDF v4.1 is the latest stable release of ESP-IDF at time of writing. |
Ok, i've managed to setup esp-idf, hopefully it will build now... |
With ESP-IDF master (4.x) it builds but does not link, with v3.2 i did not tried to build at all, since they use different build system and i would have need to setup things differently. With ESP-IDF v3.3 i get this:
|
What spindle do you currently run on your machine? |
Kress FM1050 for the router (has Mach3/ethernet Smootstepper - not going to change to grbl). |
I've just checked test branch and i see you've added following settings:
can you please add option to set
|
Is anyone using the Modbus with grblHAL? Here's a link to the manual, Modbus description on page 36 - https://inverterdrive.com/file/Invertek-Optidrive-E3-Manual |
I don't think this will work without modification with other brands, but the boilerplate code is there and you can probably modify it if you know what modbus commands your unit expects. |
Ok, thanks. I'll try to look into it when or if I decide to upgrade the spindle. Or bother you here for help 😅. |
More details can be found in this application note. As @Harvie writes it is unlikely that the Huanyang code can be used as-is, copying it to a new file for Invertek and modifying that to match the Invertek protocol is the way to go ahead. Do not modify the Huanyang code unless it is adding support for further variants or expand functionality for the existing ones. |
Thanks @terjeio ,I'll look at the document. But I think it will be above my programming skills to do it. |
It needs an RS485 adaptor. That is something I am planning to do. That is one of the reasons the new Pro board has mounting holes for a UART daughter card. |
I think we can sort this out together, for basic control not much code needs to be changed - the largest part of the job is to figure out which commands to send and testing. |
Here are 2 cards that might work for you. I have the first (ANMBEST) but think the chip is not really a max485 |
Ok, thanks for the supportive comment . Again I am no hurry to get any of the above, but if it could be sorted sometime this year then it would make a nice Christmas present 😉 . |
I'm attempting to get my Huanyang VFD working with grblHAL on a Teensy 4.1 Is this implemented for the Teensy? I have it defined in my_machine.h. Is it then just a case of defining the pins in the T41U5XBB_map.h? #if SPINDLE_HUANYANG I also saw this in the driver.h file for the ESP32, is it necessary? #if SPINDLE_HUANYANG Am I then good to go after plugging in my 3.3v TTL to RS485 adapter? |
Yes, but is easier than that. You will just need to define VFD_ENABLE=1 and SPINDLE_RPM_CONTROLLED in your my_machine.h (or in platformio.ini if building from that) Note that you will want to pull the latest code from github.com/grblHAL/, as this repo is the old location and out of date.. |
Ha! Nothing in my world is ever easy ;P Thanks for the quick reply Dresco, I'm now with a less archaic version, changed those 2 lines and compiled successfully :) Should I use the "SPINDLE_ENABLE_PIN" for RX Presumably there's nothing else I need to change? |
It will default to Serial1, which I think is pin 0 for RX and pin 1 for TX. (The RS485 adapters I'm using don't have an enable line, so not sure what pin that would be mapped to if you need it). Are you using Phils breakout board? If so, just hook your 3.3v TTL to RS485 adapter up to the serial header & should be good to go.. Cheers. |
Cool, will give that a go. I'm using a slightly ghetto looking DIY BOB, currently I'm having post upload 'GRBL not found'/'offline' issues with the new GrblHAL when connecting to my all my G-Code senders. :/ Thanks for your help |
Ok, so I have the latest GrblHAL up and running and active without spindle, when attempting to enable RS485 control, my sender can see the Teensy but I cannot get communication. I have the spindle plug in folder with the 3 files and the only code changes I've made are by adding Apologies for the school boy errors, what am I missing? |
Have you gone through the first run settings? It is fairly common for a different configuration to return previous settings to default. Try grounding the halt pin - the default is NC. |
Thanks Phil, yes, I inverted all the pins for $5, $6 and $14 on my first setup, the machine started with no alarms and worked as it should - my problem is that when I define VFD_ENABLE 1 and SPINDLE_RPM_CONTROLLED in my_machine.h, after reboot I get an offline status. Commenting these two lines out gives me my machine back but obviously no VFD control. Do I need to comment out the default spindle control settings or are they ignored? (I was fearing this would lead to compile issues) |
Is this the version form the new repository? I am about to archive this to avoid confusion...
Are you connecting to the controller via UART or USB? "Oflline status" is from a sender, does the controller respond if you connect with a terminal application such as puTTY? |
Hi Terjeio, yes, after the advice of Dresco, I am now on the correct latest build from the other repository :) My Teensy 4.1 is connected by USB, senders can identify a port and open a connection, but Grbl communication isn't ready. I've not tried to ssh, what address would I use? |
Connect via the USB com port. Do you get a response when sending If the the VFD is not set up correctly or the baud rate is wrong the controller will start up with alarm 14 active. Baud rate is set with |
Good news, whilst PuTTY failed to connect (no status or position was returned), the problem was that I was adding SPINDLE_RPM_CONTROLLED to my_machine.h rather than uncommenting in grbl/config.h Controller now boots and connects :) Thanks also for the $modbus tip, I am fiddling with the hardware before connecting it all up. In my board map, are the Spindle enable, direction and PWM pins redundant? (so I should uncomment them?) |
Yes. However, if the PWM pin definition is missing it will generate a compiler error unless you update to the version just committed. |
Apologies, that probably came from my suggestion didn't it. I pass the defines in from IDE options, so had overlooked where it's set.. |
No need to apologise Dresco. All is good. I now have full spindle talkie talkie and no release of magic smoke! 👍 Thanks again for all the help everyone. |
Hello,
can you please add support for this?
http://fightpc.blogspot.com/2014/10/vfd-control-with-arduino-using-rs485.html
The text was updated successfully, but these errors were encountered: