On Mon, 30 Apr 2001, Russell McMahon wrote: > What sort of caps are you using? > Presumably Mylar or similar rather than eg ceramic. > > Does transferring this from the ICE to a "real" PIC produce an identical > result? > > Presumably when you say "non-linearity" you mean non linear compared to an > exponential curve. > > Might it help to eg go low, then high, and time for say 5 time constants > after the low to high transition and then go low again and count the time > taken? That way, even though the 5 time constants "should" pretty much have > the cap at top rail, driving it there for a consistent period after it > passes through low-high threshold may reduce variability. Good points. I'm curious how this "2-instruction loop" is implemented. How can this be done AND count the number of cycles? I know one way, but from the context I'm sure that's not being done. To achieve the +/- 2% repeatibility to which Bob alludes you'll have to be extremely careful in keeping track of ALL cycles and ALL voltages. First the voltages: you've got ground, Vcc, and the two switching thresholds of the I/O pin (the low-to-high and the high-to-low). Others here have more experience than me with the PIC I/O thresholds. But one thing I'd comment on is that the thresholds are sensitive to variations in Vcc. If the sensitivity is linear then this approach is ratiometric. But, I don't know how the input thresholds vary. It'd be instructive to create a simple program to measure the input voltage thresholds: l1: bcf ioport, bitx ; The ioport we'll monitor l2: btfss ioport, bity ; the ioport/bit we'll test goto l1 bsf ioport, bitx goto l2 Attach a variable power supply (or a the wiper of a pot) to the ioport you wish test. Run this program and monitor the other I/O pin. This will give you a good idea of the thresholds at a given vcc. In your lab notebook, you may wish to record the results for a few different Vcc's (e.g. 4.5, 4.75, 5.0, 5.25 etc) ----------------- Now, the algorithm I'd take is this: 1) Charge the cap. You can either do this through your unknown resistor or tie the cap to another I/O pin that can quickly charge the cap. The latter makes more sense since you can use the "discharge" I/O as your input to monitor the capacitor voltage, so I'll assume that in what follows. Eg: | PIC I/O +----+------------+ | | | | | / | === C Ref \ R unknown | | / | | | --- --- /// /// 2) Begin charging the cap. Make sure it's fully charged! The pic I/O pin has fairly low output impedance, so should charge the cap in a much shorter time than your unknown resistor. 3) At the same time you change the output pin that was charging the cap to an input, start a timer. Note that the I/O pin that was charging the cap is now monitoring the cap's voltage. 4) When the PIC I/O goes low, stop the timer. ------ Sounds easy enough. But to get repeatable results you'll need an accurate counter. I don't know which PIC you're using. If you're using one with the Timer 1 peripheral (like the F877) then the timer is trivial. If you're confined to the '84 then you'll probably want to grab my 3-instruction cycle resolution software pulse width measurer. It's part of the gpsim distribution and can be found in CVS: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/gpsim/examples/14bit/ the file is pulse_measure.asm Scott -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body