Jgoddard91
Hi All,
 
I'm trying to hold the last known value of a channel that I've gated for certain conditions. What's the best method to hold the last known value of a channel?
Reply 0 0
littleozfella
There is a "hold" operator which should hold previous value but I am unsure how to apply it.
Reply 0 0
Jgoddard91
Here we go then:
 
####################################################################################
// function to take the average of a channel and hold the value, filtered by the condition in a0
register @a0;
register @a1;
register @a2;
register @a3;
register @a4;
 
@a0 = (choose([ZeroCondition]>0,1,0));
@a1 = (choose(@a0==1,@a1+1,0));
@a2 = (choose(@a1>=1,(@a2+[FL_DamperPot]),0));
@a3 = (@a2/@a1);
 
// only evaluate the channel if there are more than 20 samples
@a4 = ( choose (@a1>=20 , @a3 , @a4));
 
// show final value
@a4
####################################################################################
 
So therefore, when the "ZeroCondition" is active, a1 will start adding counts per tick., aslong as there is a count in @a1, then @a2 will be itself plus the damper pot channel, if not 0. then @a3 calculates the total value of the channel divided by the number of counts (mean)... then the avg value is only updated when there are enough samples to average - in this case ive chosen 20... this would be application dependant. pretty complicated for a gated mean value!
In my case, i would then take a moving average of this channel, about 300seconds, to then give me the actual gated average... blimey!
Reply 2 0
Reply