Search this site (www.microchipC.com).





CCS C Compiler for Microchip PIC micros

Your ad here

 


How do I measure an unknown resistor without using an A/D port?

[taken from PIClist]

[Ed.] This method is excellent for a low-accuracy, cheap way of measuring
resistance, perhaps from an external pot. Note that the timing results returned
are non-linear, as expected from capacitor charging time.


> Yes with a PIC you can use a capacitor and a resistor and one PIC pin, plus
> your unknown resistor. Don't know why I am the first to suggest it this
> way, it is the simplest tried-and-true method.
>
> Use any PIC pin on port B or any pin except RA4 on port A.
>
> 220 ohm resistor from the PIC to the capacitor. Other end of the cap to
> ground. Attach your mystery resistor from the cap to + supply voltage.
>
> Make the pin an output and make it low for a good long time, say 1 to 10
> milliseconds, so you know the cap is as close to ground as it's going to get.
>
> Then make the pin an input and time how long it takes to change from a 0 to
> a 1. Longer time = higher resistance.
>
> Rinse, and repeat as neccessary.
>
> The cap value depends on your resistor and your timing loop. This method
> does not work for very small resistor values(the 220 ohms protects the PIC
> pin from a capacitive load but also limits the lowest resistance you can
> measure.
>
> Repeatability is about +-2 percent.
>
> Cheerful regards,
>
> Bob Blick [bblick@SABER.NET]

> -----Original Message-----
> From: pic microcontroller discussion list
> [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Peter L. Peres
> Sent: Tuesday, 1 May 2001 7:35 a.m.
> To: PICLIST@MITVMA.MIT.EDU
> Subject: Re: [EE]: How to convert Resistance to digital data directly
>
>
> > It appears that the low threshold voltage is jittering, but sometimes
> > it's practically at ZERO, and that makes no sense at all. I can't
> > believe that my little 2 instruction loop is introducing any real
> > latency. A couple of counts, yes, but that's why I am using a 16 bit
> > measurement on the discharge time, and a large-ish 8 bit "1" value.
>
> Any interrupts turned on by chance ?
>
> I use code like:
>
> loop:
> movlw SET_OUTPUT_1
> movwf OUTPUT
> btfss INPUT.BIT
> goto $-1
>
> goto $+1 ;; compensate jump timing
>
> ;; optional delay here
>
> movlw SET_OUTPUT_0
> movwf OUTPUT
> btfsc INPUT.BIT
> goto $-1
>
> ;; optional delay here
>
> goto loop
>
> to test RC circuits on 'new' configurations. The output is a scope probe
> and a counter (slaved to scope X1 channel). This will not detect jitter
> that averages out but it's pretty good for getting in the 'ballpark' for
> the counter value(s) quickly. NOTE that I always do this with a Schmitt
> input. An extra fixed period of pushing high and low may be required after
> the detected transition if not. After collecting some values and heat
> cycling I get a workable code based on this in 3 tries or so. A test
> circuit based on this is also handy when examining parts for building a
> set of devices based on such principles.
>
> good luck,
>
> Peter L. Peres [plp@ACTCOM.CO.IL]



This site is non-profit. Ad revenue almost covers hosting costs.

We welcome any suggesions or comments! Send them to Shane Tolmie on support@microchipc.com. This site is a completely separate site to www.microchip.com, and is maintained independently of Microchip Ltd., manufacturers of the PIC micro. All code on this site is free for non-commercial use, unless stated otherwise. Commercial use normally free, however, it is prohibited without contacting support@microchipc.com for permission. All content on this site created by Shane Tolmie is copyrighted by Shane Tolmie 1999-2009. Click to advertise on this website - $29.90 for a banner ad which will reach 55,000 user sessions per month. One months free trial!