在 FOC 控制器中新增 `update_power` 方法,用于实时获取母线电压, 提升控制系统对电源状态的感知能力。 feat(CAN): 优化 CAN 配置与通信处理 将 CAN 相关宏定义改为 constexpr 常量,并引入角度转换因子。 修正接收数据解析方式,增强通信稳定性与精度。 feat(angle_sensor): 实现角度累积与绕回处理 重写角度传感器驱动,支持角度连续测量与自动绕回处理。 新增 `update`、`getAngle` 和 `reset` 接口,提高角度读取准确性。 feat(main): 增加角度传感器磁感应强度测试 在主函数初始化阶段调用磁感应强度检测函数,辅助判断传感器工作状态。
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#include "initial.h"
|
|
#include "Timer.h"
|
|
#include "ang_sensor.h"
|
|
#include <stdint.h>
|
|
|
|
void GPIO_config(void) {
|
|
// 使能GPIOB时钟
|
|
rcu_periph_clock_enable(RCU_GPIOB);
|
|
// 配置PB2为输入引脚,用于读取电机状态
|
|
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
|
|
}
|
|
|
|
/* retarget the C library printf function to the USART */
|
|
u8 USART0_init() {
|
|
gd_eval_com_init(EVAL_COM0);
|
|
return 1;
|
|
}
|
|
|
|
/*!
|
|
\brief configure the watchdog peripheral
|
|
\param[in] none
|
|
\param[out] none
|
|
\retval none
|
|
*/
|
|
u8 watchdog_init(u32 time) {
|
|
u8 status = 0;
|
|
/* configure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */
|
|
/* time = reload_value / clock_frequency */
|
|
status = fwdgt_config(time * 0.625, FWDGT_PSC_DIV64);
|
|
fwdgt_enable();
|
|
return status;
|
|
}
|
|
|
|
void angsens_MG_test(void) {
|
|
u8 MGH = gpio_input_bit_get(GPIOB, GPIO_PIN_10);
|
|
u8 MGL = gpio_input_bit_get(GPIOB, GPIO_PIN_11);
|
|
std::printf("MGH:%d MGL:%d\r\n", MGH, MGL);
|
|
}
|
|
/**
|
|
* @brief driver输出初始化
|
|
*/
|
|
void driver_init(void) {
|
|
timer1_gpio_config();
|
|
timer1_pwm_config();
|
|
TIMER3_config();
|
|
}
|
|
|
|
int fputc(int ch, FILE *f) throw() {
|
|
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
|
|
while (RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE))
|
|
;
|
|
return ch;
|
|
}
|