'Q: Code for simple A/D one pin 16F84?'
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
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 (digital.com) james.cameron
Digital Equipment Corporation (Australia) Pty. Ltd. A.C.N. 000 446 800
Dr. Imre Bartfai
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.)
On Fri, 24 Jul 1998, James Cameron wrote:
> 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!
; This program shows a technique for reading resistance. The pot input
; pin can only be changed during assembly, not once the program is
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:
mov macro dest,val
djnz macro reg,dest
start bsf status,rp0
mov ra,out_pot ; RA.0 to output.
mov rb,0 ; All outputs for LEDs.
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.
mov ra,in_pot ; Get input from pot.
bcf pot ; Clear output latch for pot bit.
loop btfss pot ; IF pot = 0
goto done ; THEN done
mov ra,out_pot ; Discharge cap a little.
mov ra,in_pot ; Change pot pin to input.
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.
mov rb,potL ; Show the outcome on LEDs.
goto start ; Do it again.
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- New search...