Component tester : Capacitor
The charge curve of a capacitor is Vc=Vcc*(1-exp(-t/RC)) The idea is to charge the capacitor up to ~ 70% and look how much time it took The formula is then inverted to : C= -t/R*(ln(1-ADC/4095) The problem is C can go from 1pF to 400 uF, that's a 400000000 factor So what we will do is charge up to 10% using the 20 k resistor and lookup how much time it took Depending on the result, we'll select the right resistance and do it again. That initial sampling does not need to be accurate, it's just to select the right resistor. The idea is we aim at a charge time of ~ 200 ms so the errors are neglectable. For mid values and high values capacitor that works fine (C above ~200 pF or so) We poll the ADC with slow sampling period until we get over ~ 70% and compute the capacitance value from there. It does not need to be exactly 70% since we have the matching ADC value. The limit is here is the sampling period is a few us, which is fine if R*C is big comp...