I used a running sum for my error, but with the current sum cut down by a % each loop, so that the more recent error has more "weight". You also get the advantage of not having to keep and manage an error array for a time window.
Code:
// Integral control
Integral_Sum = (Integral_Sum *995) / 1000 + Err;
Integral_Counter = (Integral_Counter *995) / 1000 + 1;
Iout = Ki * (Integral_Sum / Integral_Counter);
Using this, every loop the current sum and number of sums is multiplied by 0.995, or cut down a half a percent, then the current sum is added. The average error of the old sum stays the same since the count is reduced too. The current sum gets added while all the old sums get repeatedly reduced.
Sums from 38 loops (1 second) ago to now make up 17% of the running sum.
0.995^38 = 0.827
Sums from 114 loops (3 seconds) ago to now make up 43% of the running sum.
0.995^114 = 0.565
Sums from 191 loops (5 seconds) ago to now make up 62% of the running sum.
0.995^191 = 0.384
Sums from 382 loops (10 seconds) ago make up 85% of the running sum.
0.995^382 = 0.147
Sums from 763 loops (20 seconds) ago make up 98% of the running sum.
0.995^763 = 0.022
You can change the 0.995 to make your running sum more recent or keep older sums more important.
I haven't seen this online anywhere, I don't know what it's called or if it even works yet, but it made sense to me. If anyone sees anything wrong with it let me know.