Hello Guest it is April 18, 2024, 06:24:10 PM

Author Topic: can a Mach3 macro toggle an output pin?  (Read 3572 times)

0 Members and 1 Guest are viewing this topic.

can a Mach3 macro toggle an output pin?
« on: February 16, 2017, 02:40:27 AM »
The following code toggles when stepped through in the Mach3 VB script editor but not when run or when the macro runs.
Code: [Select]
ActivateSignal(OUTPUT4)
DeactivateSignal(OUTPUT4)
ActivateSignal(OUTPUT4)
DeactivateSignal(OUTPUT4)
End
Viewed with an oscilloscope hooked to OUTPUT4 it moves when single stepping but never triggers when running.  Only the last state happens.  What am I missing? 

Offline Tweakie.CNC

*
  • *
  •  9,198 9,198
  • Super Kitty
    • View Profile
Re: can a Mach3 macro toggle an output pin?
« Reply #1 on: February 16, 2017, 03:29:44 AM »
It is happening but it is far too quick for anything to take effect.

To slow it down try adding :

While IsMoving ()
Wend

In between each line.

If that does not produce enough delay then also add a pause in between each line :

Code "G4 P#"

Where # is the amount of the delay you need.

Tweakie.
PEACE
Re: can a Mach3 macro toggle an output pin?
« Reply #2 on: February 16, 2017, 08:19:42 PM »
Tweakie,
Thanks for the help.  I was really struggling.  Neither worked alone, but using both together, before and after the output signal I will be triggering on, seemed to work.
Here's the code so far for reading custom M-Codes and sending off to a micro.  I'm using a G100 by the way.

Code: [Select]
'M106.m1s MyG100 for 3d printing from Slic3r
'Turn the extruder fan ON
fanspeed=param1()
Dim v As Integer
v = CInt(fanspeed)
msg = ""
Dim i As Integer
For i = 1 To 12
ActivateSignal(OUTPUT4) 'clock
If 1 = (v Mod 2) Then
ActivateSignal(OUTPUT3) 'this is the data
v=v/2-1
msg = msg & "1"
Else
DeactivateSignal(OUTPUT3)
v=v/2
msg = msg & "0"
End If
Code "G04 p1" 'this and next line required to slow signal. Must have
While IsMoving()  ' 'pause as ms' set in Config/General Config..
Wend
DeactivateSignal(OUTPUT4)'read data on clock going low
Code "G04 p1" 'need to surround where I want to read data
While IsMoving()
Wend
Next i
Message msg &" "&fanspeed

End


This is what the above does with channel 1 ->OUTPUT4, the clock and 2 ->OUTPUT3 as the data.  As you can see it takes about 5 seconds to send 12 bits of data even though I have the delays set for 1ms.   Slow but Ok since it doesn't happen to often.  Still needs tweaking of course, data is inverted.



This is calling up the M-Code in MDI mode.  M106 is for a fan aiming at the part and the P parameter is the speed.  The status line shows the P parameter 13 and the binary output that I'm sending to a Teensy micro controller that will be heating the bed and extruders and doing whatever other custom stuff a 3d printer does.  I was trying to use the analog in and out of the G100 but the documentation, software tools and language are too much pain for me.  Also tried the serial out but maybe it doesn't work on the G100.  With this little bit of code the G100 will be handling the X,Y,Z and extruder feed and handing off the rest via M-Code to the Teensy.  All the G-Code and M-Code is generated automagically from Slic3r.  Can't wait to try it.