Join us today!

Notifications
Clear all

[Solved] System status light with adjustable On and Off timers

10 Posts
3 Users
6 Likes
530 Views
twinControls
Posts: 114
Admin
Topic starter
(@twincontrols)
Member
Joined: 2 years ago

Write a reusable PLC logic to control a system status light with adjustable On and Off time durations using any language. 

Sample:

 

Reply
9 Replies
2 Replies
ehixenbaugh
(@ehixenbaugh)
Joined: 2 years ago

Trusted Member
Posts: 29

@twincontrols Here is my finished, corrected version recorded on a .webm file and some screenshots. Thank you for your help.

FB StatusLight(MAIN Program)
FB StatusLight(POU)

Reply
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 114

@ehixenbaugh You're welcome! Glad you got it working!!

Reply
Posts: 17
(@joris)
Eminent Member
Joined: 2 years ago

I have this solution

Capture
code
Reply
3 Replies
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 114

@joris Well done!!! Maybe there's also a way to solve this using less variables 🤔 🙂

Reply
(@joris)
Joined: 2 years ago

Eminent Member
Posts: 17

@twincontrols What are you thinking about? xIsOn, xIsEndOff? It's to have a clean code, to be readable for all.

Reply
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 114

@joris Yes, I totally understand. You can also use one of the timers output as the input of the other timer and can solve this using 2 rungs. Your solution is great though! Thanks for sharing!

Reply
ehixenbaugh
Posts: 29
(@ehixenbaugh)
Trusted Member
Joined: 2 years ago

I am new to TwinCAT and am having trouble understanding how to use a TON/TOF inside of a function block.

When I try to make a Function Block called StatusLight, I have the following variables:

//Public Variable with Only Read Access
b_OutputLED : BOOL;
//Public Variables with Read+Write Access
b_InputSignal : BOOL;
t_onTime : TIME;
t_offTime : TIME;
//Private Variables Hidden to the User
fb_timerTON : TON;
fb_timerTOF : TOF;

I want to put the logic for the timers inside the StatusLight function block, but anytime I do that and create an object in the MAIN program, the timers themselves do not operate. I have read on other forums on the internet that you can't do this. Can someone explain why this is to me. 

(NOTE: Inside the FB for Status Light, the code for creating the on/off timing sequence is not complete. I wanted the focus of my question to be about why the TON/TOF function blocks can't work inside a new function block)

-Evan H.

FB StatusLight(POU)
FB StatusLight(MAIN Program)

 

Reply
2 Replies
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 114

@ehixenbaugh You can use function blocks inside a function block without any problem. Your first timer input is expecting b_InputSignal to be HIGH, but in the MAIN program, you haven't set that property yet. And instantiate your function block in MAIN.

FB_MyStatusLight(); 
Reply
ehixenbaugh
(@ehixenbaugh)
Joined: 2 years ago

Trusted Member
Posts: 29

@twincontrols Ok I did that and it worked like a charm. Sorry I had some replies that I deleted.

Reply
Share: