I’m learning MCU programming with Atmega32 & winavr. I need to convert ADC value to something else (say voltage=5*ADCvalue/1023) which needs to deal with floating point/double. Then to display on LCD I need to convert the calculated value to string/array (eg. Sprintf(….)). Both these (floating point number & print function) consumes large memory/code area of the microcontroller (even with the small versions made for MCU).
Can any one please help me with any alternative way. I goggled a lot but failed to figure out solution specific to my case (I’m not an expert in programming/MCU).
*****
ISR(ADC_vect)
{
uint8_t thelow=ADCL;
uint16_t adc10bit=ADCH<<2 |thelow>>6;
float adcvolt=4.8*((adc10bit)/1023);
char adcvoltstr[10];
sprintf(adcvoltstr,"%.2f",adcvolt); //sprintf() may not be used
PrintValuetolcd(adcvolt,2,1); //display ADC value
PrintStringtolcd(adcvoltstr); //display volt
_delay_ms(50);
ADCSRA |=1<<ADSC; //start the next conversion
}
****
I tried with this solution. but its i get unexpected value . Is it because of data type.
If so, what variable type i should use?
---
uint8_t thelow=ADCL;
uint16_t adc10bit=ADCH<<2 |thelow>>6;
uint16_t adcvolt=5*((adc10bit*1000)/1023);
Printlcdval(adc10bit,1,1); //display the value
Sendastring(" "); //clear 0 of previous display
Printlcdval(adcvolt,2,1);
--
how to impliment fixed point math (sorry, I'm a newbie).