STM32VLDISCOVERY - Temperature Sensor value conversions
Posted: Sat Mar 31, 2012 12:09 am
Hi Giovanni and ChibiOS/RT community,
In order to provide you a better insight into my problem and where am I, I will give a lil introduction to what I know so far:
Recently I found out about this RTOS and I'm impressed how good it is. I got STM32VLDISCOVERY board and wanted to give a try this RTOS. I'm new to STM family and new to RTOS because I was using PIC 8bit micro-controller before this. However I managed to read a lot about these new things to me and got an idea how it all works. I managed to run the Demo code for STM32VLDISCOVERY board. Tried to follow the Guide but I run into some problems which I don't want to describe in details, but I will just say its me and not the guide that caused the problem. So, at the end I programed via Keil MDK-ARM generating .hex file and downloading it to my board from but via external application called STM32 ST-LINK Utility. Did some edits to demo code, experimented. Opened Reference Manual and ChibiOS documentation, tried to understand all those things in code. I managed to understand the most of them.
Now onto my actual problem. I wanted to edit the demo code to generate PWM signals to LEDs (doesn't matter what period or width) when the temperature raises above for example 27 °C. Of course I am trying to use data acquired from temperature sensor which is present in the demo code which i suspect to be "avg_ch2" if I'm not mistaken. Now the problem is the conversion formula to °C. In the STM documentation they gave this one:
Temperature (in °C) = {(V25 - VSENSE) / Avg_Slope} + 25.
Where,
V25 = VSENSE value for 25° C and
Avg_Slope = Average Slope for curve between Temperature vs. VSENSE (given in mV/° C or µV/ °C).
VSENSE = current temperature from sensor in volts
For my board V25= 1.41 V and Avg_Slope= 4.3 V
The formula itself is correct no doubts there but I don't know what value does "avg_ch2" give me? Obviously VSENSE is needs to be in Volts too but I have hard times finding what exactly is the value for "avg_ch2". I would be very glad if someone could guide me how to convert that given value from ADC which is "avg_ch2" to actual volts so that I can use it in the formula above.
At the end I would make an "IF" statement where I check if the temperature is above 27 °C or not. I would take this part of demo code:
and wrap it around with the if statement like this:
^that one of course does not work because avg_ch2 is not in volts
Now I will give the details:
Board: STM32VLDISCOVERY
ChibiOS/RT version: 2.4.0
Demo code I've been referring to: http://www.chibios.org/dokuwiki/doku.ph ... overy:code
Please help me and thanks in advance.
In order to provide you a better insight into my problem and where am I, I will give a lil introduction to what I know so far:
Recently I found out about this RTOS and I'm impressed how good it is. I got STM32VLDISCOVERY board and wanted to give a try this RTOS. I'm new to STM family and new to RTOS because I was using PIC 8bit micro-controller before this. However I managed to read a lot about these new things to me and got an idea how it all works. I managed to run the Demo code for STM32VLDISCOVERY board. Tried to follow the Guide but I run into some problems which I don't want to describe in details, but I will just say its me and not the guide that caused the problem. So, at the end I programed via Keil MDK-ARM generating .hex file and downloading it to my board from but via external application called STM32 ST-LINK Utility. Did some edits to demo code, experimented. Opened Reference Manual and ChibiOS documentation, tried to understand all those things in code. I managed to understand the most of them.
Now onto my actual problem. I wanted to edit the demo code to generate PWM signals to LEDs (doesn't matter what period or width) when the temperature raises above for example 27 °C. Of course I am trying to use data acquired from temperature sensor which is present in the demo code which i suspect to be "avg_ch2" if I'm not mistaken. Now the problem is the conversion formula to °C. In the STM documentation they gave this one:
Temperature (in °C) = {(V25 - VSENSE) / Avg_Slope} + 25.
Where,
V25 = VSENSE value for 25° C and
Avg_Slope = Average Slope for curve between Temperature vs. VSENSE (given in mV/° C or µV/ °C).
VSENSE = current temperature from sensor in volts
For my board V25= 1.41 V and Avg_Slope= 4.3 V
The formula itself is correct no doubts there but I don't know what value does "avg_ch2" give me? Obviously VSENSE is needs to be in Volts too but I have hard times finding what exactly is the value for "avg_ch2". I would be very glad if someone could guide me how to convert that given value from ADC which is "avg_ch2" to actual volts so that I can use it in the formula above.
At the end I would make an "IF" statement where I check if the temperature is above 27 °C or not. I would take this part of demo code:
Code: Select all
/* Changes the channels pulse width, the change will be effective
starting from the next cycle.*/
pwmEnableChannelI(&PWMD3, 2, 4096, PWM_FRACTION_TO_WIDTH(&PWMD3, 4096, avg_ch1));
pwmEnableChannelI(&PWMD3, 3, PWM_FRACTION_TO_WIDTH(&PWMD3, 4096, avg_ch2));
/* SPI slave selection and transmission start.*/
spiSelectI(&SPID1);
spiStartSendI(&SPID1, ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH, samples);
chSysUnlockFromIsr();and wrap it around with the if statement like this:
Code: Select all
if(((1.41 - avg_ch2) / 4.3) + 25 > 27 )^that one of course does not work because avg_ch2 is not in volts
Now I will give the details:
Board: STM32VLDISCOVERY
ChibiOS/RT version: 2.4.0
Demo code I've been referring to: http://www.chibios.org/dokuwiki/doku.ph ... overy:code
Please help me and thanks in advance.