Hello Guest it is March 28, 2024, 10:01:03 PM

Author Topic: M code macros for IO control  (Read 12894 times)

0 Members and 1 Guest are viewing this topic.

spencoid

*
M code macros for IO control
« on: August 13, 2007, 02:13:20 PM »
I have read everything I can find and can probably struggle for a day or two to write what I need myself but am doing this as a favor for a friend and want to shorten the process as much as possible. I need to control a simple machine that moves the x and y steppers and operates a relay or two from M codes in a G code file. Specifically I need to move to a position, turn the relay on, wait (sleep) for a period, turn it off and check the state of a switch on the machine to see if it is clear before executing the next G code. From the examples I have seen, this looks possible. I would like a macro that I can just drop in and use. If I see something that works, I can edit it as I have computer programming experience and can figure out things that I see in code. Just don't have the time to figure it all out myself.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: M code macros for IO control
« Reply #1 on: August 13, 2007, 03:15:24 PM »
calll it, macro M222 (or what ever)

'M222.m1s
ActivateSignal(OUTPUT1) 'Turn on relay1
code "G4 P4"                  'Pause value P is seconds
While Ismoving()
Wend
DeActivateSignal(OUTPUT1) 'turn off relay1
SystemWaitFor(INPUT1)       'Wait for "clear" input

'scott
fun times

spencoid

*
Re: M code macros for IO control
« Reply #2 on: August 13, 2007, 11:11:05 PM »
thanks, that is pretty much what i thought was necessary but have never done this so it is great to have it from someone who knows this stuff.

spencoid

*
Re: M code macros for IO control
« Reply #3 on: August 14, 2007, 04:55:51 AM »
I can't figure out how to reply to the previous message so I am replying to myself.

I can not get the outputs to work. I have tried everything and have used the diag screen to see what is happening. I am running Mach2. I have the macro in the right place and have added some code to verify that the macro is running. It is running but the external outputs are not working. There is some confusion of terms in the setup screens and the documentation etc. Output is used in one place and external activation in another. I am using a PMDX-122 for testing. The outputs enabled LED is light but the jumper settings are very confusing in the instruction manual. If the syntax is correct for output control in mach2 then maybe this is not a question for the VB forum

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: M code macros for IO control
« Reply #4 on: August 14, 2007, 05:39:00 PM »
1st off..........UPGRADE to Mach 3!!!!! You have a lic. for Mach2 it will apply to Mach3, and many, many bug fixes has happened since mach2.

External out1 and Output1 is the same thing.  Look in your ports and pins, under outputs, make sure that Output1, 2....etc. is Enabled, if they are then toggle the Active hi, to active low, or vice versa.

Scott
fun times

spencoid

*
Re: M code macros for IO control
« Reply #5 on: August 14, 2007, 09:19:38 PM »
I started with mach3 and could not get it to work so I tried mach2 since I am more familiar with it. I switched back to mach3 and can not get it to work. Below are two macros that I have tested with. 333 works fine so I know that macros are working. Movement does not progress until I close switch 1.  222 does not change the state of output 1 no matter what I do. Even if the breakout board is not configured properly (the manual is very confusing but I have tried every combination of jumpers) output 1 should toggle in the diag mode but it doesn't. I have output 1 enabled in the pins config screen and have tried both active high and low.

'M222. this doesn't work to operate output 1
code "G00 X1 Y1"
ActivateSignal(OUTPUT1) 'Turn on relay1
code "G4 P4"            'Pause value P is seconds
DeActivateSignal(OUTPUT1) 'Turn off relay1
code "G00 X2 Y2"

'M333. this works fine
SystemWaitFor(INPUT1)       'Wait for "clear" input
code "G00 X1 Y1"

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: M code macros for IO control
« Reply #6 on: August 14, 2007, 10:12:38 PM »
You need the while is moving in the macro, it was in the first post I sent you.
This works on my machine just fine, (latest mach3), if it still doesnt work for you, reinstall mach 3.

'M222.m1s
ActivateSignal(OUTPUT1) 'Turn on relay1
code "G4 P4"                  'Pause value P is seconds
While Ismoving()
Wend
DeActivateSignal(OUTPUT1) 'turn off relay1
SystemWaitFor(INPUT1)       'Wait for "clear" input
fun times

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: M code macros for IO control
« Reply #7 on: August 14, 2007, 10:15:11 PM »
go to your diagnostic page, then open VB editor, then step through the code while watching the Output on the dianostic page leds turn on then off. If you are NOT getting a signal physical at the b reakout board then you have the wrong pins, or wrong board config.

Email Steve stallings, and get him to go over your board with you.

scott
fun times

spencoid

*
Re: M code macros for IO control
« Reply #8 on: August 14, 2007, 11:51:17 PM »
duh thanks. didn't know what the while moving did so i left it out. works fine now but there is a problem with the board config. i can get pins 2-9 to work but not the "outputs" pins 14 16 and 17. really doesn't matter because i can just use the ones that work. i am a very logical person but i can not make sense out of the PMDX manual. i could chart out the hints in the three sections that refer to configuration of the output pins and maybe it would make sense. is Steve Stallings the make of the Practical Micro Design Inc stuff? The boards that I have work fine for my mill  but this one (122)really has confusing documentation.

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
    • View Profile
Re: M code macros for IO control
« Reply #9 on: August 15, 2007, 08:51:20 AM »
Post your issues with steves board on the Mach Yahoo message board. Steve usually trolls that board, as a matter of fact almost all the OEMs troll that board, as well as Art.

Address your Post to Steve Stallings and post up your issues with his board, he will very promply reply!!!!!

Scott
fun times