Debouncing Timer on Micro 830 in Structured Text

spatricks

Member
Join Date
Jan 2013
Location
oklahoma city
Posts
9
I am wanting to debounce an digital input in structured text. I am using connected componets with a MICRO 830 2080-LC30-24-QWB.


So I essentially want to debounce both HIGH->LOW transitions and LOW->HIGH transitions to account for ripple in our digital sensors.


I have the following code that detects transitions like stated above, the problem is the code will react to any momentary ripple. I am wanting to debounce for at least 1 second.


Code:
(*Digital Input 0*)
(*Check for 1-to-0 transition*)
UTIL_input0_f(_IO_EM_DI_00);
(*If 1-to-0 transition detected, send out alarm message*)
IF UTIL_input0_f.Q = TRUE THEN 
    DATA_inputONOFFSMSText := '';
	DATA_inputONOFFSMSText := 'Alarm detected: Input 0 is OFF';
	UTIL_SEND_SMS_2( TRUE, CONFIG_slotID, CONFIG_receiverList, DATA_inputONOFFSMSText);
END_IF;
(*Check for 0-to-1 transition*)
UTIL_input0_r(_IO_EM_DI_00);
(*If 0-to-1 transition detected, send out alarm message*)
IF UTIL_input0_r.Q = TRUE THEN 
    DATA_inputONOFFSMSText := '';
	DATA_inputONOFFSMSText := 'Alarm detected: Input 0 is ON';
	UTIL_SEND_SMS_2( TRUE, CONFIG_slotID, CONFIG_receiverList, DATA_inputONOFFSMSText);
END_IF;

Could someone give me a code example that would debounce this for 1 second.
 
You will need to add a "One_Second_Timer" TON to your project and "enable" it when UTIL_input0_f(_IO_EM_DI_00)is true.
Within your code, replace every occurrence of UTIL_input0_f with One_Second_Timer/DN.
 
.DN = Timer "Done" bit; it is set (true) when the timer's accumulated value is equal to the preset value (the timer has timed out).
 
This results in an infinite loop that keeps sending messages that it is on


Code:
TEST_TON(_IO_EM_DI_00,TEST_MAXTIME);
(*If 1-to-0 transition detected, send out alarm message*)
IF TEST_TON.Q = TRUE THEN 
    DATA_inputONOFFSMSText := '';
	DATA_inputONOFFSMSText := 'Alarm detected: Input 0 is ON';
	UTIL_SEND_SMS_2( TRUE, CONFIG_slotID, CONFIG_receiverList, DATA_inputONOFFSMSText);
END_IF;

I don't see

EDIT, I don't see that I have access to a .DN bit
taXxP.png
 
Last edited:
I see...Set TEST_TON.PT to 1000 (I believe the CCW Timer base is ms) and use the TEST_TON.Q BOOL operand instead of the "classic" .DN bit.
 
This is so much easier in ladder logic...
I don't see the "Preset" of the timer within your code.
TEST_TON.Q will not be true until TEST_TON.PT has elapsed due to a 1-to-0 transition of (_IO_EM_DI_00) longer than the TEST_TON.PT value.
 
Yes it is...For one second it would be T#1s...
Now I see what's going on...Is (_IO_EM_DI_00) wired up NC ?...If Digital Input 1 is TRUE at all times except when the "event" takes place (1-to-0 transition/falling edge) you might want to use a TOF (Timer OFF) instruction) instead of the TON.
If you want to detect both edges, you will have to deploy two timers (a TON for the rising edge, and a TOF for the falling edge) within an OR statement logic.
 
Last edited:
I figured it out. Thanks for your help! This is what I settled on using a TONOFF


Code:
TIMER_DEBOUNCE_DI_0(_IO_EM_DI_00,TEST_MAXTIME,TEST_MAXTIME);
UTIL_input0_r(TIMER_DEBOUNCE_DI_0.Q);
UTIL_input0_f(TIMER_DEBOUNCE_DI_0.Q);

IF UTIL_input0_r.Q = TRUE THEN
   DATA_inputONOFFSMSText := '';
   DATA_inputONOFFSMSText := 'Alarm detected: Input 1 is ON';	
  UTIL_SEND_SMS_2( TRUE, CONFIG_slotID, CONFIG_receiverList, DATA_inputONOFFSMSText);
END_IF;


IF UTIL_input0_f.Q = TRUE THEN
	DATA_inputONOFFSMSText := '';
	DATA_inputONOFFSMSText := 'Alarm detected: Input 1 is OFF';
	UTIL_SEND_SMS_2( TRUE, CONFIG_slotID, CONFIG_receiverList, DATA_inputONOFFSMSText);
END_IF;
 
Last edited:
No problem...Haven't done any STL on CCW yet...Up until now...:ROFLMAO:
Never even thought of using anything but ladder logic on a machine level CPU...đź“š
 

Similar Topics

Hi Im new to the Micro range and 95% through a machine programming job, I'm just struggling on one task. Have a HMI and a maintained PB the a user...
Replies
8
Views
1,849
Hi. I have a quick question about debouncing. I have a machine which has two optical sensors as inputs. I’ll describe it simply as a conveyor...
Replies
6
Views
5,400
Hello! First time poster here. I've been in and out of PLC programming for around 10 years now. My current project has me way deeper into...
Replies
15
Views
5,670
I'm probably really showing my ignorance this morning... I need to filter some proximity input sensors. If I put a timer on & a timer off in...
Replies
6
Views
4,167
I have been away from this site for some time because I have been consumed with programming my SoftLogix5000 for my SoftLogix5800 controller...
Replies
2
Views
11,126
Back
Top Bottom