STM32G030系列ADC校准

用LL库编写STM32G030F6P6的ADC功能时,需要校准ADC,使用下列代码校准

LL_ADC_EnableInternalRegulator(ADC1);
delay_us(100);
LL_ADC_StartCalibration(ADC1); 
while( LL_ADC_IsCalibrationOnGoing(ADC1)); 
LL_ADC_Enable(ADC1);

手册中的相关描述

14.3.3 Calibration (ADCAL) The ADC has a calibration feature. During the procedure, the ADC calculates a calibration factor which is
internally applied to the ADC until the next ADC power-off. The
application must not use the ADC during calibration and must wait
until it is complete. Calibration should be performed before starting
A/D conversion. It removes the offset error which may vary from chip
to chip due to process variation. The calibration is initiated by
software by setting bit ADCAL = 1. Calibration can only be initiated
when the ADC voltage regulator is enabled (ADVREGEN = 1 and
tADCVREG_SETUP has elapsed) and the ADC is disabled (when ADEN = 0).
ADCAL bit stays at 1 during all the calibration sequence. It is then
cleared by hardware as soon the calibration completes. After this,
the calibration factor can be read from the ADC_DR register (from bits
6 to 0). The internal analog calibration is kept if the ADC is
disabled (ADEN = 0). When the ADC operating conditions change (VDDA
changes are the main contributor to ADC offset variations and
temperature change to a lesser extend), it is recommended to re-run a
calibration cycle. The calibration factor is lost in the following
cases: • The power supply is removed from the ADC (for example when
the product enters STANDBY or VBAT mode) • The ADC peripheral is
reset. The calibration factor is lost each time power is removed from
the ADC (for example when the product enters Standby or VBAT mode).
Still, it is possible to save and restore the calibration factor by
software to save time when re-starting the ADC (as long as temperature
and voltage are stable during the ADC power-down). The calibration
factor can be written if the ADC is enabled but not converting (ADEN =
1 and ADSTART = 0). Then, at the next start of conversion, the
calibration factor is automatically injected into the analog ADC.
This loading is transparent and does not add any cycle latency to the
start of the conversion. Software calibration procedure

  1. Ensure that ADEN = 0, ADVREGEN = 1 and DMAEN = 0.
  2. Set ADCAL = 1.
  3. Wait until ADCAL = 0 (or until EOCAL = 1). This can be handled by interrupt if the interrupt is enabled by setting the EOCALIE bit in
    the ADC_IER register
  4. The calibration factor can be read from bits 6:0 of ADC_DR or ADC_CALFACT registers. Calibration factor forcing Software Procedure
  5. Ensure that ADEN = 1 and ADSTART = 0 (ADC started with no conversion ongoing)
  6. Write ADC_CALFACT with the saved calibration factor
  7. The calibration factor is used as soon as a new conversion is launched.
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值