GSV Wall Clock in RS Logix 5000 - Compact Logix L32E

alive15

Member
Join Date
Oct 2015
Location
Montgomery, AL
Posts
690
Hey everyone, I want to add the clock into my RS Logix 5000 program. Looking at other threads, I learned to use the GSV command, but I still cannot see the time when I check the controller tags. Attached is an image (Capture.png) of what I've done in my RS Logix 5000 program.

So the tag I created for the wall clock is called "CLOCK" and the data type is DINT[7] as seen from other threads. Attached is an image (data type.png) of the tag and the data type.

I also tried to change the destination in the rung to "CLOCK" instead of "CLOCK[0]" but the program gives me an error saying "Error: Rung 0, GSV, Operand 3: Missing reference to array element." As of now, I have the destination as CLOCK[0], and all the values from CLOCK[0] - [6] are 0 in my program when online.

So How can I fix the logic to make the correct times appear in the tags once I go online with it? Thanks.

P.S. - This is RS Logix 5000 V 20.1

Capture.jpg data type.PNG
 
Last edited:
are you sure that you're scanning/executing the new routine where you've placed the GSV? ...

just as a test, try moving the GSV rung to an existing routine which you're certain is already being executed/scanned ...
 
Last edited:
^ Yup. Verify that you're calling the subroutine. Using a RET within is good practice.

That being said, CLOCK[6] should be in units of microseconds, rather than milliseconds.
 
Last edited:
Thank you, that was it!

Also, what's the benefit of using RET? I have a main routine that jumps to different subroutines, but inside those subroutines, I never use RET.
 
you don't really need an RET (Return) instruction for Ladder Logic in an Allen-Bradley PLC (the ladder execution will "return" automatically) ...

unless ...

if you're going to "pass parameters" to/from the subroutine, then the RET gives you a mechanism to specify which location/address/tag you'll be "passing" back to the "calling" routine ...

or ...

if you want to make only a PARTIAL scan of a subroutine (bail out early) then you can put an RET partway through the subroutine - and make the rung conditional ... then whenever the condition tests TRUE, the scan will "skip" the rest of the subroutine code - and just go back to the "calling" routine ...

be that as it may - some programmers always put an RET at the end of every subroutine "just because" ... it doesn't hurt anything - and it makes them feel better ... I think a lot of the reason goes back to when they studied subroutine calls in their computer science classes ... in regular computer applications, the Return is usually "required" ... in PLC work, it's usually "optional" ...
 
Last edited:
Cool, I learned a new way to use the RET instruction now to bail out of the ladder if I need to. Thanks for providing the information to me.
 
well, just because you "can" – doesn't necessarily mean that you "should" ...

something that many PLC programmers fail to consider is that the machinery that these things control will have to be maintained – and kept running – usually by folks who are not really up-to-speed on fancy programming techniques ...

Gomer and Goober on nightshift might have some serious problems understanding "WHY" the tail-end of a ladder logic routine isn't functioning the way they expect it to ...

case in point ...

you yourself were being puzzled by having a new GSV rung which wasn't being scanned/executed ... picture how confusing that same scenario would be to someone who's desperately trying to get a pump to run at 3:00 o'clock in the morning ...

good luck with your project ...
 
Ron Beaufort said:
...if you're going to "pass parameters" to/from the subroutine, then the RET gives you a mechanism to specify which location/address/tag you'll be "passing" back to the "calling" routine...

Ron,

I know you were only expanding on the RET instruction's function above, but for the "to" aspect, I think we should mention the requirement for the SBR (Subroutine) instruction to pass parameters "to" a subroutine from a JSR instruction...

If a JSR instruction passes a value into a routine, the routine must have a Subroutine (SBR) instruction. The SBR instruction must be the first instruction within the routine. The SBR instruction allocates a memory location to accept the data that is being passed by the JSR instruction. For the tags assigned to the JSR and SBR instructions, the order of the data types and values must match for both instructions. Their names can, however, be unique from the calling routine.

I just think that while our friend is learning a little, the above helps, somewhat, to complete the picture. Else it's just me being me again?

p.s. I think we all need to start programming to circumvent the all to commonly mentioned and allusive "3:00AM" gremlins!

Maybe bypass everything for 5 minutes either side of that hour?

...or...

Manipulate the controller's clock to fool it?

...or...

Introduce fixed breaks from 2:50 - 3:20?

Damn you 3:00AM!!

Regards,
George
 
Ah, George, my friend ... George, George ... George, indeed...

we really need to meet in person some day ... perhaps we're actually twins separated at birth ...

Else it's just me being me again?

no – it's just "us" being "us" ... you and I seem to share a penchant for PLC minutiae that many others seem to studiously avoid ...

I'm reminded of the old jokes that start off: "A man walks into a bar with a frog on his head" ... but here we have: "A man walks into a forum with a simple GSV problem – and walks out (eventually) with a dissertation on the passing of parameters" ...

in hindsight:

this thread started off with a new member (mistakenly) thinking that he had a problem with a GSV instruction ...

turns out that (instead) he actually had a problem with scanning – so naturally a JSR entered the conversation ...

somewhere along the way, a recommendation to use an RET instruction was mentioned ...

not wanting to appear "confrontational" – I tried to gently add a mild dose of: "well, you COULD – but you don't HAVE TO" into the conversation ...

which led to my mentioning the "passing of parameters" – and also to bringing up the less-used "skip the end of the subroutine" idea ...

I actually thought about mentioning the SBR instruction myself – but decided that "enough was enough" ... I should have known better ... thanks to you, I'm now (properly – and politely) reminded that "enough" really never is ... at least not to you – nor to me – nor to others of a like mind ... there's always another dose of "knowledge" to be found at the bottom of every bottle of "lesson" ...

and to be honest, I was betting (pocket change only) that the original poster would come back after my first post with the news that he didn't know exactly "how to" scan a new ladder routine ... so I had a Notepad "standing by" on my desktop - already loaded with the following link – ready to paste into an additional post if something more forceful than a JSR became necessary ...

http://www.plctalk.net/qanda/showthread.php?p=567395&postcount=9

so ...

I thank you (sincerely) Friend George, for carrying the discussion along ... and I assure you that (as always) no offense is taken – nor intended – throughout any of this ...

and now I must get back to "paying" work ... I'm swamped right now – and my landlord has recently informed me that he wants to "talk about" my lease on the office space that I've been using for the last eight years ... depending on how that conversation goes, I might well join the ranks of the "retired" before the end of the year ... if so, I can assure you that I will definitely miss all of this ...

be safe ...
 
Last edited:
You gentlemen are awesome. I was breaking my head trying to get the GSV to return the wallclocktime. I tried both DINT[7] and a UDT looking through all the threads here and still nothing just a bunch of 0s. After a while I got the GSV with UDT ( Dest = CurrDateTime.Minute ) and saw the light when my structure was filled with the correct Date and Time! But it wouldn't update...
After another extensive search I finally got it to update with each scan by changing the Dest = CurrDateTime.Year, and similarly tried with the DINT[7] (ie Dest = Time[0]).

Anyway I'm fairly new to this and learning as I go; just thought I'd post my findings if anyone is on the same boat.

What's the reason the GSV only updates when the Destination is the first array element?
 
If I may...

fdiaz said:
...What's the reason the GSV only updates when the Destination is the first array element?

This is because the LocalDateTime Attribute, within the WALLCLOCKTIME Object, that you are "getting" using a GSV instruction, is preset to 7 x DINT values in a fixed ordered array...

Example:

WALLCLOCK[0] = Year
WALLCLOCK[1] = Month
WALLCLOCK[2] = Day
WALLCLOCK[3] = Hour
WALLCLOCK[4] = Minute
WALLCLOCK[5] = Second
WALLCLOCK[6] = Microsecond

So when you specify the Destination address, it must be the first element or member of a similar 7 x DINT array.

You can create a simple array of 7 x DINT using...

Example:

Tag Name = CLOCK
Data Type = DINT[7]

CLOCK[0] = Year
CLOCK[1] = Month
CLOCK[2] = Day
CLOCK[3] = Hour
CLOCK[4] = Minute
CLOCK[5] = Second
CLOCK[6] = Microsecond

Or a User-Defined - User Data Type (UDT), such as yours...

UDT Name = CurrDateTime
Members =
CurrDateTime.Year
CurrDateTime.Month
CurrDateTime.Day
CurrDateTime.Hour
CurrDateTime.Minute
CurrDateTime.Second
CurrDateTime.Microsecond

Because the GSV is pulling out the fixed ordered array data, starting with the .Year value, you must assign your equivalent first member of your array, whether using the more simple created tag's first element, or the UDT's first member. Else the data will not populate in the correct order within the destination.

It's similar to the likes of a MOV or COP instruction and the assigned length. You specify the first element or member of an array as the Destination and the Length dictates how deep the instruction will execute upon that destination.

The difference with the likes of the GSV instruction is that the Length is preset or predefined to the Object it is operating upon and you need to know it.

I hope that's clear?

Regards,
George
 

Similar Topics

Hello all. Would anyone have sample code that uses a wall clock to move the CTU.ACC to a another variable in the PLC after 24-hours has elapsed? I...
Replies
2
Views
1,917
So, I'm really just trying to get some experience by practicing with arrays. I'm using studio 5000 v33. I have one rung with an XIC bit that's...
Replies
5
Views
132
Hello all, I know in the past it's been the case that we wanted to limit the total number of GSV calls per scan of the PLC. Is that still the...
Replies
2
Views
641
Hello, I have a question regarding the status checking of the module in the secondary chassis in a redundancy setup. CHASSIS 1 ...
Replies
6
Views
1,046
Hello Members We have a controllogix redundancy setup and need to display the status of redundancy in panelview. I have found in the manual the...
Replies
8
Views
1,205
Back
Top Bottom