NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Trouble with the log10 function
June 01, 2010 by Rufusthedog |
Hi All, I'm just modifying the tempsensor to change the output for log output. I modified the code as follows and it won't compile. Any idea what I'm doing wrong? From: fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"),temp_avg); To: fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"),10*log10(temp_avg)); Thanks, |
---|---|
June 01, 2010 by Ralphxyz |
Comment the changed line out to confirm that is where the problem is coming from. Your change looks good but then again ... Ralph |
June 01, 2010 by Rufusthedog |
Thanks Ralph, If I change it to somethings like this, it works. fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"),10*(temp_avg)); It just doesn't compile when add in the LOG10 function, I'm sure I'm screwing up somewhere. |
June 02, 2010 by Ralphxyz |
Possible you might try (10*(log10(temp_avg)). Where is it failing? does x= log10(temp_avg) work? Ralph |
June 02, 2010 by Ralphxyz |
Ooops try (10*(log10(temp_avg))). Ralph |
June 02, 2010 by bretm |
Does the makefile include the -lm linker flag? |
June 02, 2010 by Rufusthedog |
Hi Bretm, It appears it doesn't have that flag, I will give that a try. Thanks Rufus |
June 02, 2010 by Rufusthedog |
No, I was wrong, the-lm flag is there. I'm running this on Mac and I also tried under windows and get the same error. Here is the Makefile: GCCFLAGS=-g -Os -Wall -mmcu=atmega168 LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P /dev/tty.PL2303-0000101D LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o all: tempsensor-upload tempsensor.hex: tempsensor.c make -C ../libnerdkits avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o tempsensor.o tempsensor.c ${LINKOBJECTS} avr-objcopy -j .text -O ihex tempsensor.o tempsensor.hex tempsensor.ass: tempsensor.hex avr-objdump -S -d tempsensor.o > tempsensor.ass tempsensor-upload: tempsensor.hex avrdude ${AVRDUDEFLAGS} -U flash:w:tempsensor.hex:a |
June 02, 2010 by bretm |
Does it work if you add this to your #include statements in the source?
|
June 02, 2010 by Rufusthedog |
Hi Bretm, The Tempsensor code is the same that is part of Nerdkits and the <math.h> is called in the #include statements I just added the log10 function. I suspect the problem is with the makefile. Rufus
|
June 02, 2010 by mrobbins (NerdKits Staff) |
Hi Rufus, Does your compiler error say something like "relocation truncated to fit"? If so, give this a try: 1) In the Makefile, remove "-lm" from the end of the LINKFLAGS line:
2) In the Makefile, add "-lm" to the end of the LINKOBJECTS line:
3) Run "make". This simply rearranges the order in which the compiler/linker bundles the math code with your code, ensuring that the math code comes last. For reasons that are a little bit voodoo, this tends to make it work. (There's a bug report about this issue from a while ago, but not too much detail in explaining it clearly.) Please let me know if that works! And if not, please post the compiler's error message. Mike |
June 03, 2010 by Rufusthedog |
Hi Mike, That worked! I suspected that was where the problem was but I'm not real familiar with makefiles yet. Thanks for the help, Rufus |
Please log in to post a reply.
Did you know that our USB NerdKit works on Windows, Linux, and Mac OS X? Learn more...
|