Hello,
I have a problem with my timer. The program works as specified below. But I want, that the ADC value converted into a float and then output on the display.
If I write
sprintf(StringBuf, "ADC0: %.2f", (float)adcVal[0]);
or this
float x; x = ADC_GetValue(); sprintf(StringBuf, "ADC0: %.2f", x);
my timer doesn't works. But I don't know, why?
And another problem is, I defined the timerDelay = 10.000 ms. This means that my timer restart every 10 seconds, but why can I see every second a new value of the adc converter on the display? Normally it must show me a value every 10 seconds?
I hope anyone can help me.
SOURCE-CODE which works without problems: #include "LPC43xx.h" #include "Board_ADC.h" #include "Board_GLCD.h" #include "GLCD_Config.h" #include <cmsis_os.h> #include <stdio.h> #define STRINGBUF_LEN 21 extern GLCD_FONT GLCD_Font_16x24; char StringBuf[STRINGBUF_LEN]; void Timer_Callback (void const *arg); osTimerDef (Timer, Timer_Callback); osTimerId TimerId; uint32_t exec; uint32_t timerDelay; uint32_t cnt=0; void Timer_Callback (void const *arg) { int adcVal[3]; ADC_Initialize(); ADC_StartConversion(); while(ADC_ConversionDone() < 0); adcVal[0] = ADC_GetValue(); adcVal[0] = (adcVal[0] * 10) / 1024; sprintf(StringBuf, "ADC0: %d", adcVal[0]); GLCD_SetForegroundColor (GLCD_COLOR_BLACK); GLCD_DrawString (0, 2*24, (char*)StringBuf); ... ... ... } int main(void) { exec = 2; TimerId = osTimerCreate (osTimer(Timer), osTimerPeriodic, &exec); if (TimerId != NULL) { timerDelay = 10000; osTimerStart (TimerId, timerDelay); } GLCD_Initialize(); GLCD_SetBackgroundColor (GLCD_COLOR_BLUE); GLCD_SetForegroundColor (GLCD_COLOR_WHITE); GLCD_SetFont (&GLCD_Font_16x24); GLCD_DrawString (0, 0*24, " ADC Value "); GLCD_DrawString (0, 1*24, " "); GLCD_SetBackgroundColor (GLCD_COLOR_WHITE); GLCD_SetForegroundColor (GLCD_COLOR_BLUE); GLCD_DrawString (0, 2*24, " "); GLCD_DrawString (0, 3*24, " "); GLCD_DrawString (0, 4*24, " "); GLCD_DrawString (0, 5*24, " "); GLCD_DrawString (0, 6*24, " "); GLCD_DrawString (0, 7*24, " "); GLCD_DrawString (0, 8*24, " "); GLCD_DrawString (0, 9*24, " "); }