Searching \ for 'PIC versions of RCTIME vs POT (long reply)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'PIC versions of RCTIME vs POT (long reply)'.

Truncated match.
PICList Thread
'PIC versions of RCTIME vs POT (long reply)'
1999\03\25@082239 by Quentin

flavicon
face
After getting good tips from the list before, I guess it's time to share
one of my designs with the list.
This circuit will ensure stable readings even when you have tolerance
variances in RC values.
Stable pot value with PIC:
RA0 -----------|
              |
              >
              <
RA1 ---------->> 100K pot (see notes)
              <
              >
              |
      50ohm   |
RA2 ---/\/\/\--|
              |
             ____
             ____ 0.1 microF Cap (see notes)
              |
              |
              |
             ___ GND

Not shown: 1n4148 diode going to positive to discharge Cap when power
down.

Principal of operation:
1. Power up PIC. RA are all outputs and set low. Delay for a while to
ensure cap is discharged.
2. RA2 and RA1 tris input. RA0 set high. Read max value. Cap is charging
through POT at max resistance. Counter run while RA2 is low. When RA2 go
high, stop count, RA0 go low, RA2 tris output and set low. Short delay
(discharge cycle), RA2 tris input, check discharged? If not repeat
discharge cycle.
Code example (subroutines):
res1    equ     PORTA,0 ;RA0
res2    equ     PORTA,1 ;RA1
CAP     equ     PORTA,2 :RA2

GETVAL      CLRF        VAL             ;max value
GETVAL1     BTFSC       GPIO,CAP        ;GPIO for 12Cxxx, PortA for 16Cxxx
           GOTO        DONE
           INCFSZ      VAL,F           ;check for counter overrun
           GOTO        GETVAL1
           DECF        VAL,F           ;if overflow set to 255
DONE        BCF         GPIO,RESCAL
           MOVLW       B'001000'
           TRIS        GPIO
           BCF         GPIO,CAP        ;discharge cycle
           NOP
           NOP
           MOVLW       B'011000'
           TRIS        GPIO
           NOP
           BTFSC       GPIO,CAP        ;discharged?
           GOTO        DONE
           MOVLW       B'001000'       ;always keep CAP low when not in use
           TRIS        GPIO
           BCF         GPIO,CAP
           RETLW       0

3. Read POT value. RA2 and RA0 tris input. RA1 set high. Read set value.
Cap is charging through POT wiper. While RA2 is still low, decrease max
value that was read in 2 above until RA2 goes high (note: value reads in
reverse). Rest same as above.

Code:
GETVAL11    MOVF        VAL,W
           MOVWF       VALLO
GETVAL12    BTFSC       GPIO,CAP
           GOTO        DONE1
           DECFSZ      VALLO,F         ;POT value, check for overflow
           GOTO        GETVAL12
           INCF        VALLO,F         ;if overflow, set to 1
DONE1       BCF         GPIO,RES1
           MOVLW       B'001000'       ;discharge
           TRIS        GPIO
           BCF         GPIO,CAP
           NOP
           NOP
           MOVLW       B'011000'
           TRIS        GPIO
           NOP
           BTFSC       GPIO,CAP        ;discharged?
           GOTO        DONE1
           MOVLW       B'001000'
           TRIS        GPIO
           BCF         GPIO,CAP
           RETLW       0

Notes:
Select RC according to PIC frequency used (see formula in AN512 for an
idea). Try to get a close match. However this circuit ensures that you
have a max reference to work from as long as it does not overflow the
counter.
Maximum value can only be read once, if you wish, at start of program.

Hope this help somebody. I use this all the time.

Quentin

1999\03\25@105150 by Ross Bencina

flavicon
face
Quentin wrote:

>After getting good tips from the list before, I guess it's time to share
>one of my designs with the list.
>This circuit will ensure stable readings even when you have tolerance
>variances in RC values.
[snip]

Thanks Quentin, this is useful and may help me work out the other circuits I
have seen. However I am looking for a 1 pin per pot solution.

Ross.

1999\03\25@110436 by Quentin

flavicon
face
Ross Bencina wrote:
>

> Thanks Quentin, this is useful and may help me work out the other circuits I
> have seen. However I am looking for a 1 pin per pot solution.
>
> Ross.
Yup, you can use 1 pin. In my previous post, connect the wiper to the
Cap as well and use the first code example. This is how I started, but
I've found I got a lot of instability especially when I read on the high
or low ends of the Pot. No two readings were the same.


Quentin

1999\03\29@093938 by Lawrence Lile

flavicon
face
Neat stuff, Quentin.   If I understand it, you count up to get the maximum
value of the whole potentiometer, then count down to get the value at the
wiper position.

Two questions:

1.  You seem to be using a port, not a TMRO input, to check the value of the
capacitor.  When I've tried this I get variations from part to part due to
variations in Vih specs on the input.  I understand the schmidt trigger
input of the TMRO is more consistent.  It also seems to trip at a higher
voltage - about .85 Vss.  Do you think so?

2.  I understand the counting up and counting down, and it looks like it
might work.  I'm trying to understand how this compensates for variations
from part to part.  Given, say a nominal 100K potentiometer, which may run
from 80K to 120K.  Let's say they are all set at 50%.  The 80K times out in,
say 254.  So 50% wiper position would give us a wiper reading of 127.  The
120K would time out proportionally in 169 counts or so.  At 50% wiper
position it would read  84 counts.  Do I understand this right?





-----Original Message-----
From: Quentin <spam_OUTqscTakeThisOuTspamicon.co.za>
To: .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU <PICLISTspamKILLspamMITVMA.MIT.EDU>
Date: Thursday, March 25, 1999 7:22 AM
Subject: Re: PIC versions of RCTIME vs POT (long reply)


>After getting good tips from the list before, I guess it's time to share
>one of my designs with the list.
>This circuit will ensure stable readings even when you have tolerance
>variances in RC values.

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...