Loops and Threads

Moderators: TomKerekes, dynomotion

Post Reply
EondeK
Posts: 14
Joined: Thu May 17, 2018 3:29 pm

Loops and Threads

Post by EondeK » Sat Jun 02, 2018 12:20 pm

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

Moray
Posts: 288
Joined: Thu Apr 26, 2018 10:16 pm

Re: Loops and Threads

Post by Moray » Sat Jun 02, 2018 8:27 pm

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.

EondeK
Posts: 14
Joined: Thu May 17, 2018 3:29 pm

Re: Loops and Threads

Post by EondeK » Sun Jun 03, 2018 8:03 am

Tnx, these are great ideas. I will give it a try.

Post Reply