You wrote > I need to read 50Hz signal with PIC16F877. Actually, 10-bit accuracy is > enough, but the signal level is unknown, therefore PIC has to adjust to the > signal. The level changes relatively slowly and there is some time allowed > for adjusting. In this case four gain bands (1:2, 1:4, 1:8, 1:16) will do > the job. > > Now, the problem is that I don't want to use variable gain amps, because > they are too expensive and hard to get here, in Ukraine. Another way is to > use analog switches which will change the gain of a usual op amp. Can the > PIC's pins be used as analog switches, connected to ground? The datasheet > says that ports use FETS and that the leakage current is as small sa 1uA. > > I would connect four resistors to PIC and made the pins go low or tri-state. > Will the circuit work? > > __ > -------| + \ > | \ > | >------------- To RA0/AN0 > | / | > ---|-- / | > | ____ | > |-----[_____]---- > --------- > --------- > |---------------- > | | | | > [ ] [ ] [ ] [ ] > [ ] [ ] [ ] [ ] > | | | | > | | | ---------- RA1 > | | --------------- RA2 > | --------------------- RA3 > -------------------------- RA5 > The problems are thus; 1. The signal cannot swing below ground in the present configuration. 2. The noise introduced by connecting the analog signal path to the digital signal path would be seriously detremental to youre 10 bit resolution. SO..... The nicest application I have used was a Light Dependant Resistor that replaced the resistors controlled by the micro thus __ -------| + \ | \ | >------------- To RA0/AN0 | / | ---|-- / | | ____ | |-----[_____]---- --------- --------- | [ ] LDR [ ] | | ___ Agnd A LED shines onto the LDR whose intensity is controlled by your 4 digital control lines, giving 16 levels if you like. The led drive can be decoupled with a suitable capacitor to remove noise from the digital circuit and now you have an unpolluted signal train with common components and digital control. It does work. _____________________________ Lance Allen Technical Officer Uni of Auckland Psych Dept New Zealand www.psych.auckland.ac.nz _____________________________