This is a multi-part message in MIME format. ------=_NextPart_000_0009_01C362FB.789FD580 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit hi, Have attached an assembler program that turns 1 LED and another LED off when the program senses a voltage on a pot. -:)) ----- Original Message ----- From: "Rith Nachampasak" To: Sent: Friday, August 15, 2003 5:11 AM Subject: Re: PIC:8-bit ADC 16C765 please help! Thanks Samo, Here what I had for setting A/D: start bsf status,rp0 ;switch to bank1 movlw b'00000011' ;input/output movwf trisa movlw b'00000000' movwf trisb ;output movlw b'00000011' ;config porta, bits 4,2,1,0 analog ;bits 7,6,5 digital I/O Bit 4,2,1,0 was configured as analog input. That mean if I wanna use two analog input, all I have to do is connect two inputs to AN0 and AN1?? How does it know which input to store on the ADRES? Again thanks for your help Rith -----Original Message----- From: Samo Benedicic [mailto:samo_benedicic@YAHOO.COM] Sent: Thursday, August 07, 2003 12:30 PM To: PICLIST@MITVMA.MIT.EDU Subject: Re: PIC:8-bit ADC 16C765 please help! Hi! 8 bit A/D means that you have 255 discrete steps between 0 and Vref. That means one step is Vref/255. As far as I know, you can only measure voltages between 0 and 3V with your setup ( Vref in your case is 3V). If you want to measure voltages from 0-5V, make Vref=Vcc in A/D module setup. If Vref=5V, than each step is approx. 19,6mV. Than 1V is 1/0.0196=51, 2V=102 and so on. Samo --- Rith Nachampasak wrote: > Hi Steve, thanks for the source code, I really > appreciate your help. > > I still hazy about the result. I connect 8 LEDs to > portb, all are lights up. > (b'11111111')at 5Vdc input.Here's my setting: > Vref = 3Vdc > AN0 =0 - 5Vdc (10k pot) > When I measured the voltage on each portb, I got > around 4.45Vdc. > How do I put these values on the table, etc., > Input(vdc) Hex Binary > 1 ? ? > 2 ? ? > 3 ? ? > 4 ? ? > 4.5 ? ? > 5 ? ? > > --Rith > > -----Original Message----- > From: Steve Murphy [mailto:smurph@METRONET.COM] > Sent: Friday, July 25, 2003 6:56 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: PIC:8-bit ADC 16C765 please help! > > > > > Rith, > > I don't see at first glance any glaring error that > jumps out at me. > I have never used the 16C765. Check the data sheet > for something (i.e. > comparator or CCP, etc.) and make sure these other > peripherals are > turned off. > > Make sure the watchdog is turned off until you get > things working. > > Keep in mind that the way the A/D works, is that in > the ADRES register > you will get a result in hex of how many 19.6mVolts, > (5V reference divided > by 8 bits of A/D = 5V/255 = .0196 = 19.6 mV.) are > read at the A/D port. > > For your example: 2V = (approx) 66 hex in ADRES( > 01100110 binary). > When you write 01100110 to port B, the leds that are > connected to ground > on the opposite side from the pic (0V) will light > with the bits that = 1. > > A lot of folks, including me wire leds so that the > side oposite the > pic is connected to VDD making them active low. If > your circuit is > like wired like that, you must invert the binary > 01100110 to 10011001 > to get the leds to light with the bits that = 0. > > To do that, use the comf instruction to negate: > > movf ADRES,W ;get a/d value > comf W, W ; invert bits. > > movwf PORTB ;output to port b > > > Regards, > > Steve > > > Could someone please help me interpret the result > of the Single channel A/D of the following code that > I down loaded from microchip, AN546. I substituted > the pic16C71 to pic16C765 Builded on the emulator > ICE2000 I got succeeded messaged. I connected a 2VDC > into pin2(RA0/AN0)...should I get the outputs from > PortB,etc., around 7.8mV?? > > > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > -- > http://www.piclist.com hint: The PICList is archived > three different > ways. See http://www.piclist.com/#archives for details. __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu ------=_NextPart_000_0009_01C362FB.789FD580 Content-Type: application/octet-stream; name="A to D.asm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="A to D.asm" ;************************************************************************= **** ;Program Specification ; Setup Watchdog Timer ; 1. A/D a voltage from a pot 0-5v=20 ; use the ADRESH:ADRESL ; 2. Set up software value of 2.5v ; 3. Turn LED ON when >2.5v or OFF below =3D<2.5v ; 4. 100 ms delay before checking analog input again ;************************************************************************= **** ; I/O Maping ; GP0 analog input ; GP1 LED > 2.5 volts ; GP2 LED =3D< 2.5 volts ; GP3 not used ; GP4 not used ; GP5 not used ;************************************************************************= **** ;; Code required for final version ;;; Testing Search and remove/update as required when finished testing. ;;;? Code required? ;************************************************************************= **** ; Compiler directives list p=3D12F675 #include "p12f675.inc" __CONFIG _CP_OFF & _WDT_ON & _BODEN_ON & _PWRTE_ON & = _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF ;Code Protection OFF (Program protection) ; Watchdog timer ON ; Brown out detect ON ; Power up Timer enable ON ; Internal RC Oscillator & no clock out ; Mater clear OFF ; Data code protection OFF (EEPROM protection) errorlevel -302 ; suppress message 302 from list ;************************************************************************= **** ; Allocate Memory for verables cblock 0x20 ;Start of General Purpose Registers (64 bytes) delay ;100ms delay VrefH ;Reference voltage VrefL VinH ;VinH =3D ADRESH These two are used to limit bank switching VinL ;VinL =3D ADRESL endc ;************************************************************************= **** org 0x00 ;Set program orgin (Start of code) goto Init ;Start of program ;************************************************************************= **** ; Initilise your verables here Init ;***** Setup Watch dog timer - change Timer0 to WDT ***** bsf STATUS,RP0 ;Bank 1 Setup Watchdog Timer movlw b'00000000' ;Select clock source & postscale value movwf OPTION_REG bcf STATUS,RP0 ;Bank 0 clrf TMR0 bsf STATUS,RP0 ;Bank 1=09 bsf OPTION_REG,PSA ;Change to WDT clrwdt ;Clear WDT movlw b'00001000' movwf OPTION_REG bcf STATUS,RP0 ;Bank 0 ;************************************************************=09 bsf STATUS,RP0 ;Bank 1 movlw b'0010001' ;FOSC/8, GP0 =3D analog, rest digital movwf ANSEL movlw b'001001' ;Use GP0 as analog input movwf TRISIO bcf STATUS,RP0 ;Bank 0 movlw b'10000001' movwf ADCON0 clrf GPIO ;initialise all outputs movlw b'00000111' ;set GP<2:0> to digital I/O movwf CMCON ;turns comparator off ;Setup VrefH:VrefL analog voltage 1FF =3D 2.5 volts movlw 0x1 movwf VrefH ;VrefH:VrefL =3D 1FF movlw 0xFF movwf VrefL ;************************************************************************= **** Start ;Start A/D Converstion clrwdt ;Clear WDT bsf ADCON0,1 ;GO movlw .6 ;20us delay required after changinag the A/D channel movwf delay Call Delay Test_AtoD btfss PIR1,6 ;A/D Done? goto Test_AtoD bcf PIR1,6 Subtract movfw ADRESH movwf VinH bsf STATUS,RP0 ;Bank 1 movfw ADRESL movwf VinL bcf STATUS,RP0 ;Bank 0 movfw VrefL ;subtract LSB subwf VinL,0 btfss STATUS,DC ;0 =3D No carry, 1 =3D carry goto MSB btfsc STATUS,Z ;0 =3D Not zero, 1 =3D zero goto MSB=09 incf VinH,1 ;VinL was > VdropL goto MSB MSB movlw .255 movwf delay ;Setup for a wait between samples movfw VrefH ;subtract MSB subwf VinH,0 btfss STATUS,DC ;0 =3D No carry, 1 =3D carry goto LED_OFF ;Turn LED OFF < 2.5v btfss STATUS,Z ;0 =3D Not zero, 1 =3D zero goto LED_ON ;Turn LED ON > 2.5v goto LED_OFF ;Turn LED OFF < 2.5v LED_ON ;Turn LED ON > 2.5v movlw b'000010' movwf GPIO call delay goto Start LED_OFF ;Turn LED OFF < 2.5v movlw b'000100' movwf GPIO call Delay goto Start=09 ;************************************************************************= **** Delay decfsz delay,1 goto $-1 ;Go back one line return=09 ;************************************************************************= **** Stop end ;Thats all folks :-} ------=_NextPart_000_0009_01C362FB.789FD580--