你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

stm32l431RC ADC 采集Vbat 不准的问题

[复制链接]
zhaoxuji-239467 发布时间:2020-5-11 13:08
系统电池供电,3.6V电池,经过一个二极管(3A),大概是3.3V到Vbat .
; i+ Z# @( v5 B, M$ N* E! m2 }测量电压为2.98V 左右。+ F- N4 `5 O: j. ?$ ^4 n3 Y* A
继续采用直流电源供电,当输入Vbat 3.0v 时,测量为 2.86V左右。
& F2 f, x, @  @, C# p3 o4 W0 v同时还发现一些怪现象,aADCxConvertedData[0],明显比后续的采集值小很多。
/ }2 v; l1 @0 Z( w哪里操作有问题?. b& |: [2 r% g/ J

$ L0 c" h! a  c/ f6 u
$ t' ~: q  r$ `; M: t( B

原理图

原理图

5 L3 Y: \) s' q  g- R  ~" p/ o; |6 ^( F9 i# H
/* Definition of ADCx conversions data table size */
1 L4 O- U7 t/ c' P6 p2 {9 n6 H#define ADC_CONVERTED_DATA_BUFFER_SIZE   ((uint32_t)  10)   /* Size of array aADCxConvertedData[] */
! l* o. S+ W; Z" Rstatic uint16_t   aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE];% V$ ]0 `1 y) o% n' O2 t
/**1 i% m. _, F' L' Y: Q
  * @brief  Conversion complete callback in non-blocking mode.6 D2 G+ a" {5 z, a$ v: o* d
  * @param hadc ADC handle
+ A+ f# ]) G4 q# h$ X. h  * @retval None9 k/ ?$ \: Q) A) Y) F6 c
  */5 \; Q, @* _0 `. ~! P- ^4 U
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
2 G$ r0 @9 a3 e$ d- N+ b4 E' q{
* z/ A) d" N8 f5 X  /* Prevent unused argument(s) compilation warning */  u: w; I& S9 @/ K& ~
        if(BinarySem_ADCHandle)
+ `8 R, s1 b9 q9 \) M4 ]  @; q( x                osSemaphoreRelease(BinarySem_ADCHandle);
; P& ?5 A1 l2 V8 n  K. F' ?+ ]+ Z0 P- ]  R7 x$ r+ F$ ~
  /* NOTE : This function should not be modified. When the callback is needed,
; K/ k2 d8 r4 B  I0 Q# \9 C% T            function HAL_ADC_ConvCpltCallback must be implemented in the user file.0 g4 m5 x3 f3 j9 `
   */) F, b6 D. j- ~2 j# K( K& J( T- t; G
}
& a, p' s+ M2 c) S0 ?/**1 T# g$ l  m3 M! G& r& c
  * @brief  测量电池电压
; |( l2 [! f( K4 {  @  * @param[IN]& A! m6 R/ R* ^# `4 a# `/ }7 |
  * @retval None: X/ g) X% q8 k; g$ T$ e2 N1 G
  */- g4 W' w8 D: D5 Z0 e5 ?
uint32_t getBattaryTemperatureMeasure(uint8_t bat_flag)
. y: ]. r  j: [5 ?( K{
2 B- `# x- O1 r$ w6 v) D: f          ADC_ChannelConfTypeDef sConfig = {0};- g7 O; @" X0 ?7 c7 N  N+ a% V

5 @7 _$ u4 v4 G0 _! _3 r          memset(aADCxConvertedData,0,sizeof(aADCxConvertedData));
. h$ x& y. r& v$ c' E- A8 F          /* ### - 1 - Initialize ADC peripheral #################################### */- a. d) q- z. V4 ?
          hadc1.Instance          = ADC1;
( i& ~) \% [4 K5 g          if (HAL_ADC_DeInit(&hadc1) != HAL_OK)
) _9 K" n4 O5 ]: V          {4 T2 K# s* Q% g( f8 Q( b7 n3 ^
            /* ADC de-initialization Error */# U$ Y. o0 ]4 _( I0 q& |$ }3 j) L
            Error_Handler();7 H, W) Q" p/ C0 b& w4 |+ c' Q: G* j( Q' J9 ]
          }
7 u/ i) B2 F7 h- R, n' L. E: e0 i$ v- s
          hadc1.Init.ClockPrescaler        = ADC_CLOCK_SYNC_PCLK_DIV1;      /* Synchronous clock mode, input ADC clock divided by 2*/4 M# b1 m( @; d8 r% W. @1 Q+ J
          hadc1.Init.Resolution            = ADC_RESOLUTION_12B;            /* 12-bit resolution for converted data */  g' D( B4 B) Q8 [
          hadc1.Init.DataAlign             = ADC_DATAALIGN_RIGHT;           /* Right-alignment for converted data */
9 ]+ }7 [# d. v, ]7 i: p          hadc1.Init.ScanConvMode          = DISABLE;                       /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */9 C3 E2 z9 a' s& X
          hadc1.Init.EOCSelection          = ADC_EOC_SINGLE_CONV;           /* EOC flag picked-up to indicate conversion end */) E: E" v8 E4 W' G6 X1 E+ O
          hadc1.Init.LowPowerAutoWait      = DISABLE;                       /* Auto-delayed conversion feature disabled */7 A8 T4 {3 r7 x1 U; p' P
          hadc1.Init.ContinuousConvMode    = ENABLE;                        /* Continuous mode enabled (automatic conversion restart after each conversion) */
4 H- B! Y" K) P7 N6 M. v: J: Y          hadc1.Init.NbrOfConversion       = 1;                             /* Parameter discarded because sequencer is disabled */
( ?* ]& z# B6 W  }) r7 n          hadc1.Init.DiscontinuousConvMode = DISABLE;                       /* Parameter discarded because sequencer is disabled */
2 ?! Q0 x5 X; [& {, L6 w3 @8 a, l          hadc1.Init.NbrOfDiscConversion   = 1;                             /* Parameter discarded because sequencer is disabled */% Z, [7 t  {) J# ^" l, k
          hadc1.Init.ExternalTrigConv      = ADC_SOFTWARE_START;            /* Software start to trig the 1st conversion manually, without external event */
! ?5 |- e/ K% u* d          hadc1.Init.ExternalTrigConvEdge  = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */. M# X7 q4 b* @% {
          hadc1.Init.DMAContinuousRequests = ENABLE;                        /* ADC DMA continuous request to match with DMA circular mode */" E: m& b, n' R2 }1 ~. z
          hadc1.Init.Overrun               = ADC_OVR_DATA_OVERWRITTEN;      /* DR register is overwritten with the last conversion result in case of overrun */
/ C7 W" i# S6 ~          hadc1.Init.OversamplingMode      = DISABLE;                       /* No oversampling */( P& ^$ V9 m" i2 K% i( M2 D
          /* Initialize ADC peripheral according to the passed parameters */
' L4 a* P" ], `+ F- X- y          if (HAL_ADC_Init(&hadc1) != HAL_OK)
$ _9 w; ]' J% c( J( U6 ^          {2 R: Z: N) B: U% v& u  {' T
            Error_Handler();' i  C& x5 P! G, S
          }6 Z0 Z/ N% e( X
9 G3 Q. ^/ c& N
% ~/ j) m( h$ h% I% h
          /* ### - 2 - Start calibration ############################################ */
( J# e+ a: }* b" V9 m3 d- S          if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) !=  HAL_OK)
6 c- x3 y9 s. @, K8 V          {
! A; Z6 G1 H6 h0 C4 R* W! y' C4 D            Error_Handler();
3 p* V. @- s- _! D+ ]! K# S2 p          }
  x7 }+ q. D, }6 ~, l$ I* Z( L0 d
          /* ### - 3 - Channel configuration ######################################## */& w. Q& f$ F9 f7 {3 T: G
          sConfig.Channel      = ADC_CHANNEL_VBAT;                /* Sampled channel number */5 K7 A0 }  j- G: g2 ^# D
          sConfig.Rank         = ADC_REGULAR_RANK_1;          /* Rank of sampled channel number ADCx_CHANNEL */7 |  A! r' o+ g. A, G, x0 _2 ]/ P
          sConfig.SamplingTime = ADC_SAMPLETIME_6CYCLES_5;   /* Sampling time (number of clock cycles unit) */
+ D5 o1 ?, p: j* O# e, W; {- P          sConfig.SingleDiff   = ADC_SINGLE_ENDED;            /* Single-ended input channel */
% X" {7 S, P2 P$ f          sConfig.OffsetNumber = ADC_OFFSET_NONE;             /* No offset subtraction */
: H% M( F/ ?. m) k6 B2 c          sConfig.Offset = 0;                                 /* Parameter discarded because offset correction is disabled */8 w3 T) M5 U0 `, F; y; G
          if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
5 U! H5 G* B/ a5 e0 E          {7 ]2 G5 B4 p3 ?# z$ \8 e6 D
            Error_Handler();
% ^4 L$ T2 n, i8 p          }
; \3 y# u: Q3 T/ @5 E/ \5 _9 q7 s2 @
          /* ### - 4 - Start conversion in DMA mode ################################# */
0 @; Y9 u9 E( a5 Y) L          if (HAL_ADC_Start_DMA(&hadc1,0 Y! Y+ S- R& @/ k; q2 z
                                (uint32_t *)aADCxConvertedData,
, w# Z% E9 V0 A1 e* J                                ADC_CONVERTED_DATA_BUFFER_SIZE7 r) t7 U/ e+ M( N
                               ) != HAL_OK)
& ?  U. I5 s8 A* O' m- ]  V$ ~          {6 L& y7 |% R( s; r) F& x. u$ |
            Error_Handler();& o3 T! f* E/ v' I- U
          }9 `6 V2 {1 q- @9 R( l# U( {
          uint32_t ret = 0 ;- Y. g5 p/ i$ s# X2 ~" A  r* u
          if(osOK == osSemaphoreWait(BinarySem_ADCHandle,10))
  j7 N# ?# x" \) P$ ]          {
# _; |% w8 t5 L                  uint32_t adc_val = 0;//aADCxConvertedData[1];5 ]7 U6 e' g: d
                  for (int i = ADC_CONVERTED_DATA_BUFFER_SIZE/2 ; i < ADC_CONVERTED_DATA_BUFFER_SIZE ; i++)$ d, X* P5 \+ L* V" {$ M& y
                  {* l3 B8 w( A* o% P7 Z  H
                          adc_val += aADCxConvertedData;
; W: _" R  _4 G3 H                  }: f$ _+ ~5 J* i, S* b
                  adc_val = adc_val  / (ADC_CONVERTED_DATA_BUFFER_SIZE/2);
: d! E: ~  X+ z                  ret = __HAL_ADC_CALC_DATA_TO_VOLTAGE(2500,adc_val,ADC_RESOLUTION_12B);* m1 Y7 \4 P' b$ ]
                  ret *= 3;* ?; g! @' `8 @
          }+ I7 Y* k4 O) K1 M
5 W3 t0 d) X( [% r; B8 H
          return (ret);
( P) N1 M/ ~8 V}+ E6 ?5 m+ C! m  |% v
0 S. p2 F" T* ?& h" X
( M; t1 r1 W% a. ~
赞 收藏 评论1 发布时间:2020-5-11 13:08

举报

1个回答
zhaoxuji-239467 回答时间:2020-5-14 09:13:46
通过两天调试,讲采样周期设置长一些,比较接近了。要大于 ADC_SAMPLETIME_12CYCLES_5  。技术支持一直没响应。
关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版