Bonjour Gael & PIC.ers, I did this a while back. You might get some ideas from the code below, this part of the project worked well. .. Pity about the rest of the job.... .. Best regards, John >Date: Sun, 29 Nov 1998 21:47:24 +0100 >From: Gael Waiche >Subject: Reading a potentiometer without an ADC > >Hi! > >I need to read a pot with a 8Mhz 16C84 to drive >a motor with PWM. > >Does anybody have an assembly language routine >to read a pot? Even a low resolution ( 4 or 5 bits) >will be enough. > >Thank for your help! > >Gael ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;***************************************General subroutines ;pot_rc is defined as port pin rb2 ;ASCII art, here goes:- ; ; ; 220R Variable R, 10K ; pot_rc pin ---/\/\/\/\/\---------0----------/\/\/\/\/\/--- ; I ^ I ; ----- I I ; 0.1uF ----- ------I ; I I ; I I ; I I ; ----------- -------- ; readpot ;subroutine,read the pot position by cheap rc timer clrf count4 ;sp routine counter forced to zero bsf status,rp0 bcf trisb,pot_rc ;make the pot pin an output bcf status,rp0 ;charge up cap. to +5v Vdd bsf mirror_portb,pot_rc ;r-m-w- movf mirror_portb,w movwf portb movlw 0x50 movwf count1 pumpup decfsz count1,same goto pumpup ;drop out only after cap charged full bsf status,rp0 bsf trisb,pot_rc ;make the pot pin an input bcf status,rp0 decaycount movf portb,w ;r-m-w movwf mirror_portb btfss mirror_portb,pot_rc goto exit_readpot incfsz count4,same goto decaycount movlw 0xFF movwf count4 ;ensures pot_sp doesn't rollover >FF exit_readpot movf pot_sp,w ;pot_sp is `old' pwmmark value subwf count4,w ;c set if pot_sp>count4=want more rpm btfsc status,c goto down_speed ;=down_sp=pot_sp increase= less rpm decf pot_sp,same ;=up_sp=pot_sp reducing= more rpm goto exit_readpot_1 down_speed ;NB ?? not sure about the logic of movf count4,w ;exit_readpot -> onwards, but it movwf pot_sp ;works properly. ???!!! exit_readpot_1 bsf status,rp0 bcf trisb,pot_rc ;make the pot pin an output bcf status,rp0 bcf mirror_portb,pot_rc ;r-m-w- movf mirror_portb,w ;bash pin LO & keep it there movwf portb return ;from readpot subroutine ******** .. email from John Sanderson at JS Controls, PO Box 1887, Boksburg 1460, Rep. South Africa Manufacturer & purveyor of laboratory force testing apparatus and related products and services. Tel/fax: Johannesburg 893 4154 Cellphone 082 453 4815