On 3/15/06, markp@cannontech.com wrote: > > > >>I needed to convert a 0to5 volt input to 16 discrete alarm > >>temperatures. Dividing a 0-4096 12bit A/D count by 256 yields > >>a perfect 0-15 result. To do this, I simply grab the high > >>byte from the conversion. I then use a 16-entry lookup table > >>to convert to literal temperature values. > >> > >>This is the analog-read subroutine: > >> > >> ; Read alarm temperature 1 > >> movlw b'00001001' ; Configure A/D, RA1/AN1. > >> movwf adcon0 ; > >> call D_20US ; Delay 20 microseconds. > >> bsf adcon0,2 ; Start conversion. > >> btfsc adcon0,2 ; Test go/done bit. > >> goto $-1 > >> movf adresh,w ; Conv complete, get high A/D result. > >> movwf ALARM1_RAW ; Write data to register. > >> > >>It works except for one thing, I never get a zero for the high > >>byte. See results *: > >>It works except for one thing, I never get a zero for the high byte. > >>See results *: > >> > >>Input 12 bit Expected Actual > >>Volts Count High Byte High Byte > >>0.00 0 0 1 * > >>0.31 256 1 1 > >>0.63 512 2 2 > >>0.94 768 3 3 > >>1.25 1024 4 4 > >>1.56 1280 5 5 > >>1.88 1536 6 6 > >>2.19 1792 7 7 > >>2.50 2048 8 8 > >>2.81 2304 9 9 > >>3.13 2560 10 10 > >>3.44 2816 11 11 > >>3.75 3072 12 12 > >>4.06 3328 13 13 > >>4.38 3584 14 14 > >>4.69 3840 15 15 > >> > >> > >>Any ideas on what would cause the high byte to always have a minimum > value of one? > > >What device are you using? The only 12bit integrated ADCs in the > >16bit core that I know of are in the old 16C77x parts. Have you > >correctly configured ADCON1? > > > >Regards > > > >Mike > > > > You're right, I'm using a 16C773. ADCON1 is configured correctly. Three > other analog inputs work perfectly, however, this one is just short of > perfect due to the value being 1 when it should be 0. Maybe you have a wrong carry flag somewhere ? BTW, why did you use such a complicated algorithm while probably was much easy with the internal reference and one comparator? Probably those aren't available in PIC16C773 ? greetings, Vasile -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist