feat:优化电流采样速率 feat:优化PIDramp效率 feat:优化角度采样效率 fix:回滚CAN打包逻辑 feat:去除timer3 feat(FOC): 优化帕克逆变换与克拉克逆变换计算方式 将原有的三角函数计算替换为查表法,提高运算效率。同时添加了 sqrt(3)/2 的预计算常量,并优化了电压限制部分的计算逻辑,减少重复运算。
50 lines
1.0 KiB
C++
50 lines
1.0 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;
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief driver输出初始化
|
|
*/
|
|
void driver_init(void) {
|
|
timer1_gpio_config();
|
|
timer1_pwm_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;
|
|
}
|