Code change implements analogReadFast, which reduces the read time of an anolog pin from 112 µS down to 21 µS.

This commit is contained in:
Ken 2019-10-30 15:42:45 -04:00
parent 97296db236
commit eb052133a3
2 changed files with 10 additions and 2 deletions

View file

@ -156,8 +156,8 @@ void loop() {
// Check voltage of first and second stages and compare against thresholds
readVin();
VComp = analogRead(VCOMP_SENSE_PIN);
VFol = analogRead(V_FOLLOW_PIN);
VComp = analogReadFast(VCOMP_SENSE_PIN);
VFol = analogReadFast(V_FOLLOW_PIN);
VLast = VOld - Vin;
if (VLast > Hyst || VLast < -Hyst) {

View file

@ -12,6 +12,14 @@ void digitalWriteFast(uint8_t pin, uint8_t x) {
}
}
int inline analogReadFast(byte ADCpin)
{ byte ADCSRAoriginal = ADCSRA;
ADCSRA = (ADCSRA & B11111000) | 4;
int adc = analogRead(ADCpin);
ADCSRA = ADCSRAoriginal;
return adc;
}
/*------------------------------------------------*/
void pulse() {