S7 question. Clearing Variable Dec. Table

Johnny T

Member
Join Date
Jul 2003
Location
Fife, Scotland
Posts
642
Hi,

I've written a function block that takes in a few parameters and then outputs #motor_in_pos declared in the variable declaration table.

The problem is that the FB is only called occasionally (as and when I need to check if a motor is in position).

What seems to be happening is that if the last motor checked was in position ie. #motor_in_pos = 1. Then when I call it again to check either the same motor or a different one, the output is already set to a 1 so the software assumes that the next motor is in position. (hope this is making sense).

I need some way of calling the FB and initially (ie. just the first scan) clear all the variable declaration table back to their initial values. Then to continue to scan the block and report back to the calling block.

Can this be done?

Many thanks

JT :)
 
I can't help this time, because I've got more or less the same problem. I'm doing error checking in a multi-instance DB and on the odd occasion when an error occurs and sets the error bit in the STAT variable even after clearing the error, because the bit in the DB is set the error keeps being reported. Since I don't want to have to start mucking about clearing the DB explicitly from somewhere else, I'll be interested to see if someone comes up with a good solution for this one!
 
I did have a quick look into the /FC bit of the status word (First Check) but I wasn't sure how to implement it so thought I'd see if there was another way of doing things.

That's you and me with the same problem... it must be a common problem and therefore I'm sure there's a dead easy solution to it... (fingers crossed)...

;)
 
... what exactly is 'first scan' ? i guess... it's not after plc run, because in this case you would use OB100, right? so you need the self-restarting FB? Is there a problem to define external flag which will tell FB that new cycle (of motor in-positioning) has been started ?

- btw... why not use FC instead of FB ? it will reduce problems with datablock assigning and recreating (depends on your particular implementation of course)
 
Marius

Thanks for the reply. Its not so much a problem of detecting a new scan. Its just that the FB doesn't get called every scan. Only when the system has to check the position of a motor. So the system passes in the motor number and the block gives out the boolean signal motor_in_pos OR motor_not_in_pos if the motor takes longer than 5 seconds to reach the designated position.

The problem is that the motor_in_pos signal is boolean and if the block stops getting called while its a 1 then the next time the block is called it is still a 1 and the program falls through the block thinking the motor is in position.

If I could reset everything initially on calling the block then I think that would solve the problem

Cheers

JT :)
 
You can add an "init" BOOL to the FB.
If FB is called, and "init is not set, then you clear all relevant variables AND set "init".
Then if FB is not to be called, you reset "init" outside the FB.

Maybe there is a neater way to do it, but it ought to work at least.
 
... 'init' BOOL solution would be most simple, but if you really need it, i think you can make timer an argument of FB and let FB decide it's own (non)successful termination (which will be more difficult and may not be good for safety needs of particular project) ...
 
I generally call all blocks all the time so the blocks themselves can perform edge detection etc. If there is some processing you want to skip, jump around it in the FB itself.

However, one suggestion is to make your 'in position' variables IN_OUT variables. Given that you know when your are going to call the block, you could reset the 'in position' (again using edge detection) in the same area of logic where you are deciding whether to call the block or not. It will be much neater to do it in the FB itself though.
Your comment concerning checking the same motor or a different one only applies if you are not using multiple instances of the FB, in which case you may as well use an FC.
 
Simon, Marius

Many thanks for your replies.

I've cracked it now. I did it the way Simon said and called the FB unconditionally but then made a separate 'in' variable called "start function" of BOOL type. The FB is called every scan but only performs the necessary calculations when 'start function' is true.

Simple when you know how eh? :)

It was one of those problems that I'd been staring at for so long I couldn't see the wood for the trees... thanks for your posts that helped me out.

Cheers

JT ;)
 

Similar Topics

I'm told its necessary to clear latch bits and sometimes timers in disabled subroutines...but why? I'm thinking either it would mess up future...
Replies
6
Views
3,593
I have an HMI 2711R - T4T Series B, and I want to know which PLCs, besides Micro 820, can communicate with it.
Replies
2
Views
53
HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
58
I'm working with a project that contains some routines in ST but mostly in ladder. Am I correct in assuming this 'rung': DB1001DO._01AV55_OPEN :=...
Replies
4
Views
95
Is there a way to reset the count on the RS Logix BackUp?? XXXXX PROGRAM IN PROGRESS_BAK445.RSS XXXXX PROGRAM IN PROGRESS_BAK446.RSS XXXXX...
Replies
8
Views
247
Back
Top Bottom