
adccommunitymod (AutomationDirect) asked a question.
Created Date: September 25,2008
Created By: jondecker76
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
I'm using a DL05 to capture windspeed. I want to use a historical trend of the windspeed on a cmore micro. Because there is a limit of 24 points on the x-axis, and I want to trend the last 24 hours, this means I must update a table in vmemory every 60 minutes. Ok, this is easy enough so far, and I have it working with no problems. However, problem I am having is this: Taking the current windspeed reading only once an hour to display on the trend does not show a very true representation of what the average windspeed was for that hour. (For example, what if the wind was blowing 20MPH for most of that hour, but when I updated the table it was only blowing 5 MPH - this would not accurately represent the wind conditions for that hour.) So the next thing I tried is keeping a running average for the current hour. However, it seems that my DL05 doesn't support negative numbers, so this has become hard. I was trying to use the formula each second: average_windspeed = average_windspeed + (current_windspeed - average_windspeed/iterations) It works if the current_windspeed is greater than the average_windspeed, but does not work if the average_windspeed is greater than the current_windspeed. I'm guessing this is because current_windspeed and average_windspeed are BCD numbers. Then I tried converting everything to binary numbers before doing the math and it still does not work as expected. - so it looks like it gets thrown off if any part of the math produces a negative number... Is there a way around this?? For reference, here is a sample of how I'm calculating the average (i'm testing the theory by updating the average every second, then updating the historical data table every minute instead of every hour): Also, in case you are wondering, I chose this method of calculating the running average in real time because I plan on using the same technique for trending average windmill alternator RPM per hour (up to just a bit over 1800 RPM). So I can't just keep adding the current RPM every second and then divide by 60 in the end - as 1800 * 60 would be too large for the 16 bit address space. Though I am open to other options! v2000 = current windspeed, updated every second v2030 = running average windspeed, which I will attempt to keep updated v5000-v5030 = historical trend table - SP4----------( PD C10 ) //the following is used to represent a counter. It shows the enable and reset inputs... - C10----------X CT10 X - SP1----------X K60 X - C10-----------LD V2000 //Load the current windspeed sub v2030 //Subtract the running average div CTA10 //divide the iterations add v2030 //and add in the original running average out v2030 //place our new running average into v2030 - CT10-----------LD K24 //60 seconds has passed so lets update the table //(24 table slots) LDA O5000 //load in hex equivalent of address v5000 mov v4777 //shift the entire table "left " by one ld v2030 //load in the running average out v5030 //and put it in the last table entry (rst)CT10 //reset the counter for next time --Sorry about the formatting - somebody needs to fix the CODE tags on the forum to use a fixed-width font! thanks for any advice
Created Date: September 26,2008
Created by: AZRoger
Consider a DL06
You seem to be constantly banging your head into limitations of the DL05. I'd revisit that decision and consider the DL06.
You need relatively few input and output points. However, you have lots of computational complexity.
The DL06 meets these requirements very well and costs maybe $100 more than the DL05 depending on your exact I/O requirements.
The DL06 would give you, in the minimum configurations, enough inputs and outputs to handle 2 or 3 times as many generators.
And you get actual floating point math. This will simplify implemention of most of the future things you talk about. It makes moving averages easy.
IMHO, if your time (and sanity) is worth anything at all, you'll be way ahead with a DL06.
You should be focusing your time on getting wind energy to the grid and not struggling to do relatively simple things the hard way. :)
Roger
Created Date: September 26,2008
Created by: franji1
How can you have a negative speed? Are you actually measuring velocity, based on a direction (i.e. sign shows direction)? So you could have 100MPH winds for 30 minutes, then 100 MPH winds in the opposite direction for 30 minutes, and you actually want to display average VELOCITY of 0MPH, the same as having absolutely no wind at all for 60 minutes?
Please explain the purpose of "negative numbers " when dealing with "speed "?
Created Date: September 26,2008
Created by: jondecker76
Thanks for the advice!
I totally agree - I need to upgrade to the DL06. However, I have 4 DL05 PLCs, so I'm going to try get a simple version running on it, then upgrade to the DL06, port things over and then add the advanced features. So I think you 're right - I need to keep this first version for the DL05 simple, so I guess the thing to do would be to eliminate the un-needed bells and whistles and work on getting it running.
thanks for your input
Created Date: September 26,2008
Created by: jondecker76
franji1:
I wasn't talking about measuring negative windspeed.. Its just that a negative number can result in the math while calculating a running average windspeed - causing unwanted results. Look at the formula i my original post and you'll see that if the current windspeed is less than the running average, a negative number can happen during the calculation.
switching to the DL06 seems to be my best option in the long run
Created Date: September 26,2008
Created by: KPrice
jondecker76, we did a similar project. Say you want a running average of sixty readings taken every second. Use a one-shot to load the 1st speed (20 for example) into the 1st V-memory of 60 V locations, V2000 for example. (Initially you may want to fill the 60 V-memory with the 1st speed so you won't have (1) 20mph and 59 zeros for the first minute.) (Without the FILL instruction, you have to use LD, OUTD.) Your starting total is 1200. Then divide by 6 to get your running average of 200 with 1 implied decimal point.
MOV the table of 60 to the 2nd V-memory, V2001. Then at the next reading, add the current reading to the total, subtract V2074 (the last reading that was MOVed out of the table), OUT this to update total, divide by 6, OUT this to update the running average. (depending on how many readings you may need to OUTD the total.)
This rung is executed every second to keep the running average.
Does this make sense?
Created Date: September 26,2008
Created by: jondecker76
Thanks for sharing your method. Yes, it makes sense, and I was thinking aobut trying something similar. I'm going to try a few more simpler methods first, as my goal is to remain under 10 ms scan time and I'm already up to 8 ms.
Created Date: September 26,2008
Created by: franji1
If you are keeping a running average, you can maintain a DOUBLE BCD value representing the sum, and then the current number of samples. No need for algebraic shenanigans trying to do all the math in 16 bits.
Say V1400/V14001 has the current SUM, the math is just
STR C10 // one-shot once a second
LDD V1400
ADD V2000 // current speed
OUTD V1400 // maintain the sum in V1400
DIV CTA10 // divide by n samples; accumulator still has 32 but running sum
OUT V2030 // output the average
OR, the FILTER IBOX does similar to what you are doing, all wrapped up in a nice single instruction.
But you will get more precise results if you MAINTAIN a RUNNING SUM, and then CALCULATE the RUNNING AVERAGE.
Created Date: September 26,2008
Created by: jondecker76
Wow, I didn't even think of checking the IBoxes - thanks for the tip!
Didn't think of using 32-bit doubles either.. A much simpler solution, thanks!
Created Date: September 26,2008
Created by: jondecker76
I'm not sure if I completely understand the Filter IBox.. Can you give me an example of the Filter IBox usage? Lets say I want to keep track of the average windspeed over the course of one hour, assuming that the current windspeed is in v2000 (it is updated every second), and I want the average to be placed in v3000 and updated each minute..
thanks
Created Date: September 26,2008
Created by: Tubecut
AZroger: "I'd revisit that decision and consider the DL06. "
Sometimes the PLC foot print is a defining factor and going to the DL06 can make or break the application due to the size limitation. Retooling for size would be a major issue.