
Thus, if VREF is higher than 2.5V the chip conducts, sinking current, until VREF is back at 2.5V. The chip is designed to sink current from Cathode to Anode until the voltage at the reference pin is the reference voltage (2.5V). The TL431 has an inbuilt "bandgap" reference, which provides a stable reference voltage. Timer 1 is generating interrupts at 50 kHz: OCR1B = 39 // 20 uS - sampling frequency 50 kHzĪDCSRA = bit (ADEN) | bit (ADIE) | bit (ADIF) // turn ADC on, want interrupt on completionĪDCSRA |= bit (ADPS2) // Prescaler of 16ĪDCSRB = bit (ADTS0) | bit (ADTS2) // Timer/Counter1 Compare Match BĪDCSRA |= bit (ADATE) // turn on automatic triggering TCCR1B = bit (CS11) | bit (WGM12) // CTC, prescaler of 8 A test with analogRead commented out gives a loop overhead of 9052 µs, so to get the true figure we subtract 9052 from the above results, and then divide by 4000 to find the time per reading.
ARDUINO ANALOG PLUS
The time taken is a bit longer than the ADC conversion time (multiplied by 4000 (1000 tests of 4 ports)) but that would be the overhead of storing the results in an array, plus the timer interrupt would have fired a few times. ADCSRA |= bit (ADPS1) | bit (ADPS2) // 64ĪDCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2) // 128įor (int whichPort = lowPort whichPort <= highPort whichPort++)


ADCSRA &= ~(bit (ADPS0) | bit (ADPS1) | bit (ADPS2)) // clear prescaler bits
