float CalculaTemp(uint32_t ValorADC){
float fTemp;
float fRes;
fRes = log((_NUMPASOS/ValorADC)-1);
fTemp = (1 / (_A1 + fRes*(_B1 + fRes*(_C1+_D1*fRes))))-273.15;
return fTemp;
}
}#define _A1 0.003354016
#define _B1 0.000256985
#define _C1 0.000002620131
#define _D1 0.00000006383091
#define _NUMPASOS 4096.0
-------------- Build: Release in Prueba_UART (compiler: GNU GCC Compiler)---------------
Checking if target is up-to-date: make -q -f Makefile Release
Running command: make -f Makefile
/usr/bin/arm-none-eabi-gcc -c -mcpu=cortex-m0 -mthumb -DUSE_HAL_DRIVER -DSTM32F030x6 -IInc -IDrivers/STM32F0xx_HAL_Driver/Inc -IDrivers/STM32F0xx_HAL_Driver/Inc/Legacy -IDrivers/CMSIS/Device/ST/STM32F0xx/Include -IDrivers/CMSIS/Include -Os -Wall -fdata-sections -ffunction-sections -MMD -MP -MF"build/main.d" -MT"build/main.d" -Wa,-a,-ad,-alms=build/main.lst Src/main.c -o build/main.o
Src/main.c: In function 'HAL_ADC_ConvCpltCallback':
Src/main.c:121:16: warning: unused variable 'i' [-Wunused-variable]
unsigned char i;
^
Src/main.c: In function 'main':
Src/main.c:215:17: warning: pointer targets in passing argument 1 of 'sprintf' differ in signedness [-Wpointer-sign]
len=sprintf(buffer,"Temperatura: %i ºC\r\n",temperature); //sprintf will return the length of 'buffer'
^
In file included from /usr/include/newlib/stdio.h:29:0,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h:50,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc.h:45,
from Inc/stm32f0xx_hal_conf.h:193,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h:46,
from Src/main.c:40:
/usr/include/newlib/stdio.h:231:5: note: expected 'char * restrict' but argument is of type 'unsigned char *'
int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
^
Src/main.c:215:24: warning: format '%i' expects argument of type 'int', but argument 3 has type 'int32_t {aka long int}' [-Wformat=]
len=sprintf(buffer,"Temperatura: %i ºC\r\n",temperature); //sprintf will return the length of 'buffer'
^
Src/main.c:215:24: warning: format '%i' expects argument of type 'int', but argument 3 has type 'int32_t {aka long int}' [-Wformat=]
Src/main.c:218:17: warning: pointer targets in passing argument 1 of 'sprintf' differ in signedness [-Wpointer-sign]
len=sprintf(buffer,"Numero de ciclos: %i Numero de conversiones: %i.\r\n",numConv2, numConv1); //sprintf will return the length of 'buffer'
^
In file included from /usr/include/newlib/stdio.h:29:0,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h:50,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc.h:45,
from Inc/stm32f0xx_hal_conf.h:193,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h:46,
from Src/main.c:40:
/usr/include/newlib/stdio.h:231:5: note: expected 'char * restrict' but argument is of type 'unsigned char *'
int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
^
Src/main.c:218:24: warning: format '%i' expects argument of type 'int', but argument 3 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
len=sprintf(buffer,"Numero de ciclos: %i Numero de conversiones: %i.\r\n",numConv2, numConv1); //sprintf will return the length of 'buffer'
^
Src/main.c:218:24: warning: format '%i' expects argument of type 'int', but argument 4 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
Src/main.c:218:24: warning: format '%i' expects argument of type 'int', but argument 3 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
Src/main.c:218:24: warning: format '%i' expects argument of type 'int', but argument 4 has type 'uint32_t {aka long unsigned int}' [-Wformat=]
Src/main.c:225:21: warning: pointer targets in passing argument 1 of 'sprintf' differ in signedness [-Wpointer-sign]
len=sprintf(buffer,"canal %i: %d,%d.\r\n",i, tempEnt[i],tempDec[i]); //sprintf will return the length of 'buffer'
^
In file included from /usr/include/newlib/stdio.h:29:0,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h:50,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc.h:45,
from Inc/stm32f0xx_hal_conf.h:193,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h:46,
from Src/main.c:40:
/usr/include/newlib/stdio.h:231:5: note: expected 'char * restrict' but argument is of type 'unsigned char *'
int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
^
Src/main.c:225:28: warning: format '%d' expects argument of type 'int', but argument 4 has type 'int32_t {aka long int}' [-Wformat=]
len=sprintf(buffer,"canal %i: %d,%d.\r\n",i, tempEnt[i],tempDec[i]); //sprintf will return the length of 'buffer'
^
Src/main.c:225:28: warning: format '%d' expects argument of type 'int', but argument 5 has type 'int32_t {aka long int}' [-Wformat=]
Src/main.c:225:28: warning: format '%d' expects argument of type 'int', but argument 4 has type 'int32_t {aka long int}' [-Wformat=]
Src/main.c:225:28: warning: format '%d' expects argument of type 'int', but argument 5 has type 'int32_t {aka long int}' [-Wformat=]
Src/main.c:228:17: warning: pointer targets in passing argument 1 of 'sprintf' differ in signedness [-Wpointer-sign]
len=sprintf(buffer,"\r\n"); //sprintf will return the length of 'buffer'
^
In file included from /usr/include/newlib/stdio.h:29:0,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_def.h:50,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_rcc.h:45,
from Inc/stm32f0xx_hal_conf.h:193,
from Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal.h:46,
from Src/main.c:40:
/usr/include/newlib/stdio.h:231:5: note: expected 'char * restrict' but argument is of type 'unsigned char *'
int _EXFUN(sprintf, (char *__restrict, const char *__restrict, ...)
^
/usr/bin/arm-none-eabi-gcc build/stm32f0xx_hal_tim.o build/stm32f0xx_hal_gpio.o build/stm32f0xx_hal_tim_ex.o build/stm32f0xx_it.o build/stm32f0xx_hal.o build/stm32f0xx_hal_cortex.o build/system_stm32f0xx.o build/stm32f0xx_hal_pwr.o build/stm32f0xx_hal_uart.o build/stm32f0xx_hal_rcc.o build/stm32f0xx_hal_rcc_ex.o build/main.o build/stm32f0xx_hal_pwr_ex.o build/stm32f0xx_hal_msp.o build/stm32f0xx_hal_uart_ex.o build/stm32f0xx_hal_adc_ex.o build/stm32f0xx_hal_adc.o build/startup_stm32f030x6.o -mcpu=cortex-m0 -mthumb -specs=nano.specs -TSTM32F030F4Px_FLASH.ld -lc -lm -lnosys -Wl,-Map=build/Prueba_UART.map,--cref -Wl,--gc-sections -o build/Prueba_UART.elf
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: build/Prueba_UART.elf section `.text' will not fit in region `FLASH'
/usr/lib/gcc/arm-none-eabi/5.4.1/../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 5460 bytes
collect2: error: ld returned 1 exit status
make: *** [build/Prueba_UART.elf] Error 1
Makefile:176: fallo en las instrucciones para el objetivo 'build/Prueba_UART.elf'
Process terminated with status 2 (0 minute(s), 2 second(s))
2 error(s), 15 warning(s) (0 minute(s), 2 second(s))
Sí, lo de los sprintf para sacar datos son pruebas y no le he prestado mucha atención.
De todas formas, el PIC tampoco tiene el acelerador hardware y el xc8 lo hace bien. Por eso preguntaba si hay alguna librería o se me ha pasado por alto algún parámetro del compilador.
Tendré que plantearme si sigo con el PIC o paso a un m3.
/usr/bin/arm-none-eabi-size build/stm32f030Test.elf
text data bss dec hex filename
5708 12 1756 7476 1d34 build/stm32f030Test.elf
/usr/bin/arm-none-eabi-size build/stm32f030Test.elf
text data bss dec hex filename
2380 12 1564 3956 f74 build/stm32f030Test.elf
text data bss dec hex filename
15316 116 1756 17188 4324 build/stm32f030Test.elf
text data bss dec hex filename
17800 116 1772 19688 4ce8 build/stm32f030Test.elf
text data bss dec hex filename
15384 116 1700 17200 4330 build/stm32f030Test.elf
/usr/bin/arm-none-eabi-size build/stm32f030Test.elf
text data bss dec hex filename
13848 116 1580 15544 3cb8 build/stm32f030Test.elf
/usr/bin/arm-none-eabi-size build/stm32f030Test.elf
text data bss dec hex filename
13736 116 1580 15432 3c48 build/stm32f030Test.elf
Hola a todos.
Para un experimento casero necesito leer la temperatura en 4 puntos diferentes. Para ello estoy utilizando 4 termistores de vishay NTC de 10k.
Empecé a hacerlo con un pic18F2550, y con él conseguí leer los 4 valores con el ADC, convertirlos a temperatura y enviarlos por el puerto serie junto con la fecha y hora leida de un DS1307 por I2C. Al compilar, el XC8 decía que estaba utilizando un 30% de la memoria del micro disponible aproximadamente (no me acuerdo ahora de la cifra exacta).
También estuve haciendo pruebas con un arduino uno, el del atmega, y también compilaba y funcionaba bien.
Por seguir experimentando, lo estoy intentando hacer ahora con un STM32F030, el de la placa que venden en ebay por 1,6€, y aquí es donde empiezan los problemas.
He configurado los periféricos con STM32CubeMX, los 4 canales de ADC y el puerto serie por ahora. He podido leer los 4 canales de ADC y enviar los valores enteros por el puerto serie, pero cuando meto la fórmula de cálculo de la temperatura de los termistores:Código: [Seleccionar]float CalculaTemp(uint32_t ValorADC){
float fTemp;
float fRes;
fRes = log((_NUMPASOS/ValorADC)-1);
fTemp = (1 / (_A1 + fRes*(_B1 + fRes*(_C1+_D1*fRes))))-273.15;
return fTemp;
}
}
el linker da un error de que estoy sobrepasando la capacidad de la memoria flash del dispositivo, que son 32 kB.
Si comento las lineas en las que hago los cálculos, vuelve a compilar y enlazar sin problemas, por lo que supongo que será por los cálculos de punto flotante, pero también los estoy utilizando en el pic y en el arduino sin problemas.
¿Hay alguna librería de cálculos en punto flotante que sea algo más ligera? ¿Cómo se utilizaría?
Muchas gracias.