Machsupport Forum

Third party software and hardware support forums. => CS-Lab => Topic started by: razer00 on November 25, 2020, 06:57:02 AM

Title: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on November 25, 2020, 06:57:02 AM
Hi all,

I am trying to control an external device using an analogue output from my CSMIO-IP/S to control an external device (Arduino).
I managed to configure the setup to output a voltage signal using a G-code adjusting spindle speed ('S####' command).
So, when I set different numbers after 'S' command, the output voltage changes.
But, the problem is whenever I change the voltage, the stepper motors controlling the main axes stop for a while. After adjusting the voltage, they run again.
I really need a smooth and continuous operation.
The current spindle setting is attached.

Any advice will be really appreciated.
Do you think I can solve the problem using a macro?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: Tweakie.CNC on November 25, 2020, 07:40:13 AM
The problem is that the S### command breaks the CV chain.

Axis movements do not break the chain so movement of a spare axis such as from B0 to B100 will create step and direction signals on the Output pins of your choice which your Arduino could use. Also electronic potentiometers are driven by step and direction signals. Food for thought perhaps ?

Tweakie.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on November 25, 2020, 08:32:15 AM
Thank you very much for your advice, Tweakie.

Unfortunately, I'm not very experience in CNC control so I cannot understand what you meant by CV.
But, as far as I understand, you say I cannot use S command without stopping the axes?

Is there any way to output a analogue voltage signal at each target coordinate without stopping the motion?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: Tweakie.CNC on November 25, 2020, 10:20:25 AM
Hi Eric,

Sorry for the abbreviation, CV stands for Constant Velocity. Let me explain in a different manner...

You cannot use an S### command without breaking the smooth chain of motion.
However, there is a way - others, in the past, have connected an encoder to the Z axis stepper motor and because axis movements can be made without breaking the smooth chain of motion used the encoder output to create an anologue variable.
As said earlier, my preference would be the electronic solution of connecting an electronic potentiometer as the B axis then using that to generate the required analogue variable. An Arduino could be used to perform the same function.

Hope this helps,

Tweakie.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on November 25, 2020, 12:20:23 PM
Hi Tweakie,

Yes, that could be an option, but it is not a very convenient solution for my existing setup.
Do you mean that there is no other way to output voltage without disturbing the motion control at all?

Best Regards,
Eric
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on November 25, 2020, 01:50:57 PM
hello eric,

can you describe, what you want to do, for the Moment i am not able to follow.

analog Output of CSlab can be controlled within macros (M call's) for example)
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on November 25, 2020, 02:52:35 PM
Hi TPS,

Thanks for heading up.

CS-lab has suggested me to use the analog output for spindle speed (S command).
But, the problem is that whenever the G-code runs the S command, the axes (stepper motors) movement stops.

Would the macro be able to output voltage signal without stoping the axes?
If so, how should I setup the pins and macro?

Thanks,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on November 26, 2020, 03:33:42 AM
hello Eric,

as Tweakie sayed any usage of S word or also a custom macro call will interupt constant movement.

so the only way is to use an "unused" axis and read the axis Position via macropump or a brain and
write the analog out manualy.

here:https://en.cs-lab.eu/digital-and-analog-ios-configuration-its-easy/
is a Diagramm, witch Shows the adresses and ranges of the analog Outputs.

a code example for macropump would be:

Code: [Select]

'convert B-axis Position 0-100 to 0-10V on analog output1
SetModOutput(81,GetDro(4)*4.095)


but the update time will be about 10ms

Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on November 26, 2020, 07:53:06 AM
Hi TPS,

Thank you very much for providing the very answer that I wanted to get. So, the conclusion is there is no way to directly use the analogue output without stoping the axes motion. OK.

You suggested converting the axis position to analog value.
Can I just use macro without any hardware modification?
I'm sorry I don't have experience in using macros before.

I've got 4 axes currently being used, with 6-axis CSMIO-IP/S module. I only have 4 stepper motor drivers connected.
Do you mean that I can just make a macro you suggested and connect wires to analog output pin 81?

SetModOutput(81,GetDro(5)*4.095)

What is the number 4.095?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on November 26, 2020, 08:17:08 AM
in my posted link (https://en.cs-lab.eu/digital-and-analog-ios-configuration-its-easy/)
you can see analog Output Need's a value 0-4095 for 0-10V

so 0-100 (b-axis Position DRO(5)) multiplied by 4.095 will bring the result.

you can put the posted code into macropump.m1s (make sure macropump is enabled in
General config) and it should work.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on November 27, 2020, 08:32:47 AM
Hi TPS,

Thank you very much for the idea.
Here is an additional question.

If I create a macro M100 as below,
SetModOutput(81,GetDro(5)*4.095)

Then, what should the G-code be?
Can I run M100 just once at the beginning? or should I use it every time when I want to change the analogue output? After the motion command?

X.. Y.. Z.. A.. B..
M100
X.. Y.. Z.. A.. B..
M100

Like this?
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on November 28, 2020, 03:04:39 AM
if you put the code in a custom macro like M100, it Needs to be called in G-Code every time you want to Change
the analog Output, and Motion will stop on every macro call.

that is why i was talking about macropump macro, this is a macro witch is running in Background, and it will
read the B-Axis Position every 10ms and write the analog Output, and because it is running in Background,
it will not pause Motion.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on November 30, 2020, 07:59:25 AM
Hi TPS,

I tried the method, but it didn't work.
I think the problem is related to the value for GetDro().
For B-axis, is it right to put 5? How can I know if it is a correct value or not?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on November 30, 2020, 02:14:04 PM
GetDro(5) is the right value for B-axis.
have you enabled macropump macro in General cofig?
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 01, 2020, 11:05:26 AM
Hi TPS,

I checked the analog output only by using the following command in a normal M command before trying the macropump.

SetModOutput(81,2000)

I’ve tried the address number 80.
But there was no output.

Any idea?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 02, 2020, 02:12:05 AM
Hello Eric,

will have a look this afternoon at my machine.
i have used a analog Output there.
let you know.

Regards Tom
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 02, 2020, 08:25:13 AM
Hi Tom,

I managed to make the analog output itself is working using a normal M command.
The problem was the analog output 1 was allocated to the spindle output, and when the spindle was enabled, the analog output didn't work.
Now I need to check if GetDRO is working properly or not.
According to the MACH3 macro handbook, it is not recommended to use GetDRO.
Please see the descriptions below. What is the difference from GetOEMDRO and GetUserDRO?
And do you know where I can check the full scale of the B-axis range?

GetDRO
Function GetDRO(DRONum As Integer) As Double
This legacy function takes the DRO number passed as its argument, and returns the value of the Mach DRO of that number.
The use of GetDRO is no longer recommended practice and this function exists only to support preexisting legacy scripts. This function is deprecated, and its use is strongly discouraged.
Legacy script note: Over time, there have been two different DRO numbering schemes used with Mach; the “DRO number” series and the “OEMDRO number” series. This function uses the “DRO number” series.
The “DRO number” series was further subdivided into “User” and “OEM” ranges. Within the “OEM” range, valid DRONums were from 0 to 200, which, at one time, corresponded to OEM DRO numbers 800 to 1000.
The numerical correspondence between the numbering series is not guaranteed for future releases of Mach.
Use the GetOEMDRO and GetUserDRO functions instead of this function.

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 02, 2020, 09:01:24 AM
hello Eric,

here: https://www.machsupport.com/forum/index.php?topic=9312.0

is a oemdro list.

correct code would be:
Code: [Select]
SetModOutput(81,GetOemDro(804)*4.095)

UserDro's are for free usage.

what do you mean with the full scale of the B-axis range?
 
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 02, 2020, 10:06:56 AM
Hi Tom,

Thank you for your information.
I meant the value of the GetOemDro(804).
Your assumption is that its range is 1-1000. But, where can we set that range?
Is it like a default value?

Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 02, 2020, 12:00:01 PM
Hi Tom,

GetOemDro worked quite well.
But, the problem is that when I put B... if the value is over a certain value, the GetOemDro value went completely wrong.
I don't quite understand why this happens.
Any thought?
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 02, 2020, 01:38:20 PM
---I put B... if the value is over a certain value,

witch value?
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 02, 2020, 01:41:30 PM
Hi Tom,

Thank you for your information.
I meant the value of the GetOemDro(804).
Your assumption is that its range is 1-1000. But, where can we set that range?
Is it like a default value?



see it like a virtual axis there is no range to define, only Thing is to Zero it before you start.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 02, 2020, 01:53:37 PM
Hi Tom,

I managed to make the analog output work using macropump.
All thanks to your help!!

A funny thing is happening to the B-axis. Please see the video below.
https://youtu.be/BgLlfBCSrEA
The motor setting is also attached.
Do you know what the problem is?

With the motor setting, B1 output GetOemDRO value 1.
The problem is when I changed the value too much in a time, the value was just screwed up.

And do you know the G-code to set the OmeDRO to be zero?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 02, 2020, 02:04:10 PM
with
Code: [Select]
SetModOutput(81,GetOemDro(804)*4.095)

the value is scaled to 0-100 not to 0-1000

for 0-1000 use
Code: [Select]
SetModOutput(81,GetOemDro(804)*0.4095)

to set b axis to Zero use

Code: [Select]
SetOemDro(804,0)
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 03, 2020, 07:16:53 AM
Hi Tom,

I encounter another problem. Never going smoothly.
As soon as B... command is input (using macropump), the whole motion stops.
Any thought?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 03, 2020, 07:47:01 AM
a

G1 X100 Y100 B100 F50
G1 X0 Y0 B0

should not stop Motion

metric if in imperial use suitable values
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 03, 2020, 08:16:27 AM
The problem is that the DRO values in the display change, but the actual motion stops when the B... command is used.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 03, 2020, 08:18:20 AM
is the b axis enabled and assigned in CSLAB plugin?
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 06, 2020, 10:00:53 AM
Hi Tom,

The problem is still unsolved.

I've used the following G-code.
G90
G0 X0 Y0 B0
M7
M9
G1
X 26.0 Y 0 B 19.5 F 300
X 27.0 Y 0 B 39.0 F 300
X 28.0 Y 0 B 58.5 F 300
X 29.0 Y 0 B 78.0 F 300
X 30.0 Y 0 B 97.5 F 300

And the macropump.m1s was:
SetModOutput(81, GetOemDro(804))

B-axis setting was in a way that B1 command output the analog output value 1.
In theory, B4095 should output 10V. And when we checked B command on DMI, it worked.

The problem is that when we run the G-code above, as soon as B command starts being used, the motion stops.
Interestingly, the G-code still runs without any machine movement.

Do you know what the problem is?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 06, 2020, 02:30:47 PM
hello Eric,

tested your code here, and it is running without stopping movement.

can you pls post your prifile XML, than i will have a look.

Regards Tom.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 07, 2020, 08:19:15 AM
Hi Tom,

Thank you very much. Please see the attached profile xml file.
Any advice will be really appreciated.

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 07, 2020, 09:59:39 AM
hello Eric,
in the XML you sent B-Axis is not enabled?
if enabled do not forget the Motor Tuning

i would set 10 steps/per 10000 velocity and 10000 accel, to make sure
b-axis will not slow down the other axis.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 07, 2020, 10:28:24 AM
Hi Tom,

It is strange... I enabled the B-axis.
There are a few options for B-axis. I'm not sure which option was turned off.
I went to Plugin Control > CSMIOS (Config), and then tick the box for B-axis.
Is there anything else I should do?

Strangely, the Step Pin# and Dir Pin# for all axes were set to zero. Is it normal?

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 07, 2020, 03:28:56 PM
hello Eric,

Config -> Ports&Pins -> Motor Outputs -> enable B-axis

Pins will not matter because this is handled by the plugin.

Regards Tom
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 09, 2020, 05:21:03 AM
Hi Tom,

Yes, that was exactly how I activated the B-axis. Sorry for my confusion.
But, even when the B-axis was ticked in the Motor Outputs setting, in the xlm file the value for Motor 4 was still zero in the xlm file.
<Motor4Active>0</Motor4Active>
Interestingly, I could get the analog output well. However, the all motion stopped.

I'm trying to change the motor speed and acceleration values in the Motor Tuning menu.
I will let you know how it works.

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 09, 2020, 10:02:40 AM
Hi Tom,

B-axis still rotates very low. Here are the motor settings and G-code used.

X axis: steps per 101.823, velocity 4000.2, acceleration 200
Y axis: steps per 101.795, velocity 4000.2, acceleration 750
B axis: steps per 100, velocity 10002, acceleration 10000

G90
G0 X0 Y0 B0
M7
M9
G1
X 26.0 Y 0 B 19.5 F 300
X 27.0 Y 0 B 39.0 F 300
X 28.0 Y 0 B 58.5 F 300
X 29.0 Y 0 B 78.0 F 300
X 30.0 Y 0 B 97.5 F 300
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 09, 2020, 10:14:22 AM
hi,
if i run your test here with all axis in Zero it takes about 21s.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 09, 2020, 10:23:05 AM
That is a really slow speed.
The linear speed (F300) should be 5 mm/sec.
Since the linear distance along X is only 4 mm, it should take only 1 sec?

I've removed the B... command and ran the code again.
The movement is much faster.
I don't quite understand what B-axis setting is wrong.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: TPS on December 09, 2020, 10:30:39 AM
in G1 move all axis start and stop together

B-Axis has 97mm to go, so it is about 20s.

and the x-move is 30mm, you start from X0
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 14, 2020, 08:32:05 PM
Hi Tom,

Finally, I managed to solve the problem.
The critical thing was to use G93 command, which let the machine finish all axes movement in a specific time.
All working now... Thanks a lot for your help so far!!

Best Regards,
Eric.
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: razer00 on December 15, 2020, 08:15:50 PM
FYI, the macropump that I used is;

SetModOutput=(81,GetUserDro(4))
Title: Re: [CSMIO-IP/S + MACH3] using an analogue output to control an external device
Post by: Vlad on February 24, 2021, 03:40:14 AM
I've hit into the same problem and this thread was a good hint!

But I'd like to do my bit:
maybe I did something wrong but useing untapped coordinate didn't worked in my case.
Contrary, useing any spare variable works fine. So my version of Macropump.m1s is

SetModOutput(80,GetVar(1)*409.5)
SetModOutput(81,GetVar(2)*409.5)

and G-code should contain something like

#1=5.0 #2=10.0

to setup 5V output on analog output 0 and 10V on output 1.