customer debouncer
- giantstone
- Offline
- Senior Member
-
Less
More
- Posts: 55
- Thank you received: 0
25 Jun 2018 21:04 #112861
by giantstone
customer debouncer was created by giantstone
Hi, Im facing limit switch errors, such as "Home switch inactive before start of latch move", "joint 1 on limit switch error",
I figured it out this is probably due to electrical noise from my limit switches.
(btw the current limit switches Im using are of sunx GL-8H series.)
then I deployed debouncer for the limit switches (as you can see from the attached hal file) , and it did not help.
I figured it out that the default (software) debouncer will not help in my case, and I want to deploy a (software) debouncer written by myself which passed my tests.
here is the C code for my debouncer:
double reading_freq = 400 ; //hz #sampling frequency
unsigned reading_cache_size = 40 ; #sample storage size
double approching_switch_sig_thres = 0.5; # threshold for a signal change in the limit switch
int GPIO_PIN1_reading =0 ,GPIO_PIN5_reading=0; #GPIO_PIN1_reading is the limit switch reading
double GPIO_PIN1_sig_ratio,GPIO_PIN1_SIGNAL, GPIO_PIN5_sig_ratio,GPIO_PIN5_SIGNAL;
GPIO_PIN1_reading = (int) (pin_value & VGI_GPIO_PIN1) != 0; #GPIO_PIN1_reading is the limit switch reading
if ( frame_height_reading.size() <= reading_cache_size)
{frame_height_reading.push_back( GPIO_PIN1_reading ) ;} #filling up the sampling cache
else{
frame_height_reading.push_back( GPIO_PIN1_reading ) ;
frame_height_reading.erase (frame_height_reading.begin() ) ;
double gpio1_temp_reading =0;
for (unsigned i=0; i<frame_height_reading.size(); i++) //GPIO_PIN5_sig_ratio,GPIO_PIN5_SIGNAL
{ gpio1_temp_reading += frame_height_reading;}
GPIO_PIN1_sig_ratio = gpio1_temp_reading / (double) frame_height_reading.size() ;
if( GPIO_PIN1_sig_ratio >= approching_switch_sig_thres)
{GPIO_PIN1_SIGNAL =1;}
else {GPIO_PIN1_SIGNAL =0 ; }
cout <<"GPIO_PIN1_SIGNAL is " <<GPIO_PIN1_SIGNAL << "and GPIO_PIN1_sig_ratio is " <<GPIO_PIN1_sig_ratio << endl ;
} // end else (frame_height_reading.size() <= reading_cache_size)
GPIO_PIN1_SIGNAL is the final output signal from the limit switch.
I wonder if anyone could help me to deploy this debouncer to my linuxcnc machine.
the other solutions to deal with the limit switch errors, I'm trying, is to re-wire the switches away from other power cables,
to try new limit switches.
I appreciate your time reading this post.
I figured it out this is probably due to electrical noise from my limit switches.
(btw the current limit switches Im using are of sunx GL-8H series.)
then I deployed debouncer for the limit switches (as you can see from the attached hal file) , and it did not help.
I figured it out that the default (software) debouncer will not help in my case, and I want to deploy a (software) debouncer written by myself which passed my tests.
here is the C code for my debouncer:
double reading_freq = 400 ; //hz #sampling frequency
unsigned reading_cache_size = 40 ; #sample storage size
double approching_switch_sig_thres = 0.5; # threshold for a signal change in the limit switch
int GPIO_PIN1_reading =0 ,GPIO_PIN5_reading=0; #GPIO_PIN1_reading is the limit switch reading
double GPIO_PIN1_sig_ratio,GPIO_PIN1_SIGNAL, GPIO_PIN5_sig_ratio,GPIO_PIN5_SIGNAL;
GPIO_PIN1_reading = (int) (pin_value & VGI_GPIO_PIN1) != 0; #GPIO_PIN1_reading is the limit switch reading
if ( frame_height_reading.size() <= reading_cache_size)
{frame_height_reading.push_back( GPIO_PIN1_reading ) ;} #filling up the sampling cache
else{
frame_height_reading.push_back( GPIO_PIN1_reading ) ;
frame_height_reading.erase (frame_height_reading.begin() ) ;
double gpio1_temp_reading =0;
for (unsigned i=0; i<frame_height_reading.size(); i++) //GPIO_PIN5_sig_ratio,GPIO_PIN5_SIGNAL
{ gpio1_temp_reading += frame_height_reading;}
GPIO_PIN1_sig_ratio = gpio1_temp_reading / (double) frame_height_reading.size() ;
if( GPIO_PIN1_sig_ratio >= approching_switch_sig_thres)
{GPIO_PIN1_SIGNAL =1;}
else {GPIO_PIN1_SIGNAL =0 ; }
cout <<"GPIO_PIN1_SIGNAL is " <<GPIO_PIN1_SIGNAL << "and GPIO_PIN1_sig_ratio is " <<GPIO_PIN1_sig_ratio << endl ;
} // end else (frame_height_reading.size() <= reading_cache_size)
GPIO_PIN1_SIGNAL is the final output signal from the limit switch.
I wonder if anyone could help me to deploy this debouncer to my linuxcnc machine.
the other solutions to deal with the limit switch errors, I'm trying, is to re-wire the switches away from other power cables,
to try new limit switches.
I appreciate your time reading this post.
Please Log in or Create an account to join the conversation.
26 Jun 2018 03:06 #112864
by Sparky961
Replied by Sparky961 on topic customer debouncer
I apologize in advance, as my reply is not likely to be helpful...
However, I have to say that this seems fishy. Of the collection of machines running LinuxCNC I've dealt with, I've never had an issue with home and/or limit switches requiring debouncing to the extent that your code implements.
If you have a scope, I'd be really interested to see what's going on with the signal from the switch. If not, you can use HALScope to get an idea at slightly less resolution.
Anyway, I'll be following along and I'm interested to see what comes of this.
However, I have to say that this seems fishy. Of the collection of machines running LinuxCNC I've dealt with, I've never had an issue with home and/or limit switches requiring debouncing to the extent that your code implements.
If you have a scope, I'd be really interested to see what's going on with the signal from the switch. If not, you can use HALScope to get an idea at slightly less resolution.
Anyway, I'll be following along and I'm interested to see what comes of this.
Please Log in or Create an account to join the conversation.
26 Jun 2018 20:26 #112908
by andypugh
Replied by andypugh on topic customer debouncer
What is it about the standard debounce that fails to work?
You can set the debounce time much longer, if necessary.
If you are convinced that you need your own debounce:
linuxcnc.org/docs/2.7/html/hal/comp.html
But I would also suggest a filter on the VFD power input.
You can set the debounce time much longer, if necessary.
If you are convinced that you need your own debounce:
linuxcnc.org/docs/2.7/html/hal/comp.html
But I would also suggest a filter on the VFD power input.
Please Log in or Create an account to join the conversation.
Time to create page: 0.073 seconds