LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use of the circular buffer for the calculation of the average of a current

Solved!
Go to solution

Hello,

 

I am working on a project to estimate the state of charge of the batteries using the coulomb counting algorithm.

I want to acquire the input and the output currents of the batteries and then calculate the mean of this current continuously during 60 seconds using the circular buffer.

I tried first to write and read data from the buffer but I get an error "Error -5011 occurred at Circular Buffer.lvlib:Circular Buffer(2D DBL).vi … Possible reason(s): Attempted to write data to buffer outside of configured bounds."

For now, the mean is done using a shift register as shown in the attached file.

Would you have any idea how should I proceed?

 

Thank you.

PS. I am using LabView 2014

0 Kudos
Message 1 of 30
(5,475 Views)

You did not attach the subVI. Is that from a toolkit?

 

Why not just use "mean ptbypt"?

 

Your array building is also faulty.

  • You need to initialize with an empty array, not with an array containg a zero.
  • "built array" is better than "insert into array".
  • Your array grows forever and ultimately you will run out of memory.
  • Your small "built array" makes no difference.
  • The use of a local variables is inefficient and causes race conditions. The I-battery terminal belongs in the main loop. You can branch to all the locations where it is needed.

 

0 Kudos
Message 2 of 30
(5,463 Views)

Thank you for your quick reply and for your remarks.

 

Actually, it is part of a real time application which will be implemented on a compact RIO. I had an exchange with an NI Engineer who advised me to use this circular buffer instead.

I have no idea if “mean ptbypt” is sufficient for real time application.

 

Indeed, the local variables are inefficient and will be replaced by shared variables.

 

The subVI can be downloaded from http://www.ni.com/example/30883/en/ (once it is installed, you can find in user libraries)

 

Thank you.

 

0 Kudos
Message 3 of 30
(5,450 Views)

There are several very important points that you don't seem to have grasped about this library.

The buffer itself is functionally a pre-designed AE (Action Engine), So that you don't have to run anything between the different instances of the buffer functionality.

 

See the snippet I have included below for functionality, if you need more information have a look at the examples that are included with the library, although they are all DAQ it should be pretty easy to convert across to a user array.

 

buffer.png

0 Kudos
Message 4 of 30
(5,409 Views)
Solution
Accepted by topic author lucdu39

@lucdu39 wrote:

 

Actually, it is part of a real time application which will be implemented on a compact RIO. I had an exchange with an NI Engineer who advised me to use this circular buffer instead.

I have no idea if “mean ptbypt” is sufficient for real time application.

 


To average the last N points, you don't need a "circular buffer" because the order of  elements does not matter. Also an AE implementation is a bit limiting, because you can only have one such circular buffer per project. Sometimes you need more. I am not going to install that thing just to look at the code. Is the VI available standalone somewhere?

 

Mean ptbypt is quite efficient and I would think it should run on RT. Are you planning to do the averaging on FPGA?

 

Are you planning to change the history size during the run? How big is the history size? From your initial question, there is only one channel (Current, singular), but then you also say input and output currents (plural). Are these two channels, both to be averaged?

 

A comparison of several ways to do such averaging are discussed in our NI-Week talk of 2016. These methods can easily be expanded for multiple channels (example).

 

 

0 Kudos
Message 5 of 30
(5,369 Views)

Thanks for the clarification.

 

I have not yet created the standalone code.

 

For my application, I will just use the LabView scan engine.

 

I want to average 60 samples (fixed size) after one minute, the input and the output battery current are one channel. I think now, I have an idea how I should proceed.

 

I will try the averaging on RT using the ptbypt.

 

Thank you

 

0 Kudos
Message 6 of 30
(5,331 Views)

Hi, Can you post the final solution. I am working on solar project. I am new to labview. I am taking temperature readings every 1 second. I want to average out every 60 samples and store only this average number so that I will have one average reading every one minute. You question seams to be similar.

 

It will be very helpful if you could post the final code you used.

 

Thank you.

0 Kudos
Message 7 of 30
(4,788 Views)

Hi desireddy,

 

use PtByPt-Mean, set to average 60 samples.

In your loop you only stored once each 60 iterations: you will need a case structure and a Quotient&Remainder function to do so…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 30
(4,783 Views)

Hi Sir,

Thank you for prompt reply.

I made the following code based on your suggestion. Correct me if I am wrong.

Also, I would Like to ask one more question. How to store the time (real clock time) along with the stored average value.? Since I am working in solar project, I want to show the time (like 9 am to 4 pm) on x axis and the averaged values minute by minute on y axis.

Thank you

0 Kudos
Message 9 of 30
(4,775 Views)

Use Get Date/Time In Seconds to get a timestamp and then Build Waveform to put your timestamp and data together.  You might want to have a quick look at this nugget: Sporadic Waveform Chart


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 30
(4,770 Views)