1-> 请问Vrefint是测量的什么值? 百度查到的资料说是内部电压用作AD转换时参考电压的值,但是库函数里面的描述感觉像是测量电池的电压值,板子上备份电池的电压能测量吗?
void ADC1_Init(void)
{
ADC_InitTypeDef ADC_InitStruct;
ADC_CommonInitTypeDef ADC_CommonInitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
//ADC_InitStruct.ADC_ExternalTrigConv =
ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_NbrOfConversion = 2;
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ScanConvMode = DISABLE;
ADC_Init(ADC1,&ADC_InitStruct);
ADC_CommonInitStruct.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStruct.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStruct.ADC_Prescaler = ADC_Prescaler_Div4;
ADC_CommonInitStruct.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStruct);
ADC_Cmd(ADC1,ENABLE);
ADC_TempSensorVrefintCmd(ENABLE);
ADC_VBATCmd(ENABLE);
}
u16 ADC1_GetVal(unsigned char chnl)
{
ADC_RegularChannelConfig(ADC1,chnl,1,ADC_SampleTime_480Cycles);
ADC_SoftwareStartConv(ADC1);
while(ADC_GetSoftwareStartConvStatus(ADC1));
return ADC_GetConversionValue(ADC1);
}
float Get_CPU_Temperature(u8 ConvNumber)
{
u8 i;
u32 val = 0;
float CPU_Val;
for(i=0;i<ConvNumber;i++)
{
val += ADC1_GetVal(CPU_Temperature);
}
CPU_Val = val / ConvNumber;
CPU_Val = CPU_Val*3.3/4096;
CPU_Val = (CPU_Val-0.76)/0.0025 + 25;
return CPU_Val;
}
float Get_VBAT_Voltage(u8 ConvNumber)
{
u8 i;
u32 val = 0;
float VBAT_Val;
for(i=0;i<ConvNumber;i++)
{
val += ADC1_GetVal(VBAT);
}
VBAT_Val = val / ConvNumber;
VBAT_Val = VBAT_Val*3.3/4096;
VBAT_Val *= 2;
return VBAT_Val;
}
#define CPU_Temperature ADC_Channel_16
#define VBAT ADC_Channel_17
2-> 为什么我代码采取分时复用的方式测量 “内部温度” 和 “VBAT” 的值不行,只测量一个就是正确的?
只测量CPU温度如下:
for(;;)
{
sprintf(LCD_Buffer,"CPU_Temperature:%7.2f C",Get_CPU_Temperature(5));
LCD_ShowString(80,110,500,24,24,LCD_Buffer);
// sprintf(LCD_Buffer,"VBAT_Voltage :%7.3f V",Get_VBAT_Voltage(5));
// LCD_ShowString(80,140,500,24,24,LCD_Buffer);
LED0=!LED0;
delay_ms(1000);
}
只测量电压如下:
for(;;)
{
// sprintf(LCD_Buffer,"CPU_Temperature:%7.2f C",Get_CPU_Temperature(5));
// LCD_ShowString(80,110,500,24,24,LCD_Buffer);
sprintf(LCD_Buffer,"VBAT_Voltage :%7.3f V",Get_VBAT_Voltage(5));
LCD_ShowString(80,140,500,24,24,LCD_Buffer);
LED0=!LED0;
delay_ms(1000);
}
温度和电压都测量如下:
for(;;)
{
sprintf(LCD_Buffer,"CPU_Temperature:%7.2f C",Get_CPU_Temperature(5));
LCD_ShowString(80,110,500,24,24,LCD_Buffer);
sprintf(LCD_Buffer,"VBAT_Voltage :%7.3f V",Get_VBAT_Voltage(5));
LCD_ShowString(80,140,500,24,24,LCD_Buffer);
LED0=!LED0;
delay_ms(1000);
}
Vrefint测出的值在 2.428 V ~ 2.446 V之间
谢谢原子哥,为什么同时检测就会出错呢
一周热门 更多>