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 December 3rd, 2009, 07:23 PM   #1
twu026
Lifetime Supporting Member
New Zealand

twu026 is offline
 
Join Date: Jan 2008
Location: Wales
Posts: 62
Beckhoff losing persistent data values

I am using a Beckhoff PLC (CX9010 series) for a batching process control.

There are a lot of parameters (scale factors, preset, setpoints etc) that are criticial to the control logic which I need to store in the PLC.

These variables that I wish to retain have been declared as VAR_PERSISTENT in the PLC.

My problem is that under certain circumstances the data that had been declared as persistent will lose its values and go back to defaults.

After doing some digging I have found out a few things related to the persistent data but there is still a lot of holes in my knowledge.

My understanding is this:

- The variables that are declared as VAR_PERSISTENT get stored on the Bechkoff as a file named TCPLC_T_1.wbp in the TwinCAT\Boot\ directory
- This TCPLC_T_1.wbp file is created everytime TwinCAT is placed into Configure mode OR when the WritePersistentData function block is called in the PLC program.
- When TwinCAT is placed into Run mode, the TCPLC_T_1.wbp is read and renamed to TCPLC_T_1.wb~ (which is suppose to be a backup copy).

Now, as far as I have been able to establish. If the PLC is power cycled with only the backup file (TCPLC_T_1.wb~) in the directory, the persistent data will be lost.

Here comes the question:

How is this persistent data file actually linked to the PLC program?

There must be a way the PLC program links/maps tags to that file.

Now, if I made a change to the PLC program that required a program download (not online change). Does that mean the persistent data file is no longer valid and will not load?

I have noticed that when I did a program download any of the 3 possible things could happen:

- all my persistent data are retained
- all my persistent data goes back to default values
- some of my persistent data goes back to default values and some are retained

As a side question:

When/How does PLC Control decide a full download is required and when an online change is permitted?

When/How does PLC Control decide the offline project does not match the code on the PLC and hence require a full download to go online?

There has been times that I swear I have the latest copy of the code and yet PLC Control refuses to let me go online without a full downloads (which means I risk losing my persistent data).

I personally do not like Windows/PC based control. The concept of the PLC code running as an app in a multi-purpose operating system with the data being stored as files in directories.
  Reply With Quote
Old December 3rd, 2009, 09:06 PM   #2
Archie
Member
United States

Archie is offline
 
Join Date: May 2002
Location: Orangeburg, SC
Posts: 1,754
As far as I know the Persistant memory does not work on Windows CE because it requires an orderly shut down in order to write the data to the file. I have never used the UPS for the CX series which may allow it to work.

To save data that needs to survive through a power cycle, I have always used the Non-Volatile Ram (NOVRAM). There are two way to do this.

The first is to assign an address (%Qxx) to the variables that need to save their values and then link them to NOVRAM using the System Manager. There is a problem with this on the CX controllers. The NOVRAM write cycle is slow which will cause the CPU usage to jump above 60% and even max out to 80%.

The second way, which I prefer is to use the FB_NovRamReadWriteEx function block. I either use a TON or configure another Task that scans typically every 2 seconds and writes the data to NOVRAM. On a first pass scan during restart, I use the function block to read the NOVRAM.
__________________
Expectations lead to disappointment. Appreciation leads to satisfaction.

AdvancedHMI - HMI Software without the license key hassles
  Reply With Quote
Old December 4th, 2009, 10:43 AM   #3
SteveMaves
Member
United States

SteveMaves is offline
 
Join Date: Apr 2009
Location: Minneapolis, MN
Posts: 141
Quote:
Originally Posted by twu026 View Post
I am using a Beckhoff PLC (CX9010 series) for a batching process control.

There are a lot of parameters (scale factors, preset, setpoints etc) that are criticial to the control logic which I need to store in the PLC.

These variables that I wish to retain have been declared as VAR_PERSISTENT in the PLC.

My problem is that under certain circumstances the data that had been declared as persistent will lose its values and go back to defaults.

After doing some digging I have found out a few things related to the persistent data but there is still a lot of holes in my knowledge.

My understanding is this:

- The variables that are declared as VAR_PERSISTENT get stored on the Bechkoff as a file named TCPLC_T_1.wbp in the TwinCAT\Boot\ directory
- This TCPLC_T_1.wbp file is created everytime TwinCAT is placed into Configure mode OR when the WritePersistentData function block is called in the PLC program.
Correct so far, also, when the PLC does an orderly shutdown, either from the start menu, or as Archie mentioned, with a UPS.

Here's a detailed description of Retain and Persistent variables...
http://infosys.beckhoff.com/content/...torvardecl.htm
Scroll towards the bottom of the page.

Quote:
Originally Posted by twu026 View Post
- When TwinCAT is placed into Run mode, the TCPLC_T_1.wbp is read and renamed to TCPLC_T_1.wb~ (which is suppose to be a backup copy).

Now, as far as I have been able to establish. If the PLC is power cycled with only the backup file (TCPLC_T_1.wb~) in the directory, the persistent data will be lost.
See the link above, there's two files, the last, and the next too last. There's also a set of bits you can and should check in your code to make sure that you got good data from the files. This data is retrieved before TwinCAT starts. One other thing that gets people is that the system writes the files back to zero on startup, so in your code, on the first scan, you should check to make sure you loaded the persistants correctly, then call FB_WritePersistant one time again to get them "committed" back into the file. The logic being here thatif there's a problem you'll want to alert the operator right away before you intiate machine operation.

Quote:
Originally Posted by twu026 View Post

Here comes the question:

How is this persistent data file actually linked to the PLC program?

There must be a way the PLC program links/maps tags to that file.

Now, if I made a change to the PLC program that required a program download (not online change). Does that mean the persistent data file is no longer valid and will not load?

I have noticed that when I did a program download any of the 3 possible things could happen:

- all my persistent data are retained
- all my persistent data goes back to default values
- some of my persistent data goes back to default values and some are retained
Hope these questions are all answered by the link above.

Quote:
Originally Posted by twu026 View Post

As a side question:

When/How does PLC Control decide a full download is required and when an online change is permitted?
Not sure I know, sorry.

Quote:
Originally Posted by twu026 View Post

When/How does PLC Control decide the offline project does not match the code on the PLC and hence require a full download to go online?

There has been times that I swear I have the latest copy of the code and yet PLC Control refuses to let me go online without a full downloads (which means I risk losing my persistent data).
The PLC compares the compiled version of the program on the development PC with the compiled version on the target, so if you move just the .PRO file onto a new development PC and do a recompile, it's just like doing a "Rebuild All", and you are in effect starting over. The feature "File / Save/Mail Archive" will allow you to save all the files together in one zip file, that's the best way to move a program from one development PC to another.

Quote:
Originally Posted by twu026 View Post

I personally do not like Windows/PC based control. The concept of the PLC code running as an app in a multi-purpose operating system with the data being stored as files in directories.
Well, to each is own. However, be aware that the architects of TwinCAT are aware of the pitfalls associated with PC based control, and have made provision to keep the data integrity.

The long and the short of it, if you absolutely must have data integrity, the best solution is to use two methods, Persistant data, and the NOVRAM that Archie has already suggested.

Best of luck.
  Reply With Quote
Old December 4th, 2009, 01:25 PM   #4
Joe_WaZoo
Lifetime Supporting Member
United States

Joe_WaZoo is offline
 
Joe_WaZoo's Avatar
 
Join Date: Oct 2006
Location: Murphy, TX
Posts: 301
Banner still hasn't replaced anybody of your caliper yet. We miss you there!

Joe_WaZoo
__________________
TURCK Network I/O Guy, Banner Wireless knowledge, & Red Lion HMI stuff! Yes I am the techie geek for the local Rep Firm Automated Dynamics Corp covering the states of TX, OK, AR, LA, MS, part of TN, and a little bit of Mexico.
  Reply With Quote
Old December 4th, 2009, 02:12 PM   #5
SteveMaves
Member
United States

SteveMaves is offline
 
Join Date: Apr 2009
Location: Minneapolis, MN
Posts: 141
Thanks Joe, hope you are enjoying Crimson 3.0, sounds pretty cool.
  Reply With Quote
Old December 4th, 2009, 11:54 PM   #6
twu026
Lifetime Supporting Member
New Zealand

twu026 is offline
 
Join Date: Jan 2008
Location: Wales
Posts: 62
Thanks for all the help/advice guys. The problem I have is that there is no Beckhoff tech support in New Zealand and Beckhoff's documentation is far from complete.

We originally tried to use the NOVRAM method, but like Archie mentioned we experienced high CPU loads.

Thanks Archie, I will look into the FB_NovRamReadWriteEx, sounds like a potential work around.

Thanks Steve, I will make sure to use the "Save/Mail Archive" method to move files between development PC.

Last edited by twu026; December 4th, 2009 at 11:58 PM.
  Reply With Quote
Old December 5th, 2009, 09:21 AM   #7
Archie
Member
United States

Archie is offline
 
Join Date: May 2002
Location: Orangeburg, SC
Posts: 1,754
Quote:
Originally Posted by twu026 View Post
Thanks Archie, I will look into the FB_NovRamReadWriteEx, sounds like a potential work around.
If you need any sample code, I'll be glad to email you some project files.I have the sample from Beckhoff and a version of it that I had written.
__________________
Expectations lead to disappointment. Appreciation leads to satisfaction.

AdvancedHMI - HMI Software without the license key hassles
  Reply With Quote
Old December 5th, 2009, 01:00 PM   #8
qwsoftware
Member
Australia

qwsoftware is offline
 
Join Date: Feb 2006
Location: Perth
Posts: 10
Hi twu026,

I had exactly the same questions as you with developing our product with Twincat!!

I dont use a UPS or NOVRAM as limited, I just create a persistent data backup every hour and as soon as the power is cycled, on the first scan, create a new persistent data file as I found that once the TCPLC_T_1 has been read on boot, it cant be used for the next boot for some strange reason so simply recreate it!

I have some sample code and can help you out if need more info

Regards

Matt
  Reply With Quote
Old December 6th, 2009, 07:17 AM   #9
Archie
Member
United States

Archie is offline
 
Join Date: May 2002
Location: Orangeburg, SC
Posts: 1,754
Quote:
Originally Posted by qwsoftware View Post
I dont use a UPS or NOVRAM as limited, I just create a persistent data backup every hour and as soon as the power is cycled, on the first scan, create a new persistent data file as I found that once the TCPLC_T_1 has been read on boot, it cant be used for the next boot for some strange reason so simply recreate it!
One thing to be cautious about is not to write to the flash memory too much. They do have limited write cycles (typical 1,000,000). If they are written to every few seconds, you can kill the memory/flash card within months.
__________________
Expectations lead to disappointment. Appreciation leads to satisfaction.

AdvancedHMI - HMI Software without the license key hassles
  Reply With Quote
Old December 7th, 2009, 09:42 AM   #10
SteveMaves
Member
United States

SteveMaves is offline
 
Join Date: Apr 2009
Location: Minneapolis, MN
Posts: 141
Archie is right, Compact Flash cards have limited write cycles. Beckhoff sources CF cards that have a "wear leveling" feature that makes the cards last longer. The inexpensive consumer-grade cards don't have this feature, so don't last as long.

Archies advice about using a slow task to initiate NOV writes is also a recommended "best practice" for TwinCAT. Trying to do it over and over again in a fast task will cause the high CPU usage, as you've already seen.
  Reply With Quote
Old January 19th, 2010, 12:25 PM   #11
FilipN
Member
Belgium

FilipN is offline
 
Join Date: Sep 2009
Location: Knokke-Heist
Posts: 3
i needed to make some inputs and output of Function Blocks remanent so i couldnt use the persistent variable declaration on this one, so i tried the NOVRAM like this...
VAR INPUT
input1 AT %Q : REAL;
END_VAR

so when i rescan my project in the hw manager i get these variables as many times as i have called this function block.
Then i link them to the NOVRAM of the same type and made sure the Init IO is checked.
then i do the restart and still the variables are reset to init value.
For some reason variables inside a function block cant be made remanent.

Somebody must have encountered this problem..?
  Reply With Quote
Old January 19th, 2010, 12:40 PM   #12
Archie
Member
United States

Archie is offline
 
Join Date: May 2002
Location: Orangeburg, SC
Posts: 1,754
Quote:
Originally Posted by FilipN View Post
i needed to make some inputs and output of Function Blocks remanent so i couldnt use the persistent variable declaration on this one, so i tried the NOVRAM like this...
VAR INPUT
input1 AT %Q : REAL;
END_VAR

so when i rescan my project in the hw manager i get these variables as many times as i have called this function block.
Then i link them to the NOVRAM of the same type and made sure the Init IO is checked.
then i do the restart and still the variables are reset to init value.
For some reason variables inside a function block cant be made remanent.
A function block defnition by itself is only a definition and has no place in memory. To use the function block, you declare an instance then the memory is allocated. Every instance has its own memory space, therefore different variable values. When you refer to "calling a function block", you must mean that you are executing unique instances.

To give you a quick solution, try defining an address for the declaration of the instance of the function block. Then link that instance to your NOVRAM.

VAR
fb1 AT %Q0:funcblockdef;
END VAR
__________________
Expectations lead to disappointment. Appreciation leads to satisfaction.

AdvancedHMI - HMI Software without the license key hassles
  Reply With Quote
Old January 19th, 2010, 03:18 PM   #13
SteveMaves
Member
United States

SteveMaves is offline
 
Join Date: Apr 2009
Location: Minneapolis, MN
Posts: 141
Although the compiler will allow you to put Is and Qs in a function block variable declaration, it is not recommended.

Instead, I think you should set up the Is and Qs as Variables in the Calling POU, then pass them as inputs and outputs to the Function Block. That way, you can use the same FB for non-persistant memory, too.
  Reply With Quote
Old January 20th, 2010, 04:25 AM   #14
FilipN
Member
Belgium

FilipN is offline
 
Join Date: Sep 2009
Location: Knokke-Heist
Posts: 3
Thanks for the quick response!
-Archie
That is a quick sollution indeed.

-SteveMaves
i have to make these input and output of some blocks remanent because sometimes a setpoint (in my case an input variable of a FB) is linked to a constant or another variable. But in other (most) cases its written to from the HMI. And my HMI faceplates are based on the function block.

In the meanwhile i made a backup sollution if anyone interests.

VAR_INPUT
var1 AT %Q* : REAL ;
END_VAR
VAR_OUTPUT
var2 AT %Q* : REAL ;
END_VAR

becomes

VAR_INOUT
var1 AT %Q* : REAL ;
var2 AT %Q* : REAL ;
END_VAR

In case a constant is linked to var1 for example there i no problem.
And when the inout parameter is not linked , when operators fill in the value, i can attach the inout parameter to the writetonovram FB wich makes it remanent on reboot.
Another benifit is that with some extra programming u can make it write to NOVRAM , not cyclic, but on change. wich reduces CPU usage.

Last edited by FilipN; January 20th, 2010 at 04:38 AM.
  Reply With Quote
Old February 9th, 2010, 11:48 PM   #15
coa
Member
Thailand

coa is offline
 
coa's Avatar
 
Join Date: Jun 2004
Posts: 96
Hi Archie,

Could you please send your sample code for FB_NovRamReadWriteEx to me.

My mail is coa_eng at yahoo.com

I have application need to save many parameters during power off.
  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
Devicenet Error Code 77 ganutenator LIVE PLC Questions And Answers 22 January 9th, 2014 07:43 AM
how to read more data in a packet by CIP read data service(4C) chenhg LIVE PLC Questions And Answers 0 October 7th, 2008 03:31 AM
Log and retrieve data using PanelView Plus Acano LIVE PLC Questions And Answers 4 February 5th, 2008 10:40 AM
Updating initial values of data block with S7 kemppioy LIVE PLC Questions And Answers 9 June 16th, 2007 02:01 AM
1771-IFE For Dummies Vetteboy LIVE PLC Questions And Answers 5 February 26th, 2003 11:06 AM


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


.