![]() LastSampleTime += SampleIntervalMicroseconds ![]() SampleIndex = (SampleIndex + 1) % SampleCount įor (unsigned i = 0 i = SampleIntervalMicroseconds) This is only done once per sample interval SampleTotal -= Samples // Remove the value falling out of the buffer You need these three line for each value being sampled Return 1.0 // Put your sensor reading code here You only need one set of these for all values You need a set of these for each value to be averaged Let's make the averaging time one secondĬonst unsigned SampleCount = ACLineFrequency * SamplesPerACCycle Ĭonst unsigned long SampleIntervalMicroseconds = 1000000UL / SampleCount const unsigned ACLineFrequency = 60 Ĭonst unsigned SamplesPerACCycle = 2 // We take two samples, 180° out of phase, during each AC cycle I would sample at half the local AC frequency to try to avoid any AC hum. Instead of taking an average of three measurements very close together you might be better served with a longer term moving average.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |