Forum: Mikrocontroller und Digitale Elektronik Temp Sensor Stm32


von Ma B. (drumstick)


Lesenswert?

Hallo!

Ich verwende den STM32F103VDT6 und das uVision von Keil.

Ich möchte den Tempsensor verwenden.

Ich erhalte leider immer eine Temperatur von -379944°C.

Meine Init: Ausschnitt!
1
volatile TADCin  ADCin;
1
typedef struct{
2
                TADCinval AN_MotI;        // AN_IN
3
                TADCinval AN_IN1;
4
                TADCinval AN_TmpSens;
5
              }
6
        TADCin;
1
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(ADC1->DR);
2
  DMA_InitStructure.DMA_MemoryBaseAddr      = (uint32_t)&ADCin;     // ADC In Variable
3
4
  DMA_InitStructure.DMA_DIR                 = DMA_DIR_PeripheralSRC;
5
  DMA_InitStructure.DMA_BufferSize          = sizeof(TADCin)/ sizeof(TADCinval);
6
7
// ADC1 configuration ------------------------------------------------------
8
  ADC_InitStructure.ADC_Mode                = ADC_Mode_Independent;
9
  ADC_InitStructure.ADC_ScanConvMode        = ENABLE;
10
  ADC_InitStructure.ADC_ContinuousConvMode  = ENABLE;
11
  ADC_InitStructure.ADC_ExternalTrigConv    = ADC_ExternalTrigConv_None;
12
  ADC_InitStructure.ADC_DataAlign           = ADC_DataAlign_Right;
13
  ADC_InitStructure.ADC_NbrOfChannel        = 3;
14
  ADC_Init(ADC1, &ADC_InitStructure);
15
16
17
  // ADC1 regular channel11 configuration 
18
  ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_71Cycles5); // AN_IN   12.5 + 71.5 = 84 cycles --> 7us
19
  ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 2, ADC_SampleTime_71Cycles5); // VNFGND  12.5 + 71.5 = 84 cycles --> 7us
20
  ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 3, ADC_SampleTime_71Cycles5); // Pot R43 12.5 + 71.5 = 84 cycles --> 7us
21
  ADC_RegularChannelConfig(ADC1, ADC_Channel_17,  4, ADC_SampleTime_71Cycles5); // Pot R56 12.5 + 71.5 = 84 cycles --> 7us
22
23
// Enable ADC1 DMA 
24
  ADC_DMACmd(ADC1, ENABLE);
25
  
26
  // Enable ADC1 
27
  ADC_Cmd(ADC1, ENABLE);
28
29
  // Enable ADC1 reset calibration register 
30
  ADC_ResetCalibration(ADC1);
31
  // Check the end of ADC1 reset calibration register 
32
  while(ADC_GetResetCalibrationStatus(ADC1));
33
34
  // Start ADC1 calibration 
35
  ADC_StartCalibration(ADC1);
36
  // Check the end of ADC1 calibration 
37
  while(ADC_GetCalibrationStatus(ADC1));
38
  
39
  ADC_TempSensorVrefintCmd(ENABLE);
40
     
41
  // Start ADC1 Software Conversion 
42
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

Ich füre noch 2 andere Messungen durch, die funktionieren.

ADC_Channel_16 und _17 sind für den TempSens.
1
#define V25       1.43
2
#define AVGSLOPE  0.0043
3
4
int   ADC_Device_Mes  = 0;      
5
int   ADC_DevValue    = 0;
6
float TempSens_C      = 0.0;
7
8
9
int DevTemperatur_Measure(void)               //ToDo//                    
10
{                                            
11
  ADC_Device_Mes =  ADCin.AN_TmpSens;         // get the measured ADC value
12
  TempSens_C = ((V25 - ADC_Device_Mes)/AVGSLOPE) + 25;  
13
  return(TempSens_C);
14
}

ADC_Device_Mes in Digits, dies ist ja korrekt, damit die Formel am 
Schluss °C ergibt.


1
ADC_InitStructure.ADC_NbrOfChannel        = 3;
Habe ich auch mit 4 probiert, dann lief nichts mehr

Sieht jemand einen Fehler?

von Ma B. (drumstick)


Lesenswert?

Ich habe jetzt die Digits in eine Spannung umgerechnet:

Vref = 3.3 V
12 Bit = 4096
ADCWert = 1633

3.3V / 4096 * 1633

T = ((V25 - 1.3156) / 0.0043) + 25 = 51.60°C

Ohne das + 25 ergäbe dies 26.60°C

Mein Thermometer misst gerade 24,5°C . würde fasst in der Toleranz 
liegen (2°C)

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.