Expression for calculating two input data


asaikk

Recommended Posts

In the case where two data are read on two channels (ex. MyChannel_1, MyChannel_2) respectively,

Where should I put the expression for calculation of two data such as below?

MySum = MyChannel_1[0]+MyChannel_2[0]

Can I put it on Either of the two channels, or should I make a sequence?

And how should I declare "MySum", private, public or global?

Link to comment
Share on other sites

Technically you can't use the event for the channels because you don't know which will be read first, so you probably have to put it in a sequence. The other question is why you even bother to create another variable, unless you want to log the sum (and then you'd need another channel, not a variable). You can access the sum at any time by doing:

myChannel_1[0] + MyChannel_2[0]

wherever you want the sum of the most recent readings. If you want to graph the sum, drop the [0]'s from above.

As for your other question, there is no "public" variable type, just private and global, and you'd most likely want global. Private would only be accessible in your sequence.

Link to comment
Share on other sites

  • 5 months later...

How does this change if your data is being streamed in the two channels? I'm streaming data from a duty cycle measurement using Timer0. Rather than logging the MSW and LSW on two channels and then processing the data later, I'd like to calculate the duty cycle as the data is being captured and then only log the calculated duty cycle value. Any suggestions?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.