Dynomotion

Group: DynoMotion Message: 11579 From: cnc_machines Date: 5/26/2015
Subject: M-Code
Greetings,

I have a CNC machine with a air blow off function that I would like to function from either a push button on the front of the machine, or an M Code in the program. I can easily set up an if statement to make the button work, and then a separate thread for the MCode.

This code is in my infinite loop on the INIT file:

        if(ReadBit(1030)) //If button is pushed blow off
            SetBit(61);
        else
            ClearBit(61);


Unfortunately this clears bit 61 as quickly as my MCode thread sets it.


Is there a global variable that would be available to both the INIT thread and the M code thread? I could read the button (1030) and check to see if the other thread is running before I set or clear the bit. Does this make sense?


This should be be simple, I just dont know how to do it.


Thanks,


Scott

Group: DynoMotion Message: 11581 From: Tom Kerekes Date: 5/26/2015
Subject: Re: M-Code
Hi Scott,

Its always difficult to have two controls controlling the same thing.

You might set the bit only when the button is pushed and clear it only when the button is released.  The Debounce function you used earlier is handy for this as it returns 1 when the button first goes high, 0 when if goes low, and -1 when it hasn't changed.  So maybe try:

int alast=0,alastsolid=-1,acount=0;  // declare variable for air blast


        // Handle External Ar Blast button
        result = Debounce(ReadBit(1030),&acount,&alast,&alastsolid);
        if  (result == 1)
        {
            SetBit(61)
        }

        if  (result == 0)
        {
            ClearBit(61)
        }


HTH
Regards
TK

Group: DynoMotion Message: 11586 From: cnc_machines Date: 5/27/2015
Subject: Re: M-Code
Excellent! It worked perfectly Thanks!