Easylogger, what it does of evaluateADC in actual process
Posted: 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);
}
-----------------
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);
}
-----------------