Searching \ for 'Q: Code for simple A/D one pin 16F84?' 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/ios.htm?key=a%2Fd
Search entire site for: 'Q: Code for simple A/D one pin 16F84?'.

Truncated match.
PICList Thread
'Q: Code for simple A/D one pin 16F84?'
1998\07\23@215448 by James Cameron

picon face
Looking for code that will give me a simple A/D conversion for use on
a PWM lamp brightness control.  No linearity required.  Seven or eight
bits.

Hardware would be a 10k variable resistor to a 0.1uF cap to ground.

I've had a look at the Scott Edwards book, the section on "pot", but I
don't understand the mnemonics there.

I'm sure I could write it myself, but that's another couple of hours at
my experience level.  ;-}

--
James Cameron                              (spam_OUTjames.cameronTakeThisOuTspamdigital.com)
Digital Equipment Corporation (Australia) Pty. Ltd. A.C.N. 000 446 800

1998\07\24@030146 by Dr. Imre Bartfai

flavicon
face
Hi,
if you want to measure a resistor, use the AN 512. A lot of topics is
written before. I tried it and works fine. (It needs three pins, however,
and one of them MUST be the RA4, due to its Schmitt-trigger input.)

Good luck:
Imre


On Fri, 24 Jul 1998, James Cameron wrote:

{Quote hidden}

1998\07\24@081741 by paulb

flavicon
face
Hello James.

> I've had a look at the Scott Edwards book, the section on "pot", but I
> don't understand the mnemonics there.

 Oh dear, let me try...  Untested code, review before use!

; POT
; This program shows a technique for reading resistance. The pot input
; pin can only be changed during assembly, not once the program is
; running.
       cblock  8
       temp:1          ; Temporary counter for delay.
       potL:1          ; Low byte of Pot measurement.
       potH:1          ; High byte of Pot measurement.
; forgot mnemonic for end of cblock...

#define pot     ra,0    ; Pin assigned to pot.
#define out_pot 0       ; Value to set ra.0 to output for pot.
#define in_pot  1       ; Value to set ra.0 to input for pot.

; not sure on these:
       device  pic16c55,xt_osc,wdt_off,protect_off
       reset   start

mov     macro   dest,val
       movlw   val
       movwf   dest,f
       endm

djnz    macro   reg,dest
       decfsz  reg,f
       goto    dest
       endm

       org     0
start   bsf     status,rp0
       mov     ra,out_pot      ; RA.0 to output.
       mov     rb,0            ; All outputs for LEDs.
       bcf     status,rp0
       bsf     pot             ; Start charging cap.
       mov     potL,8          ; Set up for 6-ms delay: 8 trips
wait    djnz    temp,wait       ; through outside loop x 256
       djnz    potL,wait       ; x 3 cycles for inside loop = 6.1 ms.
       clrf    potL
       clrf    potH
       bsf     status,rp0
       mov     ra,in_pot       ; Get input from pot.
       bcf     status,rp0
       bcf     pot             ; Clear output latch for pot bit.
loop    btfss   pot             ; IF pot = 0
       goto    done            ;  THEN done
       bsf     status,rp0
       mov     ra,out_pot      ; Discharge cap a little.
       mov     ra,in_pot       ; Change pot pin to input.
       bcf     status,rp0
       incfsz  potL            ; Incerement potL.
       goto    loop            ; If zero then potL overfolowed, so
       incfsz  potH            ; increment potH. If it overflows, exit.
       goto    loop            ; Overflow?  No: loop.
done    mov     temp,2          ; Divide 16-bit number represented by
div     bcf     status,carry    ; potH and potL by 2^temp (in this case,
       rrf     potH,f          ; 2^2 or 4). This scales the pot value
       rrf     potL,f          ; to fit within an 8-bit range.
       djnz    temp,div
       mov     rb,potL         ; Show the outcome on LEDs.
       goto    start           ; Do it again.
--
 Cheers,
       Paul B.

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