A ten turn pot used for RV1 (Figure 8 Guessing Game Schematic) with the wiper to pin PC0, with this voltage measured by a voltmeter and set to 2.50 volts and used for the set value. Then, changing the pot to approximately 3.2 volts and slowly backing it down, guessing frequently, both LEDs flash for a correct answer around 2.7 volts. Same thing but coming up from about 1.8 volts, a voltage of about 2.3 volts gets in the correct range.
These results are repeatable, within about 10 - 15 mV.
However, if that single line of code is commented out so the ADC clock is 16 MHz, then every single guess is correct, even when the pot is rotated fully to either end of its range, i.e. 0 or 5V for a guess against the 2.5V setting. If the set value is ground or Vcc, even then any guess is always right.
I don't know what noisy ADC value is being saved for the set and for the guess but I assumed that they would sometimes be different, and the guess would be either too high or too low. Maybe I did't try enough times?
Nevertheless, it is clear that the ADC clock must be slowed down.
Code: Select all
ADCSRA = (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); //Clock Prescaler: 128, allow for accurate (>50kHz <200kHz) sampling with 16MHz system clock