I did that code and I can explain:haiyi911 wrote: ↑Dec 14 2018 10:23amHi，stancecoke
whats the following lines meaning? calculate average? and how to calculate it?
“”ui32_erps_accumulated -= ui32_erps_accumulated >> 3;
ui32_erps_accumulated += ui16_motor_speed_erps;
ui32_erps_filtered = ui32_erps_accumulated >> 3;“”
1. ui32_erps_accumulated = ui32_erps_accumulated - (ui32_erps_accumulated / 8 );
2. ui32_erps_accumulated = ui32_erps_accumulated + ui16_motor_speed_erps;
3. ui32_erps_filtered = ui32_erps_accumulated / 8;
Yes, it is the average using fast shifting register operations -- you know, it is very important to save the very limited processor time.
First we remove 1/8 of the accumulator and then we add our new value, finally the average value is 1/8 of the accumulator.