01-31-2018 06:38 AM
Hi everyone,
I am working on a piece of code for some time now, which still isn't exactly doing what I want. I am working on a control system that is to be uploaded to a CompactRIO in scan mode. For this control system I am using a capacitive displacement sensor that gives values between 0 and 10V, corresponding to an absolute displacement (between 0 and 800 um) from the sensor head.
Before I close the control loop, I want to press a button on the front panel and subtract an average of a number of samples from the signal, so it will be 0 m. Because there is some noise on the sensor signal, I want to take an average of say 100 samples. This average has to be computed after the button is pushed.
I have been working on a dummy program (attached). The sensor signal is simulated by using a random number between ±0.5 for noise above a displacement of 400 um. I am using a for loop inside a case structure to start counting until 100 samples to compute the average. The average is saved to a local variable, which is subtracted from the signal+noise. The code is doing what I want the first time I press the button, although I am not sure if the average is taken over 100 samples. When the button is pushed again, also values from the previous time the button is pushed are used in the average, while this is not what I want.
Can someone give me a good idea to change the code to get this presumably easy problem solved? Or are there simpler ways to solve this? Thanks in advance
Solved! Go to Solution.
01-31-2018 07:04 AM
01-31-2018 09:06 AM
Works exactly the way I want it to, thanks!