Hi tom ,
I am using kflop+konnect+kanalog.
I have connected one MPG handwheel as per the connection on dynomotion wiki.
I want to control that MPG using a push button, similar to feed hold push button .
I checked the External buttons program and understood the debounce of a switch, but what if want to enable one i/o using bouncing that switch again. ??
One push button to enable that mpg and if pressing same push button, will disable the MPG, please help on how to proceed with that?
Waiting for your kind reply.
MPG ENABLE AND DISABLE USING A PUSH BUTTON
Moderators: TomKerekes, dynomotion
-
- Posts: 134
- Joined: Tue Feb 20, 2018 7:35 am
- Location: India
MPG ENABLE AND DISABLE USING A PUSH BUTTON
Thank You
AMIT KUMAR
AMIT KUMAR
- TomKerekes
- Posts: 2677
- Joined: Mon Dec 04, 2017 1:49 am
Re: MPG ENABLE AND DISABLE USING A PUSH BUTTON
Hi Amit,
You might do something like:
You might do something like:
Code: Select all
#include "KMotionDef.h"
#define ENABLE_MPG_BIT 46
int elast=0,elastsolid=-1,ecount=0;
int Debounce(int n, int *cnt, int *last, int *lastsolid);
void main()
{
int EnableMPG=0;
for(;;)
{
WaitNextTimeSlice();
// Handle Enable/Disable MPG
if (Debounce(ReadBit(ENABLE_MPG_BIT),&ecount,&elast,&elastsolid)==1)
{
EnableMPG = 1-EnableMPG; // toggle the enable
printf("Enable = %d\n",EnableMPG);
}
}
}
// Debounce a bit
//
// return 1 one time when first debounced high
// return 0 one time when first debounced low
// return -1 otherwise
#define DBTIME 300
int Debounce(int n, int *cnt, int *last, int *lastsolid)
{
int v = -1;
if (n == *last) // same as last time?
{
if (*cnt == DBTIME-1)
{
if (n != *lastsolid)
{
v = *lastsolid = n; // return debounced value
}
}
if (*cnt < DBTIME) (*cnt)++;
}
else
{
*cnt = 0; // reset count
}
*last = n;
return v;
}
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 134
- Joined: Tue Feb 20, 2018 7:35 am
- Location: India