cancel
Showing results for 
Search instead for 
Did you mean: 

Using ADC converted value

marcl
Associate II
Posted on November 18, 2008 at 09:10

Using ADC converted value

3 REPLIES 3
marcl
Associate II
Posted on May 17, 2011 at 12:52

Hallo everybody,

I arranged an ISR to use the ADC and to calculate the temperature of the temp sensor in grades Centigrade, but it doesn't work (I use RIDE7).

The strange thing is, when I use a value assigned to the variable, it works with no problems. Here is the code:

u16 TempSTM32;

u16 ADCConvertedValue;

void SysTickHandler(void)

{

/* Start ADC1 Software Conversion */

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

/* Wait End of conversion */

while (!ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));

/* When using this line instead of the next, all the code runs with no probs */

//ADCConvertedValue = 1740;

/* This value is correct ONLY when the next code line is not executed */

ADCConvertedValue = ADC_GetConversionValue(ADC1) ;

/* Temperature calculation for STM32 On-Chip sensor */

TempSTM32 = ((1.43 - ADCConvertedValue*3.4/4096 )/(4.3)*1000 + 25);

/* Sends the temperature via USART */

USART_SendData(USART1, TempSTM32 );

while ( USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET) {}

}

Any idea? 😉

ivanov-i
Associate II
Posted on May 17, 2011 at 12:52

Hi,

Did you setup the ADC in the beginning of your program? You need also to enable the temperature sensor before using it. Please, refer to the User Manual for STM32 about this.

One more point - it is a general rule to keep the ISR code as short as possible. Avoid such operations like waiting the UART to transmit the data and other time consuming things.

marcl
Associate II
Posted on May 17, 2011 at 12:52

Yes, the temperature sensor is enabled and all is correctly set up.

Still no way to use a floating expression after getting the ADC value, but I solved converting the temperature expression in integer form,just avoiding float numbers.

About the UART, do you mean I should use the TXE interrupt to send data?

I will check it, thanks for help!