>-----Original Message----- >From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] >On Behalf Of Andre Abelian >Sent: 07 January 2007 21:13 >To: Microcontroller discussion list - Public. >Subject: Re: [pic]: how to convert 0-2,5v to 0-1023 > > >Rolf, > >thanks for your replay. Using Vref is very good idea but in my >case the >situation is lot more >complicated. This is how it should be: > >0-2,4v output 0-1023 with 2's complement format and enable a >bit 2.6-5.0v output 0-1023 disable the bit. While it is in >between 2,5v >should output 0 > >any idea? So this sounds like you really want to output (via the UART) a range of -1023 to +1023 for an input voltage range of 0-5 volts, with 2.5 volts giving an output of zero? Is that correct? Ignore the following if not. You mentioned in a later post that a resolution of 512 counts for full scale was acceptable. If so this is a trivial problem to solve. With Vcc=5v, the PICs ADC converter gives an output of 0-1023 for your input range. You simply need to double the output, then subtract 1023 to give the result you require e.g. in C this would be something like this: int16_t result; /* 16 bit signed value to hold final result */ int16_t adc; /* 16 bit signed value to hold ADC result */ adc = GetAdc(); /* Get ADC result */ result= (adc * 2) - 1023; /* convert range -1023 to +1023 */ putch( (uint8_t)(result >> 8) ); /* Send MSB of result to UART */ putch( (uint8_t)(result & 0xFF) ); /* Send LSB of result to UART */ It would be just as easy if you are using assembler, just remember to use a signed 16 bit subtract function in the calculation. Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist