You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old January 14th, 2013, 10:08 AM   #1
spatricks
Member
United States

spatricks is offline
 
Join Date: Jan 2013
Location: oklahoma city
Posts: 9
Debouncing Timer on Micro 830 in Structured Text

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.
  Reply With Quote
Old January 14th, 2013, 10:31 AM   #2
dmargineau
Lifetime Supporting Member
United States

dmargineau is offline
 
dmargineau's Avatar
 
Join Date: Dec 2011
Location: Midwest
Posts: 2,385
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.
  Reply With Quote
Old January 14th, 2013, 10:43 AM   #3
spatricks
Member
United States

spatricks is offline
 
Join Date: Jan 2013
Location: oklahoma city
Posts: 9
What is /DN?
  Reply With Quote
Old January 14th, 2013, 10:56 AM   #4
dmargineau
Lifetime Supporting Member
United States

dmargineau is offline
 
dmargineau's Avatar
 
Join Date: Dec 2011
Location: Midwest
Posts: 2,385
.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).
  Reply With Quote
Old January 14th, 2013, 10:57 AM   #5
spatricks
Member
United States

spatricks is offline
 
Join Date: Jan 2013
Location: oklahoma city
Posts: 9
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

Last edited by spatricks; January 14th, 2013 at 11:04 AM.
  Reply With Quote
Old January 14th, 2013, 11:17 AM   #6
dmargineau
Lifetime Supporting Member
United States

dmargineau is offline
 
dmargineau's Avatar
 
Join Date: Dec 2011
Location: Midwest
Posts: 2,385
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.
  Reply With Quote
Old January 14th, 2013, 11:37 AM   #7
spatricks
Member
United States

spatricks is offline
 
Join Date: Jan 2013
Location: oklahoma city
Posts: 9
Like I did in the code I posted? If so that code will get stuck in an infinite loop.
  Reply With Quote
Old January 14th, 2013, 12:03 PM   #8
dmargineau
Lifetime Supporting Member
United States

dmargineau is offline
 
dmargineau's Avatar
 
Join Date: Dec 2011
Location: Midwest
Posts: 2,385
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.
  Reply With Quote
Old January 14th, 2013, 12:20 PM   #9
spatricks
Member
United States

spatricks is offline
 
Join Date: Jan 2013
Location: oklahoma city
Posts: 9
TEST_TON.PT is TEST_MAXTIME which is 3s. Is this not a valid way to set the PT?
  Reply With Quote
Old January 14th, 2013, 01:11 PM   #10
dmargineau
Lifetime Supporting Member
United States

dmargineau is offline
 
dmargineau's Avatar
 
Join Date: Dec 2011
Location: Midwest
Posts: 2,385
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 by dmargineau; January 14th, 2013 at 01:19 PM.
  Reply With Quote
Old January 14th, 2013, 01:27 PM   #11
spatricks
Member
United States

spatricks is offline
 
Join Date: Jan 2013
Location: oklahoma city
Posts: 9
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 by spatricks; January 14th, 2013 at 01:30 PM.
  Reply With Quote
Old January 14th, 2013, 01:51 PM   #12
dmargineau
Lifetime Supporting Member
United States

dmargineau is offline
 
dmargineau's Avatar
 
Join Date: Dec 2011
Location: Midwest
Posts: 2,385
No problem...Haven't done any STL on CCW yet...Up until now...
Never even thought of using anything but ladder logic on a machine level CPU...
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Modicon Structured Text snipe LIVE PLC Questions And Answers 1 December 4th, 2003 01:35 PM
RS 5000 Structured Text olias LIVE PLC Questions And Answers 10 October 14th, 2003 02:20 AM
Documentation on Structured Text cmulder LIVE PLC Questions And Answers 13 June 11th, 2003 10:10 AM
Structured Text Programming Martin IRL LIVE PLC Questions And Answers 3 January 21st, 2003 11:49 AM


All times are GMT -5. The time now is 10:25 PM.


.