- if(adc_state==1)
- {
- // Convert to milliamps: (v*5/1024-2.5)*1000/0.185
- if(value<512) // Ignore negative current readings
- value = 0;
- else if(value>663) // Limit range so averaging won't overflow
- value = 4000;
- else
- value = (value-512)*132/5;
-
- uint8_t i = track_current_head;
- track_current_sum -= track_current_samples[i];
- track_current_samples[i] = value;
- track_current_sum += value;
- track_current_head = (i+1)&15;
- }
- else if(adc_state==3)
+ uint16_t value = track_current_sum;
+
+ // Convert to milliamps: (v/16*5/1024-2.5)*1000/0.185
+ if(value<8192) // Ignore negative current readings
+ return 0;
+ else