Machsupport Forum

Third party software and hardware support forums. => Modbus => Topic started by: shangJie on April 19, 2014, 09:58:25 AM

Title: How to Address Modbus Outputs if you have more than 20
Post by: shangJie on April 19, 2014, 09:58:25 AM
Hi everyone, we are building a machine that needs 50 discrete outputs. We are planning to daisy chain 7 of Peter Homann's ModIO boards together. I have been able to use a brain to assign Mach3 Outputs to the ModIO output holding registers. So far so good.

The problem is that I can only find 20 outputs within Mach3. So I can set the first 20 outputs using brains, but I don't know how to address outputs 21-50.

My idea was to use custom M codes which would map to VB scripts as in this post: http://www.machsupport.com/forum/index.php?topic=15179.0 (http://www.machsupport.com/forum/index.php?topic=15179.0).

That will work great for the first 20, but anyone have any ideas how to set the rest?
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on April 19, 2014, 12:47:29 PM
Hi shangJie

If I understand your requirement correctly, I *think* you may be going about this in an overly complicated way. If it were me I'd be looking at something like an Arduino mega and have Mach simply send the number of the colour you want across modbus.
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on April 23, 2014, 11:51:44 AM
guess not then...
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: shangJie on April 28, 2014, 10:10:11 AM
Hi stirling,

Sorry to get back late here! Thanks so much for your recommendation. I hadn't heard of that board. Looks like something I need to check out. Obviously from my questions a lot of this stuff is new to me. Really appreciate the help.

We had already purchased several ModIO boards when I made the previous post, so we will need to use the ModIO to make it work on this machine. Got a suggestion from Peter Homann to set UserLEDs in a VBscript and then to use a brain to translate these UserLEDs into output signals on the ModIO. There are a whole lot more UserLED signals available than there are Mach3 Outputs. This seems to be working beautifully. We were able to get three boards up and receiving commands from VBscript tonight.
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on April 28, 2014, 11:08:40 AM
Hi shangJie

Thanks for getting back. Good you're getting it sorted.

Just for completeness - this would have been the detail of my suggestion. The Arduino Mega has 54 outputs and can be programmed with open source software to be a MODBUS slave.

You could then send the number of the output you wanted activating via MODBUS using a single register and the GCode S word (normally for spindle speed but it's just a number) so no VB macros needed. Then your Brain would be ONE rung like:

CmdSpindleRpm ->NOP -> MODBUS register

Anyway - you're up and going so no worries

Ian
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: shangJie on April 28, 2014, 09:23:05 PM
Hi Ian,

Thanks so much for your detailed response and ideas. We are hoping to build several more machines in the future, so the Arduino Mega will be on our list of potential candidates as we evaluate machine #2. Considering that for 50 outputs we need 100 different vbscripts (one to turn on, one to turn off for each output) it would be nice to use just an S word. Perhaps Mach 4 will support passing arguments to VB macros?

Am I correct in understanding that if we want to use the Arduino Mega I would need to learn a bit of C programming?

One thing that has been really nice about using the ModIO is the great customer support that Peter Homann provides.

Thanks so much,
Sam
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on April 29, 2014, 03:54:05 AM
No need to wait for Mach4, Mach3 macros take parameters.

Yes - an understanding of C would certainly help.

Cheers

Ian
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: shangJie on April 29, 2014, 06:20:33 AM
You are blowing my mind! Thank you so much! This could save me lots of time.

I thought from this post in 2010 that you had to put your parameters in a filename and then make a bunch of different files: http://www.machsupport.com/forum/index.php/topic,15179.0.html (http://www.machsupport.com/forum/index.php/topic,15179.0.html)

Is there a thread out there that discusses how to pass parameters through Gcode?

But I'm getting off the topic of Modbus. Feel free to censor this thread if need be!
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on April 29, 2014, 08:08:48 AM
You are blowing my mind! Thank you so much! This could save me lots of time.

I thought from this post in 2010 that you had to put your parameters in a filename and then make a bunch of different files: http://www.machsupport.com/forum/index.php/topic,15179.0.html (http://www.machsupport.com/forum/index.php/topic,15179.0.html)

well it's a way - no doubt about that...  ::)

Is there a thread out there that discusses how to pass parameters through Gcode?
I think maybe you should have a read of the various programming docs here http://www.machsupport.com/help-learning/product-manuals

But parameters are pretty straightforward. You can have up to 3, namely P, Q and R. e.g. M1000 P7 will pass 7 into the macro. Then you retrieve them in the macro with the functions param1(), param2() and param3() so in this example (P) you'd retrieve it with param1().
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: poppabear on May 01, 2014, 07:54:09 AM
Just as a side note:

Another option would be to build Integer numbers 16 bit, that each bit represents and output.
If using Peters Board(s) those numbers would be output registers (one per board).
If using Arduino or a PLC for that matter you could use bit shifting plus "AND" masking (also known as Bit of Word in PLC land).
to do what you want.

Scott
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: shangJie on May 01, 2014, 09:19:30 PM
Thanks Scott! Didn't realize there were so many ways to do this. Much appreciated!

Sam
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: LGF on August 31, 2014, 06:48:36 AM
Stirling

I see you seem to have some experience with Modbus and arduino in Mach3 and since I am struggling to get any answers here on the forum I thought I'd ask you directly.

Using the Arduino mega 2560 I have serious amounts of pins that I can use, however I have an LCDKeypad shield that plugs onto the headers of the mega and virtually leaves me with the pin header containing 22-53 to use for my stepper drivers (step and dir)
The specs of the DIY cnc Mill I have built is somewhere here on the forum but I could post it here if it would have any bearing on the issue I am struggling with.

What I am struggling with is confirming if I define the motor outputs in the Mach config "ports and pins/motor outputs" to say X step = 22, X dir = 23, Y step = 24, Y dir= 25 etc etc would I be able to get the motors running. The Modbus I am using is the one on the forum by a guys called Schilling and defines registers as follow:


//############  REGISTER DEFINES ############# // Each Register is 16bit
#define Digital_IO_Register 0
#define PWM_Register        10
#define AN_Register         30
#define Timer_Register      50
#define IO_Config_Register  60
#define Kill_IO_Register    70
#define PWMIOMap_Register   80
#define ANIOMap_Register    81
#define General_Config      90
#define Error_Register      91
#define Digital_IO_Pins     64   //Total number of Digital IO pins, Limits update scanner pin count
#define Number_Of_Registers 100
//############ GLOBAL VARIABLES ##############
unsigned char Data[256];                                         // All received data ends up in here, also used as output buffer
unsigned short Index = 0;                                        // Current Location in Data
unsigned short Register[Number_Of_Registers];                    // Where all user data, Coils/Registers are kept
ModBusSlave ModBus(Slave_Address,Register,Number_Of_Registers);  // Initialize a new ModBus Slave, Again, you must have my Arduino ModBusSlave Library
unsigned long Last_Time=0;
unsigned long Time = 0;
unsigned long LongBreakTime;                                            //Time for 3.5 characters to be RX
//################## Setup ###################
// Takes:   Nothing
// Returns: Nothing
// Effect:  Opens Serial port 1 at defined Baudrate
//          Configures all Pins
//          Initiallized Timer 1
void setup()
{
  //################ Initialize IO #################     // 0 => Output, 1 => Input, opposite of normal Arduino, but my habit from other platforms, 0 looks like an O and 1 looks like an I
  Register[IO_Config_Register]    = 0b0000000000000000;  // UNO and MEGA  PIN 00-15
  Register[IO_Config_Register+1]  = 0b0000000000000000;  // MEGA          PIN 16-31
  Register[IO_Config_Register+2]  = 0b0000000000000000;  // MEGA          PIN 32-47
  Register[IO_Config_Register+3]  = 0b0000000000000000;  // MEGA          PIN 48-64
  Register[IO_Config_Register+4]  = 0b1111111111111111;  // AN Digital    PIN A0-A16

  //################ Kill IO Register #################  // 0 => Leave, 1 => Kill
  Register[Kill_IO_Register]    = 0b1111111111111111;    // UNO and MEGA  PIN 00-15
  Register[Kill_IO_Register+1]  = 0b1111111111111111;    // MEGA          PIN 16-31
  Register[Kill_IO_Register+2]  = 0b1111111111111111;    // MEGA          PIN 32-47
  Register[Kill_IO_Register+3]  = 0b1111111111111111;    // MEGA          PIN 48-64
  Register[Kill_IO_Register+4]  = 0b1111111111111111;    // AN Digital    PIN A0-A16

  //################ PWM IO Register #################   // 0 => Normal I/O, 1 => PWM I/O
  Register[PWMIOMap_Register]   = 0b0000111001101000;    // UNO and MEGA  PWM 01-16

  //################ AN IO Register #################    // 0 => Digital, 1=> Analog
  Register[ANIOMap_Register]    = 0b1111111111111111;    // UNO and MEGA

  Config_IO();


Thanx in advance for any help.
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on September 02, 2014, 04:08:22 AM
I think you misunderstand what Modbus is for. It is for non-time-critical I/O expansion - you can't drive axis motion via Modbus.

With Mach you either use the Parallel port driver OR you use an external motion controller.

Arduino can be used with Mach for all sorts of things - but NOT for driving the axis (unless I suppose you write your own plugin which is non-trivial. Even then I'd argue an 8 bit processor is a poor choice for motion control).
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: LGF on September 02, 2014, 04:32:51 AM
Thank you so much for the reply, really appreciate it. It's just that I thought I was lost the last week or so trying to figure out what to do, until now, now I know I cannot get any more lost than what I am now.

I have 4 Nema 2r 3NM steppers with Wantai DQ542MA stepper driverd, a manual switch controlled flood system and a manual controlled router I post full specs if required, but please then advise on the way forward?

I am getting two old LPT PC's today and hopefully I can make one working from the two, that said do I need to still have an external controller with the modbus on it or do I just use the Arduino Mega for something else?

Really lost now
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on September 02, 2014, 06:10:39 AM
First step, just get your axes moving: All you need is Mach3 on a 32 bit windoze PC -> parallel port -> (optional BOB) -> drivers -> motors (plus a power supply of course). See http://www.machsupport.com/help-learning manuals, videos etc.

(I've said BOB is optional but probably advisable unless you know exactly what you're doing).
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: LGF on September 02, 2014, 06:34:56 AM
Thanx, so which Break Out would be appropriate? Not too sure of my knowledge regarding the LPT capabilities with regards to pulsing the stepper drivers (they require 5v pulses)

Steppers draw around 4.2A

PS: downloaded and read through all the doc's, watched all the vids even the ones that is not on Artsoft, and perhaps thats what messed me up so much as I was looking for info regarding the setting up and config using the Arduino and Modbus.

PS2: Got the motors tested with Accelstepper (Arduino sketch that was uploaded and replaced with modbusslave) some time back and they were fucntioning, but will see if I can get them working without the slave just using LPT, this is however not my system preffered method as I would have loved to use a laptop for drafting, scanning and Mach operation all in one. With this I will have to do the drafting on the laptop or Macbook (perhaps the 3d scanning part too) then process them and physically transfer them to the desktop that will have the LPT port (that is if I am able to get one machine from the two, combining parts, working this afternoon.)
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: LGF on September 02, 2014, 07:00:16 AM
Stirling

The machine is built, wired and checked manually and electronically too all seems to be in order, have movement on the lead screws when turning them manually (also with a previous test with the Arduino) backlash is virtually so little and might require some tuning on the backlash nuts I made on the lathe, but thats about it. Oh and getting the machine a soul, NOT A GHOST hopefully.

Anyhow here's the specs I can recall off the top of my head so far:

The enite machine (framework) is constructed of 10mm thick aluminium plate with variations of width between 70-100mm's and one or two pieces that has 400x350 and 200x120 dimensions.
M12 (1.75 pitch) high tensile threaded rod leadscrews, very well made anti-backlash nuts, stepper leadscrew couplers commercial units, no play or slipping etc.
4-Axis (standard X, Y Z with rotational B slave mounted in a linear manner on Y)
X, Y, Z fitted with NEMA23 3N/M 1.8* steppers whilst B = NEMA23 1N/M 1.8* stepper (all works out with 200steps /rev)
4 x Wantai DQ542MA Stepper drivers with Enb, Step and Dir signal inputs, a separate 48V input for stepper power
Power supply delivers 5v, 12v 1nd 48v with @ 20A max (Main source is 220-240)
Spindle is a 500W industrial router with toggle switch (later to be altered to be controlled by Mach including MPG)
Flood system fitted with manual switch (also to be included in above alt for Mach)
LCDKeypad shield for Arduino Mega (now redundant)
2 channel 5v relay system for power control for end of job and e stop functions (also to be added)
E stop fitted but is manual.

As for physical dimensions, have not measured the exact travel distances yet but these are roughly as follow:
between the max and min of X roughly around 380mm, Y around 240mm, Z has a travel of around 210mm.

Giving you this info so that perhaps you have a better idea of what I have to do to get this frankenstein to come to life>

Thank you so much for your very helpfull replies, I now have hope again!!!! and will most probably leave work (sneak out) early to go get busy with it today still.
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on September 02, 2014, 07:13:38 AM
BOBs are plentiful - might want to ask on the general forum - I don't use them so can't offer suggestions.

If you want to use a laptop with Mach then your only real option is to use external motion control - again there are several - might want to google or ask on the general forum. Don't use one so I can't advise.

Personally I wouldn't use threaded rod for "lead screws". Apart from not being very accurate, the pitch is way too low for a router.
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: mrich0908 on September 11, 2014, 07:21:43 PM
Stirling do DB25 LPT cards not work?
https://www.google.com/search?q=laptop+db25+lpt+card&rlz=1C1CHFX_enUS601US601&biw=1422&bih=702&noj=1&source=lnms&tbm=isch&sa=X&ei=Wi4SVI3xA42xyATUgILAAw&ved=0CAkQ_AUoAg&dpr=0.9
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: stirling on September 12, 2014, 04:31:21 AM
Never tried using a laptop for Mach3 - officially, use of the parallel port driver with laptops is not supported. You may want to do a search of the forum - it's been discussed many times. Here's one example. http://www.machsupport.com/forum/index.php?topic=5981.0
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: mrich0908 on September 12, 2014, 10:39:02 AM
I have ,
I dont use mach with a laptop. Just curious.
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: LGF on September 25, 2014, 05:22:47 AM
on this question, I saw a tut vid where an additional port was said to be used and that one could with the 2nd port config them to all be inputs? Have a second port and might require this soon, with homing switches and limit switches (although all my limit switches are on 1 input pin)
Title: Re: How to Address Modbus Outputs if you have more than 20
Post by: jziz on May 13, 2015, 04:18:53 PM
Maybe I am missing something, but I am more than 50 ModBus addresses with Mach3. I have 40 Descrets, 16 Analogs, 200 Holding registers and 25 coils. the only problem I have is with 32 bit numbers.everything I want to display is 16 bit or a signed integer. 

Jzee