Easylogger, what it does of evaluateADC in actual process

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
xiao

Easylogger, what it does of evaluateADC in actual process

Post by xiao » Mon Aug 18, 2008 6:00 pm

this is a purpose to optimise & cut the code size to fits the 2K flash when an example of easylogger equipped for ATTINY45 of which has 4K flash.

our gloa is not far away from the began, as the result offered by the function evaluateADC, a typical code & time consuming by division of a 16bit ADC data, if we are able to landing with optimisation without do this math stuff, the overall code size can be fit into 2K space.

however, I am not familiar with the C coding and would like to have some input for the code snippet follwings, in order to catch the idea of this function completely, what it does.

-----------------
static void evaluateADC(unsigned int value)
{
uchar digit;

value += value + (value >> 1); // value = value * 2.5 for output in mV = value x2 + value /2
nextDigit = &valueBuffer[sizeof(valueBuffer)]; // == 16 ?
*--nextDigit = 0xff;// terminate with 0xff, pointer -1
*--nextDigit = 0;
*--nextDigit = KEY_RETURN; // KEY_RETURN=40 ??
do{
digit = value % 10; //mod, value is dvidend, 10 is divisor, digit is remainder
value /= 10; // quotient
*--nextDigit = 0;
if(digit == 0){
*--nextDigit = KEY_0; //KEY_0=39 ??
}else{
*--nextDigit = KEY_1 - 1 + digit; //KEY_1=30 ??
}
}while(value != 0);
}

-----------------

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Tue Aug 26, 2008 6:56 pm

The code converts a binary number in the range 0 - 1023 (or whatever you get after normalization to a voltage) into a sequence of key strokes representing the digits of the decimal number. The decimal digits are found by modulo 10 (least significant digit) and division by 10 (shift out least significant digit). The code omits leading zeros.

xiao

Post by xiao » Wed Sep 03, 2008 8:44 am

christian wrote:The code converts a binary number in the range 0 - 1023 (or whatever you get after normalization to a voltage) into a sequence of key strokes representing the digits of the decimal number. The decimal digits are found by modulo 10 (least significant digit) and division by 10 (shift out least significant digit). The code omits leading zeros.



Thanks Christian, we have read the same thing before seeing your reply with a hand written calculation, and now it is done.

In order to lower firmware size to fits within 2K flash of the TINY26, we have repalced this code with the approach of unpack HEX to USBKeyID, if only ADCH is read as 8bits resolution.

Come across here to look for something else, it is because the ADC problem, the signle-end ADC input by stimulating the resistor ladder as voltage divider, ADC output is perfect, it is working flawless. However, a pair of differtienl ADC inputs is used, the ADC result is jumping always no matter 8bits or 10bits in resolution. so we are here to look at if someone has the experience to a kick off such issue.

Post Reply