At 10:08 01/07/1997 +0100, you wrote: >Wayud wrote: >> Could some one give me better explanation or another method about >> using OP AMP and timer module to implement A/D converter..? I've read >> the app note from microchip, but I still don't get it... (I'm too >> dumb.) Here a simple schematic: |\ R1 | \ Port output(P1)__/\/\_ Vin ______|+ \____ Port Input for CHARGE R2 |_______________| / or Timer gate Port output(P2)__/\/\_| | |-/ for discharge cap --- |/ --- | ground Purpose is to make a "simple" AD converter using a TIMER. Principle is based on charge(via R1)/discharge(via R2) of a capacitor and then comparing the cap-voltage to the Vin input. Step to achive a convertion are as follow: - set P1 to Hi-Z (input), - set P2 to output, and to "0" in order to discharge the cap7 - reset the TIMER (prepare Timer pin to handle correct polarity) - set P1 to output, set P1 to "0" - set P2 to Hi-Z (input), - set P1 to "1", the capacitor begin to charge throught R1 - as soon as Timer pin as changed, memorize TIMER value - set P1 to "0", - set P2 to output, set P2 to "0" in order to discharge the capacitor. The following formula give the relation between the time needed to charge the capacitor and the input voltage: T = - R1.C. ln (1 - Vin/Vcc) with: R1: the Resistor value C : the cap value in Farad, Vin: the input voltage to measure Vcc: the maximum voltage level of the port-pin P1 R2 is needed to prevent port destruction with a high current discharge for exemple: R1 = 100K R2 = 100 C = 100nF Note if discharge time is not critical, you can use only one port pin to make charge and discharge. This method is simple but not so accurate because of logarithm conversion. Input voltage is not proportionnal to measured time. A better approach is to charge the cap. with a current generator, this authorized a linear conversion as time will be proportionnal to Vin. Current generator can be made as follow: using a zener Diode Vz, a PNP transistor Vcc Vcc _|__ | Vz /\ | /__\ _ |/E |__| |\______ | C / \ R Port pin ___ / Vz fix a constant VBE voltage to the PNP transistor which fix a collector current which will be constant. Then to active the current generator, put "0" on the port pin. With a constant current charge, formula become: T = Vin. C/I0 For code implementation, there is no special problem if you understand the A/D principle. Note this kind of technic is not very precize due to: - TIME quantification that timer will do - Voltage imprecision on port pin output, Vcc dependent - Discharge which will be not totaly complete But if you need only to know an average of a value, it is sure better than a simple comparator which will give only TRUE/FALSE. Hope this will help all people who try to implement such A/D converter Best regards, Philippe TECHER. +--------------------------------------------------------+ | Virtual Micro Design | | | | UMPS: The universal microcontroller simulator | | | | E-Mail: p.techer@idls.izarbel.tm.fr | | URL: http://idls.izarbel.tm.fr/entp/techer | | or http://sistudio.com/umps | +--------------------------------------------------------+