Page 1 of 1

STM32VLDISCOVERY - Temperature Sensor value conversions

Posted: Sat Mar 31, 2012 12:09 am
by Azur
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:

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.

Re: STM32VLDISCOVERY - Temperature Sensor value conversions

Posted: Sat Mar 31, 2012 6:27 am
by Giovanni
Hi the measurement is performed from GND to the analog VCC which is 3 Volts (please verify in the schematic). The conversion is performed using 12 bits so a sample value goes from 0 (0 Volts) to 4095 (3 Volts). You just need to convert it in Volts.

If I remember well, I read something on the spreadsheet about the temperature sensor, you shouldn't expect a great precision from it.

Giovanni

Re: STM32VLDISCOVERY - Temperature Sensor value conversions

Posted: Sat Mar 31, 2012 9:34 am
by pito
..there is a schottky diode D3 in series with the 3V3 voltage regler, so actualy the voltage is ~3V. The voltage drop depends on the diode itself (forward voltage), current flowing through the diode (ie cpu load, peripherals activities, sdcard connected etc., for BAT60J it is max 0.32V/10mA, 0.4V/100mA) and temperature (~2mV/degC). So it is more-less a rnd generator (good for adc dithering ;) ). Moreover the temperature dependency of the D3 is similar to that internal senzor (also a forward biased diode) so when those 3V will be used as reference you may see interesting results.. On the STM32VLdisco the same, I replaced the diode with a wire there, not done on F4 yet.. If you want to measure voltages within 12bit adc precision you need a good external voltage reference source (plus a good decoupling, grounding, shielding, etc.) p.