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

stm32l431RC ADC 采集Vbat 不准的问题

[复制链接]
zhaoxuji-239467 发布时间:2020-5-11 13:08
系统电池供电,3.6V电池,经过一个二极管(3A),大概是3.3V到Vbat .
' u  n  f; a; r: j+ G  k0 ^测量电压为2.98V 左右。0 ~" R4 ?+ m7 d
继续采用直流电源供电,当输入Vbat 3.0v 时,测量为 2.86V左右。7 A" L5 F$ i! N5 Z
同时还发现一些怪现象,aADCxConvertedData[0],明显比后续的采集值小很多。; n0 E% e5 f! u6 ~' A; b9 k
哪里操作有问题?
! x8 f0 \+ H+ J9 y7 W2 ~* w2 S2 @4 O3 O- x, w) B& ^3 N
9 r3 i; }: t/ U9 |

原理图

原理图

, O1 H- y* F, ]6 [# {$ y* A+ a
& O7 U& i* a4 g' }. R/* Definition of ADCx conversions data table size */1 f  f% N% k# {
#define ADC_CONVERTED_DATA_BUFFER_SIZE   ((uint32_t)  10)   /* Size of array aADCxConvertedData[] */
4 X# V2 u3 g$ V$ astatic uint16_t   aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE];
0 w& L( W  B7 [( O/**8 m/ q1 R3 x1 C2 Z, [* ~
  * @brief  Conversion complete callback in non-blocking mode.
9 ^: D# [) {+ X0 W* k! O2 _  * @param hadc ADC handle
/ r/ h% S. X& ]- _+ k  * @retval None
; x5 @4 y" [( ]0 P8 ]- r  */% z. t* E8 H8 e: {- v3 _
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
5 K) m) c# @) a2 Z) x{
9 O2 f: ?! ?1 \$ b  /* Prevent unused argument(s) compilation warning */8 v8 R3 D! ?6 T9 H" I
        if(BinarySem_ADCHandle)
4 c! O3 L/ ?8 S$ U2 _                osSemaphoreRelease(BinarySem_ADCHandle);( U5 D, F1 r, H4 d

+ k( f7 @" V' @6 H; e& b  /* NOTE : This function should not be modified. When the callback is needed," P  ^9 |, W' d& j/ ~0 V
            function HAL_ADC_ConvCpltCallback must be implemented in the user file.
1 y4 q  B' q5 ?7 J   */) G% \8 k  l5 `/ n1 V1 i
}
/ M, n! J6 O% `6 {1 P/**
. Q# u9 ^, I# L' ~  * @brief  测量电池电压
8 s5 @) G; y) K9 m- d  * @param[IN]
% T+ q: z" p0 S3 C/ W  c( [  * @retval None
1 k! R0 _8 q0 z4 \  */' Q' P4 ]* F2 L/ q$ e, v
uint32_t getBattaryTemperatureMeasure(uint8_t bat_flag)
1 b9 C; d- Y8 o  H) x; F{
" s7 G1 T3 h2 ]) i          ADC_ChannelConfTypeDef sConfig = {0};
7 B- o! s8 b- v4 s+ h3 X8 s
, V/ W4 X& r  U* ]% N          memset(aADCxConvertedData,0,sizeof(aADCxConvertedData));: R7 k9 W- C8 `6 l! d7 z' Y
          /* ### - 1 - Initialize ADC peripheral #################################### */
- P. c6 o0 R' F# _/ ?, S1 T          hadc1.Instance          = ADC1;5 [. j( G% s8 f7 l7 T& L! E2 |! ?
          if (HAL_ADC_DeInit(&hadc1) != HAL_OK)2 M; `/ {8 M8 x
          {. }& H' ^% T' R1 S; X
            /* ADC de-initialization Error */  J* I. L# r3 H7 @+ O3 Y. ^3 U
            Error_Handler();+ S3 D9 I( ^1 U
          }* h2 O6 h" q# N' v+ t

4 A2 \9 ~9 g# n# D2 e' \, r: |          hadc1.Init.ClockPrescaler        = ADC_CLOCK_SYNC_PCLK_DIV1;      /* Synchronous clock mode, input ADC clock divided by 2*/
! Y3 [8 p7 j& O- @& S3 z- Q          hadc1.Init.Resolution            = ADC_RESOLUTION_12B;            /* 12-bit resolution for converted data */
5 s7 G4 D/ T$ w2 K) b( y          hadc1.Init.DataAlign             = ADC_DATAALIGN_RIGHT;           /* Right-alignment for converted data */
9 [( Z2 V) O7 z7 a+ F4 H' R6 w          hadc1.Init.ScanConvMode          = DISABLE;                       /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
6 O3 A+ o; m, D) t          hadc1.Init.EOCSelection          = ADC_EOC_SINGLE_CONV;           /* EOC flag picked-up to indicate conversion end */7 u" c) b8 T4 j
          hadc1.Init.LowPowerAutoWait      = DISABLE;                       /* Auto-delayed conversion feature disabled */9 l6 X& d- E$ D  o$ ]; g. ^  U+ r
          hadc1.Init.ContinuousConvMode    = ENABLE;                        /* Continuous mode enabled (automatic conversion restart after each conversion) */
& b5 U# E# E- X1 N$ P- {) Q          hadc1.Init.NbrOfConversion       = 1;                             /* Parameter discarded because sequencer is disabled */+ j9 m* J3 A) q! t
          hadc1.Init.DiscontinuousConvMode = DISABLE;                       /* Parameter discarded because sequencer is disabled */
9 Z7 D- A3 A+ H          hadc1.Init.NbrOfDiscConversion   = 1;                             /* Parameter discarded because sequencer is disabled */
) e3 ~; G; U" |8 c          hadc1.Init.ExternalTrigConv      = ADC_SOFTWARE_START;            /* Software start to trig the 1st conversion manually, without external event */) X" X3 K. c* Y% w
          hadc1.Init.ExternalTrigConvEdge  = ADC_EXTERNALTRIGCONVEDGE_NONE; /* Parameter discarded because software trigger chosen */2 ?6 s, i  E; M
          hadc1.Init.DMAContinuousRequests = ENABLE;                        /* ADC DMA continuous request to match with DMA circular mode */
- C/ B$ x7 H3 N  Q          hadc1.Init.Overrun               = ADC_OVR_DATA_OVERWRITTEN;      /* DR register is overwritten with the last conversion result in case of overrun */
4 E7 [$ @$ H% w          hadc1.Init.OversamplingMode      = DISABLE;                       /* No oversampling */
' C& f3 C# ~3 m! s          /* Initialize ADC peripheral according to the passed parameters */
5 |! T3 W, i; w' ~# m5 H          if (HAL_ADC_Init(&hadc1) != HAL_OK)+ n9 `8 j7 z! a6 |8 M" t
          {
3 t( X9 p; `. f3 X; p  c* u2 m            Error_Handler();
$ M: `1 F, j6 j" M" h; i          }$ |+ A& O2 X3 O" O3 v

: l5 K" f( q% V/ x- v7 T/ |1 C2 d; C6 R
          /* ### - 2 - Start calibration ############################################ */
$ z; \5 V3 y" g0 d4 F6 s: t0 \  r          if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED) !=  HAL_OK)' d4 X- k' n& X
          {
* _9 v+ e6 Z7 R( Y& I/ Q& M9 i5 D            Error_Handler();  U4 ~  \3 Z" r) J1 p
          }' D; R1 N% ~  Z$ J6 w) l6 x
* ]8 _& t6 W3 b! p8 R+ ]3 E
          /* ### - 3 - Channel configuration ######################################## */" \2 P; G$ r  |' b
          sConfig.Channel      = ADC_CHANNEL_VBAT;                /* Sampled channel number */
8 v" z' D! i9 o! K# l          sConfig.Rank         = ADC_REGULAR_RANK_1;          /* Rank of sampled channel number ADCx_CHANNEL */
0 z4 |2 d7 e5 C* x          sConfig.SamplingTime = ADC_SAMPLETIME_6CYCLES_5;   /* Sampling time (number of clock cycles unit) */
' n+ C. ~6 _) N4 Q          sConfig.SingleDiff   = ADC_SINGLE_ENDED;            /* Single-ended input channel */: k/ H6 ?7 ?: p: z2 E* D* D0 e3 W! Y
          sConfig.OffsetNumber = ADC_OFFSET_NONE;             /* No offset subtraction */
' ?; h' X1 s$ s( j          sConfig.Offset = 0;                                 /* Parameter discarded because offset correction is disabled */
' }4 E* }0 g0 Y) v- P+ r          if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
5 p- A$ s: W" ?7 ^          {
, g! A/ a6 l7 }- ]            Error_Handler();( T4 x0 W# U( R9 r- g
          }
$ z' u; @# s. l6 k5 u
7 L% ~* q0 n$ {+ r          /* ### - 4 - Start conversion in DMA mode ################################# */  {& m* j0 O- D: f# o! X% a
          if (HAL_ADC_Start_DMA(&hadc1,
2 G( L$ ]6 l5 P7 X8 T& s4 f4 S                                (uint32_t *)aADCxConvertedData,
& z) r2 `, @  G0 r                                ADC_CONVERTED_DATA_BUFFER_SIZE. x) t5 |7 ^2 d: y; u
                               ) != HAL_OK)
8 Q: _/ h+ {% V$ G$ I& w          {1 u  O6 V2 M4 T- _3 {2 j% n
            Error_Handler();5 _8 u; ~: T! L5 x2 f$ K
          }
# N, k4 y- _: R6 }0 v          uint32_t ret = 0 ;5 C% N. m: u4 f. s5 S
          if(osOK == osSemaphoreWait(BinarySem_ADCHandle,10))
+ Z6 i3 U1 m. N+ g% ?8 A          {" U" i2 r* [/ G+ S. L
                  uint32_t adc_val = 0;//aADCxConvertedData[1];% C5 ~) [$ Q! _
                  for (int i = ADC_CONVERTED_DATA_BUFFER_SIZE/2 ; i < ADC_CONVERTED_DATA_BUFFER_SIZE ; i++)$ R: G9 k$ e( V  ]/ b- Z
                  {
- R5 e+ _* g' f8 \, v: \                          adc_val += aADCxConvertedData;" [/ D5 N, u9 b
                  }# L7 Z3 t+ S, i9 B$ V6 M3 z2 k
                  adc_val = adc_val  / (ADC_CONVERTED_DATA_BUFFER_SIZE/2);" w; M" c% `' x) H* i3 x
                  ret = __HAL_ADC_CALC_DATA_TO_VOLTAGE(2500,adc_val,ADC_RESOLUTION_12B);! j/ {  h; t! f% O
                  ret *= 3;8 S1 \$ ?" Q# O/ I9 o; L  w; e
          }" F' B& s2 T* G& Z- V" w! I/ r
& q3 R  H! N9 H# a6 u4 ^' Q* E$ @
          return (ret);
7 |( X" L( T- R, h9 f}
( ~# x* E% f9 b0 L  h& m& _+ Q
9 }1 B8 a% C7 C& i; [: S8 N5 N5 [0 j' u; }% ^+ x$ o, T/ a( ]
收藏 评论1 发布时间:2020-5-11 13:08

举报

1个回答
zhaoxuji-239467 回答时间:2020-5-14 09:13:46
通过两天调试,讲采样周期设置长一些,比较接近了。要大于 ADC_SAMPLETIME_12CYCLES_5  。技术支持一直没响应。

所属标签

相似分享

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版