Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control of a VFD Spindle over RS485, ie a second serial port. #24

Open
davehines91 opened this issue Sep 1, 2018 · 21 comments
Open

Control of a VFD Spindle over RS485, ie a second serial port. #24

davehines91 opened this issue Sep 1, 2018 · 21 comments
Labels
enhancement New feature or request

Comments

@davehines91
Copy link

davehines91 commented Sep 1, 2018

This is a port from my unpublished, but well used work using grbl-Mega

Background :
I currently use grbl-Mega to control a DIY CNC router with a work area of about 600mm x 900mm.
The spindle I currently use is an 800w spindle controlled by a 1.5KW Huanyang Variable Frequency Drive (HY01D523B) . I was looking for a more convenient platform than the Mega , and stumbled upon the ESP32 port.

Testing :
So far I've tested this with the ESP32 dev module in a breadboard , controlling a single axis , and a RS485 module , connected via a levelshifter breakout board to the ESP32 . (Note , the 3.3v version did not work well for me ) .
This setup was used to connect to the VFD over the RS485 interface.

Implementation:

The RS485 link is a two wire differential half duplex interface. The controller needs to assert a send signal
as it transmits , I've controlled this with a timer interrupt ( I've used timer 3 ) . The timer is restarted as each character is transmitted , so the transmit is held high for 4mS after the last character is send , the response is then awaited for by a task , shamelessly cloned from the main serial task. This task checks for the correct response from the VFD , and in the case of the speed request , holds up any further command processing , until the spindle has reached the required speed. If it fails to reach the required speed, the motor is sent the stop command, and an alarm ( 10) is raised.

All the interface to grbl has been implemented within spindle_control.cpp and is enabled or disabled via the Macro RS485_HUANYANG_MOTORCONTROL , currently defined in config.h. The pins used are defined in cpu_map.h , these could be the same three pins currently used by grbl for pwm control, but I've left this code in place in parallel at the moment.

To run the motor use the G-code command :
M3 S10000
To Stop the Motor use:
M5 S0
grbl doesn't seem to like commands like M5 or M3 without a speed .

Various debugging messages, written to Serial1 , can be enabled by defining DEBUGSERIAL in VFD.h

I've hard coded the BAUD rate to 38400 binary 8N1 , PD164 needs setting to 3 for this
baud rate. similarly PD165 should be set to 3 for binary 8N1 comms.

PD01 and PD02 need setting to 2 to respond to stop/start and speed commands
over RS485.

Repo currently at https://github.com/davehines91/Grbl_Esp32

@bdring
Copy link
Owner

bdring commented Sep 1, 2018

Cool. I think I have one of those VFDs. I might be able to test it. do you have a schematic of the whole setup.

@davehines91
Copy link
Author

I'll try and draw up one tomorrow.

@davehines91
Copy link
Author

ESP32-VFD.pdf

Here is an approximate schematic of my setup. I've used the adafruit level shifter , but I couldn't find an eagle library for it , so I've drawn it up with the sparkfun one. The pinout is slightly different .

@davehines91
Copy link
Author

I've now tried this with an equivalent level shifter to the sparkfun one ( clone )

@bdring
Copy link
Owner

bdring commented Sep 2, 2018

I like your suggestion of the option of using the existing PWM pin.

Have you ever used RS485 transceivers with auto direction control ?

@davehines91
Copy link
Author

:)
I couldn't find any transceivers with auto direction control at the time I first did this.
It was also a exercise in interrupts on the arduino for me. and likewise on the ESP32.
It was also more configurable if different baud rates were to be used.
More instructions currently being typed up.

@davehines91
Copy link
Author

davehines91 commented Sep 2, 2018

To run the motor use the G-code command :
M3 S10000
To Stop the Motor use:
M5 S0
grbl doesn't seem to like commands like M5 or M3 without a speed .

Various debugging messages, written to Serial1 , can be enabled by defining DEBUGSERIAL in VFD.h

I've hard coded the BAUD rate to 38400 binary 8N1 , PD164 needs setting to 3 for this
baud rate. similarly PD165 should be set to 3 for binary 8N1 comms.

PD01 and PD02 need setting to 2 to respond to stop/start and speed commands
over RS485.

I think this is the last of the things I set up , but most was done along while ago , and while my memory is quite good .....
[EDIT]
I've also added this info on to the end of the initial post.

@bdring
Copy link
Owner

bdring commented Sep 2, 2018

I think RPM is modal, like feedrate.

S500 ;set rpm but don't turn on spindle
M3 ;turn on CW
S1000 ; change rpm
M5 ; turn off
M3 ; turn on at 1000

You can see all modal values at any time by sending $G

@bdring
Copy link
Owner

bdring commented Sep 2, 2018

Check out this one.

SMAKN® SCM TTL to RS485 Adapter 485 to Serial Port UART Level Converter Module 3.3V 5V https://www.amazon.com/dp/B010723BCE/ref=cm_sw_r_cp_apa_o4.IBbAXJ4E04

3.3v and direction control

image

@davehines91
Copy link
Author

yes I would agree re RPM , but grbl doesn't seem to behave quite like that for me.

I'm sure that no commands were getting thru properly to any functions in spindle_control.c wheen I did this with grbl-Mega, though I'll investigate further with this setup . I've just configured my g-code generator to use full commands like I listed above.

@davehines91
Copy link
Author

I've ordered a couple on the 485 converters you list above off ebay from china, for about $2 each .
I'll try them when they arrive, The ESP32 is little short on available pins , so any we can save will be a bonus

On the subject of saving pins , do you know if it is possible to allocate inputs and outputs , to unexposed GPIO pins ,( 20,24,28,29,30,31) (37,38 have no pull up resistor , so I wouldn't try these ) so their pins could be used for other purposes , I'm thinking 4th axis as an example.

@misan
Copy link

misan commented Sep 2, 2018 via email

@davehines91
Copy link
Author

I considered that when I first implement the motor control on the Mega, but I consider it safer to wait til the motor has run up to speed before continuing. so feedback is required IMHO.

@misan
Copy link

misan commented Sep 2, 2018

@davehines91 let me elaborate a bit more: for starting/stopping or setting the RPMs only TX is needed if you agree on giving up feedback. Otherwise, you need 3 I/O pins and can raise an error condition when, for example, the spindle is not starting up as requested so a tool will not be broken.

I guess the module above does use TX signal activity to trigger a timer to enable the driver output thus saving one output pin.

@davehines91
Copy link
Author

@misan I agree,
I'm describing what I have implemented for grbl-Mega and used successfully for about 18 months, and have just ported to Grbl_Esp32.
Bart has asked me to share my work , which I'm more than happy to do.

@bdring
Copy link
Owner

bdring commented Sep 2, 2018

@davehines91 unexposed GPIO pins.

I don't know. It is probably easier to use something like #ifdef PROBE_PIN to free up some pins.

Ultimately the use of an I/O expander will be supported for low speed I/O, but the initial goal is to get all features working for a basic machine in a single chip (ESP32) solution.

@davehines91
Copy link
Author

@bdring #ifdef, yes , I would agree , I was just trying to make minimal changes.

I like the idea of an IO expander , though I'm more than happy with your port so far .
I look forward to actually cutting some plastic with it when your board arrives.

@misan
Copy link

misan commented Sep 2, 2018

@davehines91 I was not so careful. I started by checking VFD response http://fightpc.blogspot.com/2014/10/vfd-control-with-arduino-using-rs485.html but ended up ignoring it in a patch I made for Marlin firmware. Someone suggested me to forward the patch for GRBL which I did but that was considered too specific a feature.

@davehines91
Copy link
Author

@misan , yes I got the too specific a feature response as well , that's why I've implemented the interface to grbl in just the spindle_control.cpp file , so its easy for anyone to put in , or take out.
If you want to use standard grbl to run a vfd, I'm sure you can use the analog input speed control , but that seems a waste to me , and I wanted to play :)

@davehines91
Copy link
Author

davehines91 commented Sep 2, 2018

@bdring

I think RPM is modal, like feedrate.

I've just pushed a change to my repo which fixes this behaviour
Thanks for pushing me :)

@bdring bdring added the enhancement New feature or request label Sep 4, 2018
@Harvie
Copy link

Harvie commented Jun 24, 2020

Can you please send your huanyang VFD RS485 code to this issue? terjeio/grblHAL#68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants