Skip to content

Commit f8b0f21

Browse files
committed
Merge branch 'fix/esp_bldc_control_drag' into 'master'
fix: Modify drag time type and filter cap See merge request ae_group/esp-iot-solution!1026
2 parents 5460c83 + c358714 commit f8b0f21

23 files changed

+547
-102
lines changed

components/.build-rules.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ components/motor/esp_sensorless_bldc_control/test_apps/bldc_adc:
3939
- if: SOC_MCPWM_SUPPORTED == 1
4040

4141
components/motor/esp_sensorless_bldc_control/test_apps/bldc_comparer:
42-
disable:
43-
- if: IDF_TARGET in ["esp32c2"]
42+
enable:
43+
- if: SOC_MCPWM_SUPPORTED == 1
4444

4545
components/led/lightbulb_driver/test_apps:
4646
enable:

components/motor/esp_sensorless_bldc_control/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# ChangeLog
22

3+
4+
## v0.3.0 - 2024-6-20
5+
6+
### Bug fix
7+
8+
* Fix drag time and modify the filter cap to type uint32_t
9+
* Fix Comparator Acquisition Method for MCPWM Trigger
10+
311
## v0.2.0 - 2023-11-14
412

513
### Enhancements

components/motor/esp_sensorless_bldc_control/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
[![Component Registry](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control/badge.svg)](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control)
22

3-
## ESP Sensorless bldc control 组件介绍
3+
## ESP Sensorless BLDC Control Component Introduction
44

5-
``esp_sensorless_bldc_control`` 是基于 ESP32 系列芯片的 BLDC 无感方波控制库,支持以下功能:
5+
``esp_sensorless_bldc_control`` is a sensorless BLDC control library based on ESP32 series chips, supporting the following features:
66

7-
* 支持基于 ADC 采样检测过零点
8-
* 支持基于比较器检测过零点
9-
* 支持基于脉冲法实现转子初始相位检测
10-
* 支持堵转保护
11-
* 支持过流,过欠压保护[feature]
12-
* 支持缺相保护[feature]
7+
* Supports zero-crossing detection based on ADC sampling
8+
* Supports zero-crossing detection based on comparators
9+
* Supports initial rotor position detection using pulse method
10+
* Supports stall protection
11+
* Supports overcurrent and undervoltage protection [feature]
12+
* Supports phase loss protection [feature]
1313

14-
### ESP Sensorless bldc control 用户指南
14+
### ESP Sensorless BLDC Control User Guide
1515

16-
请参考https://docs.espressif.com/projects/esp-iot-solution/zh_CN/latest/motor/index.html
16+
Please refer tohttps://docs.espressif.com/projects/esp-iot-solution/zh_CN/latest/motor/index.html
1717

18-
### 添加组件到工程
18+
### Adding the Component to Your Project
1919

20-
1. 请使用组件管理器指令 `add-dependency` `esp_sensorless_bldc_control` 添加到项目的依赖项, 在 `CMake` 执行期间该组件将被自动下载到工程目录。
20+
1. Use the component manager command `add-dependency` to add `esp_sensorless_bldc_control` to your project's dependencies. The component will be automatically downloaded to the project directory during `CMake` execution.
2121

2222
```
2323
idf.py add-dependency "espressif/esp_sensorless_bldc_control=*"
2424
```
2525
26-
2. `esp_sensorless_bldc_control/user_cfg/bldc_user_cfg.h.tpl` 文件复制到工程目录下,并更名为 `bldc_user_cfg.h`。并在 `main/CMakeLists.txt` 文件中加入:
26+
2. Copy the `esp_sensorless_bldc_control/user_cfg/bldc_user_cfg.h` file to your project directory and rename it to `bldc_user_cfg.h`. Add the following to your `main/CMakeLists.txt` file:
2727
2828
```
2929
idf_component_get_property(bldc_lib espressif__esp_sensorless_bldc_control COMPONENT_LIB)
3030
cmake_policy(SET CMP0079 NEW)
3131
target_link_libraries(${bldc_lib} PUBLIC ${COMPONENT_LIB})
3232
```
3333
34-
Note: 该文件用于设置电机控制相关参数,一定要包含在工程中。
34+
Note: This file is used to set motor control related parameters and must be included in the project.
3535
36-
## 使用示例
36+
## Example Usage
3737
3838
```C
3939
esp_event_loop_create_default();

components/motor/esp_sensorless_bldc_control/bldc_control.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -103,13 +103,19 @@ esp_err_t bldc_control_init(bldc_control_handle_t *handle, bldc_control_config_t
103103
xTaskCreate(bldc_control_task, "bldc_control_task", 1024 * 4, control, 10, NULL);
104104

105105
switch (config->alignment_mode) {
106-
case ALIGNMENT_COMPARER:
106+
case ALIGNMENT_COMPARER: {
107107
ret = bldc_zero_cross_comparer_init(&control->zero_cross_handle, &config->zero_cross_comparer_config, &control->control_param);
108108
BLDC_CHECK_GOTO(ret == ESP_OK, "bldc_zero_cross_comparer_init failed", deinit);
109109
control->zero_cross = &bldc_zero_cross_comparer_operation;
110+
mcpwm_timer_event_callbacks_t cbs = {
111+
.on_full = &read_comparer_on_full,
112+
};
113+
config->six_step_config.upper_switch_config.bldc_mcpwm.cbs = &cbs;
114+
config->six_step_config.upper_switch_config.bldc_mcpwm.timer_cb_user_data = (void *)control->zero_cross_handle;
110115
break;
116+
}
111117
#if CONFIG_SOC_MCPWM_SUPPORTED
112-
case ALIGNMENT_ADC:
118+
case ALIGNMENT_ADC: {
113119
ret = bldc_zero_cross_adc_init(&control->zero_cross_handle, &config->zero_cross_adc_config, &control->control_param);
114120
BLDC_CHECK_GOTO(ret == ESP_OK, "bldc_zero_cross_comparer_init failed", deinit);
115121
control->zero_cross = &bldc_zero_cross_adc_operation;
@@ -123,6 +129,7 @@ esp_err_t bldc_control_init(bldc_control_handle_t *handle, bldc_control_config_t
123129
config->six_step_config.upper_switch_config.bldc_mcpwm.cbs = &cbs;
124130
config->six_step_config.upper_switch_config.bldc_mcpwm.timer_cb_user_data = (void *)control->zero_cross_handle;
125131
break;
132+
}
126133
#endif
127134
default:
128135
ESP_LOGE(TAG, "control_mode error");
@@ -276,6 +283,8 @@ esp_err_t bldc_control_stop(bldc_control_handle_t *handle)
276283
default:
277284
break;
278285
}
286+
287+
bldc_control_dispatch_event(BLDC_CONTROL_STOP, NULL, 0);
279288
return ESP_OK;
280289
}
281290

components/motor/esp_sensorless_bldc_control/control/bldc_zero_cross_comparer.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -15,7 +15,7 @@ typedef struct {
1515
control_param_t *control_param;
1616
int alignment_pin[PHASE_MAX];
1717
int zero_stable_flag; /*!< Over-zero stabilization flag bit */
18-
uint32_t alignment_queue_value[PHASE_MAX];
18+
uint64_t alignment_queue_value[PHASE_MAX];
1919
uint16_t queue_filter_state[PHASE_MAX]; /*!< State after three-phase filtering */
2020
} bldc_zero_cross_comparer_t;
2121

@@ -48,6 +48,13 @@ static uint8_t bldc_umef_edge(uint8_t val)
4848
return 2;
4949
}
5050

51+
bool read_comparer_on_full(mcpwm_timer_handle_t timer, const mcpwm_timer_event_data_t *edata, void *user_data)
52+
{
53+
bldc_zero_cross_comparer_t *zero_cross = (bldc_zero_cross_comparer_t *)user_data;
54+
alignment_comparer_get_value(zero_cross);
55+
return false;
56+
}
57+
5158
esp_err_t bldc_zero_cross_comparer_init(bldc_zero_cross_comparer_handle_t *handle, bldc_zero_cross_comparer_config_t *config, control_param_t *control_param)
5259
{
5360
BLDC_CHECK(config != NULL, "bldc zero cross config is NULL", ESP_ERR_INVALID_ARG);
@@ -92,7 +99,6 @@ uint8_t bldc_zero_cross_comparer_operation(void *handle)
9299

93100
bldc_zero_cross_comparer_t *zero_cross = (bldc_zero_cross_comparer_t *)handle;
94101
uint16_t filterEdge; /*!< Edge detection after filtering */
95-
alignment_comparer_get_value(zero_cross);
96102
zero_cross->control_param->speed_count++;
97103

98104
for (int i = 0; i < PHASE_MAX; i++) {

components/motor/esp_sensorless_bldc_control/control/include/bldc_control_param.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct {
5454
uint8_t phase_change_done; /*!< Motor phase change successful */
5555
uint16_t duty; /*!< duty cycle */
5656
uint16_t duty_max; /*!< duty cycle max */
57-
uint16_t drag_time; /*!< drag time */
57+
int16_t drag_time; /*!< drag time */
5858
alignment_mode_t alignment_mode; /*!< alignment mode */
5959
/* speed */
6060
uint32_t expect_speed_rpm; /*!< Expected speed */

components/motor/esp_sensorless_bldc_control/control/include/bldc_zero_cross_comparer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ typedef struct {
2222
*/
2323
typedef void *bldc_zero_cross_comparer_handle_t;
2424

25+
/**
26+
* @brief Used to detect the value of gpio when the top tube and bottom tube are open
27+
*
28+
* @param timer MCPWM timer handle
29+
* @param edata MCPWM timer event data, fed by driver
30+
* @param user_data User data, set in `mcpwm_timer_register_event_callbacks()`
31+
* @return Whether a high priority task has been waken up by this function
32+
*/
33+
bool read_comparer_on_full(mcpwm_timer_handle_t timer, const mcpwm_timer_event_data_t *edata, void *user_data);
34+
2535
/**
2636
* @brief Initialize zero cross comparer
2737
*

components/motor/esp_sensorless_bldc_control/idf_component.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
version: 0.2.0
1+
version: 0.3.0
2+
targets:
3+
- esp32
4+
- esp32s3
5+
- esp32c6
6+
- esp32h2
7+
- esp32p4
28
description: ESP32 Sensorless BLDC Control Component
39
url: https://github.com/espressif/esp-iot-solution/tree/master/components/motor/esp_sensorless_bldc_control
410
repository: https://github.com/espressif/esp-iot-solution.git
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
# bldc_fan_rainmaker
22

3-
`bldc_fan_rainmaker` 例程将无刷电机驱动的电风扇接入 ESP Rainmaker 云,实现了以下功能
3+
The `bldc_fan_rainmaker` example connects a brushless motor-driven fan to the ESP Rainmaker cloud, achieving the following functionalities:
44

5-
* 风扇无极调速
6-
* 摇头
7-
* 自然风
8-
* 远程启动关闭
9-
* OTA
10-
* BLE 配网
5+
* Stepless fan speed control
6+
* Oscillation
7+
* Natural wind mode
8+
* Remote start and stop
9+
* OTA updates
10+
* BLE provisioning
1111

12-
## 组件介绍
12+
![rainmaker_fan](https://dl.espressif.com/AE/esp-iot-solution/esp_bldc_rainmaker.gif)
1313

14-
* [esp_sensorless_bldc_control](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control) 是基于 ESP32 系列芯片的 BLDC 无感方波控制库。支持以下功能:
15-
* 支持基于 ADC 采样检测过零点
16-
* 支持基于比较器检测过零点
17-
* 支持基于脉冲法实现转子初始相位检测
18-
* 支持堵转保护
19-
* 支持过流,过欠压保护[feature]
20-
* 支持缺相保护[feature]
14+
## Component Overview
2115

22-
* [esp_rainmaker](https://components.espressif.com/components/espressif/esp_rainmaker) 是一个完整且轻量级的 AIoT 解决方案,能够以简单、经济高效且高效的方式为您的企业实现私有云部署。
16+
* [esp_sensorless_bldc_control](https://components.espressif.com/components/espressif/esp_sensorless_bldc_control) is a sensorless BLDC square wave control library based on the ESP32 series chips. It supports the following features:
17+
* Zero-crossing detection based on ADC sampling
18+
* Zero-crossing detection based on a comparator
19+
* Initial rotor position detection using pulse method
20+
* Stall protection
21+
* Overcurrent, over/under-voltage protection [feature]
22+
* Phase loss protection [feature]
23+
24+
* [esp_rainmaker](https://components.espressif.com/components/espressif/esp_rainmaker) is a complete and lightweight AIoT solution that enables private cloud deployment for your business in a simple, cost-effective, and efficient manner.

examples/motor/bldc_fan_rainmaker/main/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ set(INC_DIRS "app/include/" "hal/include/")
66
idf_component_register(SRCS ${SRC_FILES} ${SOURCES}
77
INCLUDE_DIRS "." ${INC_DIRS}
88
)
9-
idf_component_get_property(bldc_lib esp_sensorless_bldc_control COMPONENT_LIB)
10-
cmake_policy(SET CMP0079 NEW)
11-
target_link_libraries(${bldc_lib} PUBLIC ${COMPONENT_LIB})
9+
10+
idf_build_get_property(build_components BUILD_COMPONENTS)
11+
if("esp_sensorless_bldc_control" IN_LIST build_components)
12+
idf_component_get_property(bldc_lib esp_sensorless_bldc_control COMPONENT_LIB)
13+
cmake_policy(SET CMP0079 NEW)
14+
target_link_libraries(${bldc_lib} PUBLIC ${COMPONENT_LIB})
15+
endif()
16+
if("espressif__esp_sensorless_bldc_control" IN_LIST build_components)
17+
idf_component_get_property(bldc_lib espressif__esp_sensorless_bldc_control COMPONENT_LIB)
18+
cmake_policy(SET CMP0079 NEW)
19+
target_link_libraries(${bldc_lib} PUBLIC ${COMPONENT_LIB})
20+
endif()

0 commit comments

Comments
 (0)