Page 1 of 1

Loops and Threads

Posted: Sat Jun 02, 2018 12:20 pm
by EondeK
Hi, I need to write a program to do intermittent Spray Mist Control. I thought of using a loop which can then pull the I/O pin low for Time A and wait for Time B before doing it again. Some questions:
1) I can start the loop as a forever loop but how do I stop it?
2) The loop needs to run at the same time as the Gcode interpreter and not wait for the completion of the loop

What would be the best way to do this?

Regards

Re: Loops and Threads

Posted: Sat Jun 02, 2018 8:27 pm
by Moray
How do you plan on starting/stopping the misting?

My approach would probably be to include it in my init.c forever loop, and have it monitor a virtual bit (that can be set/unset via KMCNC using an M-code). When virtual bit is set, turn on output, and store the time the output has to be turned off. When time expires, repeat but turn bit off, and store turn on time. Then repeat from start until virtual bit is turned of.

Alternative approach would be two C-programs. One with a forever loop that starts and runs indefinitely, and another basic one that turns the output off then exits. Load them to a dedicated thread, and running the basic/turn off program will kill the forever loop program.

Re: Loops and Threads

Posted: Sun Jun 03, 2018 8:03 am
by EondeK
Tnx, these are great ideas. I will give it a try.