Hello Guest it is October 14, 2024, 11:19:02 PM

Author Topic: Mach3, Arduino, Modbus and MPG  (Read 90738 times)

0 Members and 1 Guest are viewing this topic.

Re: Mach3, Arduino, Modbus and MPG
« Reply #10 on: February 08, 2013, 05:33:24 PM »
Zafar:
Were you able to properly configure the MPG?.
As you connected? .
Re: Mach3, Arduino, Modbus and MPG
« Reply #11 on: February 08, 2013, 10:44:28 PM »
Zafar:
Were you able to properly configure the MPG?.
As you connected? .

MPG works with Arduino in Mach3 but there's a delay of about 0.5 seconds in it's response. Couldn't figure out to fix that. Haven't touched it for quite some time. Maybe I'll give it another shot in a few days.

Zafar
Re: Mach3, Arduino, Modbus and MPG
« Reply #12 on: February 09, 2013, 02:21:49 PM »
Hello Zafar:

I have not yet connected an MPG through the ModBus, but have all the I/O pins on the Arduino Mega, pin #2 through #53 digital, and all of the Analog inputs tested, working just fine.

However, as I understand the ModBus functionality in Mach3, in the Serial ModBus Setup screen, there is a column for the millisecond pause for each Cfg.#, and that is a time period the scan will pause at each register waiting for an input. and another millisecond time in the upper right corner, for the "timeout" period. This seems to me, that there cannot be instantaneous response to an input in ModBus, due to the accumulated milliseconds during a scan. The Cfg# time period can be as small as 25 or 50, but it still adds up to some given period of time. I believe this is the cause of the delay in MPG response you mention.

Since the Arduino Mega has so many I/O pins, but the common parallel port has limited inputs, I think the MPG should be wired directly to the Breakout board. The BB itself can be 12 outputs, and 5 inputs, or vice versa. There are only a few kinds of inputs that need to be instant, i.e., the probe signal, the MPG, and perhaps an optical home switch, and an optical sensor spindle index.

On one of my Cubloc plc, there are the standard I/O, and then there are a couple of "High Speed" I/O pins, which are for an MPG.

I am not claiming to be a ModBus expert, and might have some some points wrong, but this seems a reasonable understanding. There is not a lot of info in the inner workings of the Serial ModBus Setup. Also the baud rate might have a different effect, say from 9600 bps, to higher settings. ModBus works perfectly fine for I/O that are not super time critical, like limit switches, spindle on/off
LED's, FRO, etc.


John

You want your limit switches to be fast as well.

Edited...... Brett
« Last Edit: February 09, 2013, 03:56:05 PM by Chaoticone »
Re: Mach3, Arduino, Modbus and MPG
« Reply #13 on: February 10, 2013, 12:50:17 PM »
John,

I had tried differnt timeout values and baud rates etc. with my modbus MPG, but they had no effect on it's response. Maybe there was some difference and I couldn't notice it. The lag only becomes noticeable when you try it on the real machine. On your desktop PC with no hardware attached to Mach you can't catch it.

I am using MPG hooked up with PP or Smooth Stepper now. I'll give it a try once again with Arduino when I return back from my out of town visit.

Zafar
Re: Mach3, Arduino, Modbus and MPG
« Reply #14 on: February 10, 2013, 12:53:09 PM »
John,

Have you tried LCD output with Arduino and modbus. I did it once to display axes DRO's on a 4x24 LCD module. Have to give it another try too some time.

Zafar
Re: Mach3, Arduino, Modbus and MPG
« Reply #15 on: February 10, 2013, 02:25:19 PM »
Hello Zafar:

I have not yet done anything with the LCD/serial display output on the Mega, connected with Mach3.

That is next; however have done a lot of Arduino stuff, using the LCD. One project was a Marine Autopilot, displaying compass bearings with a Compass module, and also putting out GPS coordinates, by parsing the Mag compass outputs, and the GPS output stream. That project used a serial backpack module with a 20X4 LCD, combined with a power converter board from Polulu, which can take a pin signal, and drive a 300+ watt DC motor, which in turn moved the ships wheel with hydraulic steering. Worked just like the commercial units.

Want display the jog status, current step value, jog %  setting, etc., since these are not so easily seen on the Mach screen.

Just takes time to sit down and work with it. Of course, there are bits and pieces scattered about on the Forum how to do lots of obscure tricks.


John

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
Re: Mach3, Arduino, Modbus and MPG
« Reply #16 on: February 11, 2013, 08:09:15 AM »
Hey just thought I would add my two cents here.....

Modbus: 
The time values on the config is how often you want it to poll that register group.
For MPG to work reasonably well, your hardware would need to buffer the counts,
and to get some kind of "smooth" action you would need to send in a "Tick Count"
to Mach3 as well.

Delay: since BOTH Modbus, and a motion plugin, all run at mach3's update loop, 1/10 per second your
not going to get "real time" MPG control......  see the thing about the count buffers in the hardware
above.

Scott
fun times
Re: Mach3, Arduino, Modbus and MPG
« Reply #17 on: February 11, 2013, 11:48:00 AM »
Hey just thought I would add my two cents here.....

Modbus: 
The time values on the config is how often you want it to poll that register group.
For MPG to work reasonably well, your hardware would need to buffer the counts,
and to get some kind of "smooth" action you would need to send in a "Tick Count"
to Mach3 as well.

Delay: since BOTH Modbus, and a motion plugin, all run at mach3's update loop, 1/10 per second your
not going to get "real time" MPG control......  see the thing about the count buffers in the hardware
above.

Scott


Scott,

That's what I wanted to ask. How do I calculate the tick count. Maybe that is what's causing the delay. The delay I get is definitely much bigger than 100 ms, the refresh cycle duration of brains.

Zafar

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
Re: Mach3, Arduino, Modbus and MPG
« Reply #18 on: February 11, 2013, 08:31:29 PM »
Zafar,

   I have a cheezy, Arduino here, and there is a "Timer" style kinda function you can call.
The resolution of that time would need to be in the ms granularity.
In any case, the "Tick Counter" in the arduino would need to at the minimum be MUCH faster,
than the 10hrz update loop.

If it where me, I would then send that Tick Value across the modbus in the standard 16 bit register,
I would then map that register address (in the modbus config in mach), to the "Tick Count" termination object.

NOTE: ( and I suspect you already know this ), You will need to set your MPG count type to "Multi-step", and set your
counts per pulse to 4 in the Ports/Pins. (assuming a 100ppr encoder). The "Single Step" choice will usually (boarding on almost always), loose steps.

Also, given the update fx of the ardino, I would make sure my count buffer is large enough, to sum the total counts of how ever many scans,
it is before it can be read and cleared by mach3. I suspect you already have a mechanism for this, but if not, I would set an modbus output hot,
as it comes around, and I would set a clearing bit, that would control the clearing of the count register.

Tick count, make sure you put "Roll Over" code in the 16bit register that holds your count on the arduino side.

Mach will use both your count register, AND your tick count to not only see how far you have moved, but how fast since last update loop.
again, DON'T expect ANY SUPER results even with the above, you can OUTRUN your Machs ability to keep up with your MPG if you turn it fast.
the 10hrz lag, is a BUZZ KILL no doubt.

Scott

fun times
Re: Mach3, Arduino, Modbus and MPG
« Reply #19 on: February 11, 2013, 08:39:50 PM »
Thanks a lot Scott for the explanation. I am out of town right now. Will give it a try when I get back home and let you know if I get any better results.