I have completed a program for an app. on the Atmega48 and my code size is 110.7%.
I have added the libm.a library to my linker.
I use a floating point calculation as well as a printf in my program. I am measuring a <0 ADC value and sending it to the UART through a printf statement. I am also using a division statement to get the floating point value as follows:
ADC_buffer_dummy = (float)(ADC_dummy * 5)/1023; a = ADC_buffer_dummy/1; if(a == 1) // if ADC_buffer_dummy value is less than one //say for e.g. ADC_buffer_dummy = 0.547 //then a = 0, b = 0.547 * 1000 = 547 //hence the else statement b = (ADC_buffer_dummy - 1)*1000; else b = ADC_buffer_dummy * 1000;
For the printf statement I am using the FDEV_SETUP_STREAM routine. It is working fine and I would like to try and stick to this rather than make any last minute changes.
When I remove the division statement:
ADC_buffer_dummy = (float)(ADC_dummy * 5)/1023;
my code size drops to 85%.When I remove the division it does not change much. When I remove the float it does not change much either, it is only when I completely remove the statement above, I get the code size drop to 85%.
Now I am trying to rewrite this logic to eliminate the divide and the float but I am looking for three decimal places for my values (0.xxx).
Any ideas of how I can reduce code size? Getting another chip with larger memory is also an option but that will be my last resort.