THC in Marlin

I built a MPCNC Lowrider 2 and I’m using it as a CNC Plasma Cutter. I would like to implement Torch Height Control and I need some direction with syntax, Marlin and what pins to use. I don’t know where to start learning everything. I have found a lot of tutorials about configuring Marlin but I don’t know how to write a feature.

So far… I have a device that outputs between 0-5v based on the distance the plasma cutter is from the metal. if the tip is far away the voltage goes up. If the tip is close the voltage goes down. I will input 0-5v into my Ultimachine miniRambo 1.3. If the voltage is at 0v the Z stepper should not move. If the voltage is at 3.5v or more the Z stepper should move down. If the voltage is at 3v or lower the Z stepper should move up. I don’t exactly know how to code this into Marlin. How do I assign pins as inputs? what code will make the steppers move? I know how to move steppers with Gcode but I don’t think that is relevant to what I am trying. The adjustments need to be made while Gcode is running. Also since the Gcode gives a Z height coordinate the Z adjustments need to be made physically but without changing the coordinates inside the brain. I think marlin has something called baby steps that would accomplish this. If the coordinates were changed this would possibly cause the cut to start too far away or crash into the material at the beginning of each cut.

Thanks for any pointers and resources. I hope this was clear.

What device is this you’re referring to?

A few months ago @forcerouge mentioned in another thread that he spoke to the marlin developers and they were open to the idea of programming this for him but didn’t have electronics side sorted out.

There has been a lot of work done recently on THC over at linuxcnc, all open source. If you’re up for it you can take a look at this code and see how they did it. I don’t know if it’ll translate well at all to the way marlin does things, and I know you said you’re really only looking for simple hysteresis type contol… but it might be worth taking a look.

Thanks for the links Kyle. The device I have is simply just some resistors and an optocoupler. I’m wary of posting the specifics of it right now because 1: it might not work and 2: it is wired directly to the plasma cutter and that sort of thing can be dangerous to DIY. It could also be different for each plasma cutter. I’ll take a look at the linuxcnc solution.
Thanks

I’m sure it’ll be fine.
https://i.imgur.com/MMQulm0.mp4

3 Likes

I’m going to have to watch that movie now…

1 Like

Sounds like a PID control loop, but I don’t know how to feed that back to Marlin.

Getting connected to marlin seems to be the most difficult part. I’m making the transition to linuxcnc for my plasma table. I think the features I can get in Linuxcnc are worth the steep learning curve.

THC in marlin would allow us to make the cheapest cnc plasma cutters on the planet! I did get some cuts done without THC but I really had to fight the steel.

what movie is this from?

Down periscope.

2 Likes

thanks, that probably would’ve bugged me all week :stuck_out_tongue:

Yes, but the guys who code and maintain Marlin were totally open to do it last time I asked them. They told me they could help me creating such option if I were to provide them with actual data on how the hardware would be done.
Unfortunately I had to work on other stuff, plus I wasn’t entirely clear on the hardware myself, so I didn’t go further, my bad.
But if you do have such hardware or at least you know how to design it as well as what kind of output it could give to Marlin, then you should definitely get in contact with them through the Marlin forum, I’m sure they’ll help you if you ask nicely.

The idea was to feed this data as a babystepping parameter, so it wasn’t actually too hard to do (according to them at least)

Lieutenant, you’re almost out of uniform.

1 Like

“THC in Marlin”

Yeah, it’s showing up more and more everywhere. :dizzy_face:

Saw the title, clicked on for a read, and was like…

anyways, back OT. :wink:

I wonder if there would be a way to simply read the output of the Mesa THCAD from an Arduino? Circuitry there is already proven and safe… The THCAD I have outputs a range from 120-970 kHz, but from my limited googling the arduino can only read up to like 40kHz. Maybe someone knows how to easily design an intermediate circuit that can easily translate TCHAD to Arduino?

1 Like

The THCAD has a frequency output range of approximately 100 KHz to 1 MHz. T his can be counted directly by our FPGA cards for conversion to voltage value. The frequency output can optionally be divided by 32, 64 or 128 if the output must be counted in software.

From: THCAD picture

Looks like you can shrink it down. IDK how much spare time Marlin has to determine the frequency, or what kind of actual circuit you would need to make it not fry the arduino’s pins.

The THCADs frequency output is available on the FOUT+ and FOUT- pins. Thesepins comprise a differential pair. (That is, one output is always just an inverted copy of theother). For best noise immunity the differential outputs of the THCAD should drive aterminated RS-422 receiver. If differential mode is not required, either FOUT+ or FOUT-may be used as TTL level signals.

So it looks simple enough. 1MHz/128=7.8kHz.

1 Like

The frequency divider!! How could I forget?!

The frequency output can optionally be divided by 32, 64 or 128 if the output must be counted in software.

for a reliable reading I’m guessing you would have to put it on an interrupt pin? Are there any available? I’m guessing that would screw with the stepper timming?