Jose76

CJ - Adding several consecutive floating points

7 posts in this topic

Hi everybody!

I have several REAL data stored in consecutive addresses, for example, in D100, D102, D104,..., D110 and I want to sum it all and store it in another address, for example, on D200, but I haven't find an elegant way to do it.

In fact, I need a SUM(184) instruction but, for floating point instead of byte.

Can you help me?

Thank you!

Share this post


Link to post
Share on other sites

How big is your range of floating point numbers? Do they need to be added every scan? 

D100 - D110 is only 5 floating point registers. Easily done with 4 +F(454) floating point additions. You won't get any more efficient than that. However if you were adding 10 or more  consecutive registers you may want to look at pointers/indirect addressing. Then you can choose if they are all added in 1 scan with a "FOR" loop or over consecutive scans.

Share this post


Link to post
Share on other sites

Instruction "+F"

And you can do an array and sum them using FOR. Or indirect addressing. 

Share this post


Link to post
Share on other sites

I would do a Structure Text FB.

Share this post


Link to post
Share on other sites

Sorry for the delay, I was suppossed to receive an email when an answer was received ...

I'm about to add 10-20 numbers. I've been thinking about a indirect addresing and a FOR instruction, but I don't know how to use indirect addressing neither with contacts or structured text. In fact, I haven´t been able to write the @ symbol in the arguments of a +F instruction and don't knwo why.

Can you write a little example on how to do any of these?

Thank you!

Share this post


Link to post
Share on other sites

Here is summing D10 to D50 (20 floating point values)

 

The way I did it requires 1 extra loop hence the 21 in the FOR loop because I increment the index after adding. You may write yours differently.

cap1.PNG

CAP3.PNG

cap4.PNG

Share this post


Link to post
Share on other sites

In my opinion, 20 instructions do not worth organizing a loop, not to mention FB.
Configure the output instructions to be shown horizontally, and 19-instruction rung will be of reasonable size.
And each register value will be on the screen for immediate monitoring.

Edited by Sergei Troizky

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now