Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tools-mirror
Micropython
提交
0555ada2
M
Micropython
项目概览
tools-mirror
/
Micropython
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Micropython
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0555ada2
编写于
12月 12, 2018
作者:
D
Damien George
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stm32/adc: Fix calibrated volt/temp readings on H7 by using 16bit scale.
上级
1b4031ed
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
23 deletion
+16
-23
ports/stm32/adc.c
ports/stm32/adc.c
+16
-23
未找到文件。
ports/stm32/adc.c
浏览文件 @
0555ada2
...
...
@@ -67,6 +67,7 @@
#define ADC_CAL_ADDRESS (0x1ffff7ba)
#define ADC_CAL1 ((uint16_t*)0x1ffff7b8)
#define ADC_CAL2 ((uint16_t*)0x1ffff7c2)
#define ADC_CAL_BITS (12)
#elif defined(STM32F4)
...
...
@@ -76,6 +77,7 @@
#define ADC_CAL_ADDRESS (0x1fff7a2a)
#define ADC_CAL1 ((uint16_t*)(ADC_CAL_ADDRESS + 2))
#define ADC_CAL2 ((uint16_t*)(ADC_CAL_ADDRESS + 4))
#define ADC_CAL_BITS (12)
#elif defined(STM32F7)
...
...
@@ -91,6 +93,7 @@
#define ADC_CAL1 ((uint16_t*)(ADC_CAL_ADDRESS + 2))
#define ADC_CAL2 ((uint16_t*)(ADC_CAL_ADDRESS + 4))
#define ADC_CAL_BITS (12)
#elif defined(STM32H7)
...
...
@@ -100,6 +103,7 @@
#define ADC_CAL_ADDRESS (0x1FF1E860)
#define ADC_CAL1 ((uint16_t*)(0x1FF1E820))
#define ADC_CAL2 ((uint16_t*)(0x1FF1E840))
#define ADC_CAL_BITS (16)
#define ADC_CHANNEL_VBAT ADC_CHANNEL_VBAT_DIV4
#elif defined(STM32L4)
...
...
@@ -110,6 +114,7 @@
#define ADC_CAL_ADDRESS (0x1fff75aa)
#define ADC_CAL1 ((uint16_t*)(ADC_CAL_ADDRESS - 2))
#define ADC_CAL2 ((uint16_t*)(ADC_CAL_ADDRESS + 0x20))
#define ADC_CAL_BITS (12)
#else
...
...
@@ -149,7 +154,7 @@
#define CORE_TEMP_AVG_SLOPE (3)
/* (2.5mv/3.3v)*(2^ADC resoultion) */
// scale and calibration values for VBAT and VREF
#define ADC_SCALE (ADC_SCALE_V /
4095
)
#define ADC_SCALE (ADC_SCALE_V /
((1 << ADC_CAL_BITS) - 1)
)
#define VREFIN_CAL ((uint16_t *)ADC_CAL_ADDRESS)
typedef
struct
_pyb_obj_adc_t
{
...
...
@@ -699,13 +704,14 @@ int adc_get_resolution(ADC_HandleTypeDef *adcHandle) {
return
12
;
}
int
adc_read_core_temp
(
ADC_HandleTypeDef
*
adcHandle
)
{
int32_t
raw_value
=
adc_config_and_read_channel
(
adcHandle
,
ADC_CHANNEL_TEMPSENSOR
);
// Note: constants assume 12-bit resolution, so we scale the raw value to
// be 12-bits.
raw_value
<<=
(
12
-
adc_get_resolution
(
adcHandle
));
STATIC
uint32_t
adc_config_and_read_ref
(
ADC_HandleTypeDef
*
adcHandle
,
uint32_t
channel
)
{
uint32_t
raw_value
=
adc_config_and_read_channel
(
adcHandle
,
channel
);
// Scale raw reading to the number of bits used by the calibration constants
return
raw_value
<<
(
ADC_CAL_BITS
-
adc_get_resolution
(
adcHandle
));
}
int
adc_read_core_temp
(
ADC_HandleTypeDef
*
adcHandle
)
{
int32_t
raw_value
=
adc_config_and_read_ref
(
adcHandle
,
ADC_CHANNEL_TEMPSENSOR
);
return
((
raw_value
-
CORE_TEMP_V25
)
/
CORE_TEMP_AVG_SLOPE
)
+
25
;
}
...
...
@@ -714,31 +720,18 @@ int adc_read_core_temp(ADC_HandleTypeDef *adcHandle) {
STATIC
volatile
float
adc_refcor
=
1
.
0
f
;
float
adc_read_core_temp_float
(
ADC_HandleTypeDef
*
adcHandle
)
{
int32_t
raw_value
=
adc_config_and_read_channel
(
adcHandle
,
ADC_CHANNEL_TEMPSENSOR
);
// constants assume 12-bit resolution so we scale the raw value to 12-bits
raw_value
<<=
(
12
-
adc_get_resolution
(
adcHandle
));
int32_t
raw_value
=
adc_config_and_read_ref
(
adcHandle
,
ADC_CHANNEL_TEMPSENSOR
);
float
core_temp_avg_slope
=
(
*
ADC_CAL2
-
*
ADC_CAL1
)
/
80
.
0
;
return
(((
float
)
raw_value
*
adc_refcor
-
*
ADC_CAL1
)
/
core_temp_avg_slope
)
+
30
.
0
f
;
}
float
adc_read_core_vbat
(
ADC_HandleTypeDef
*
adcHandle
)
{
uint32_t
raw_value
=
adc_config_and_read_channel
(
adcHandle
,
ADC_CHANNEL_VBAT
);
// Note: constants assume 12-bit resolution, so we scale the raw value to
// be 12-bits.
raw_value
<<=
(
12
-
adc_get_resolution
(
adcHandle
));
uint32_t
raw_value
=
adc_config_and_read_ref
(
adcHandle
,
ADC_CHANNEL_VBAT
);
return
raw_value
*
VBAT_DIV
*
ADC_SCALE
*
adc_refcor
;
}
float
adc_read_core_vref
(
ADC_HandleTypeDef
*
adcHandle
)
{
uint32_t
raw_value
=
adc_config_and_read_channel
(
adcHandle
,
ADC_CHANNEL_VREFINT
);
// Note: constants assume 12-bit resolution, so we scale the raw value to
// be 12-bits.
raw_value
<<=
(
12
-
adc_get_resolution
(
adcHandle
));
uint32_t
raw_value
=
adc_config_and_read_ref
(
adcHandle
,
ADC_CHANNEL_VREFINT
);
// update the reference correction factor
adc_refcor
=
((
float
)(
*
VREFIN_CAL
))
/
((
float
)
raw_value
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录