| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /**********************************
- * 文件名称: hall_sensor.h
- * 功能描述: 霍尔传感器模块头文件
- * 主要内容:
- * 1. 定义霍尔传感器相关宏
- * 2. 声明霍尔传感器相关变量
- *
- * 注意事项:
- * - 包含霍尔传感器的时钟和采样频率定义
- * - 包含角度和速度计算的系数定义
- **********************************/
- #ifndef __HALL_SENSOR_H_
- #define __HALL_SENSOR_H_
- typedef struct
- {
- uint8_t state; // 当前稳定霍尔状态
- uint8_t state_last; //上一个霍尔状态
- float angle; //霍尔传感器计算得到的电机角度
- float angle_add; //单次电流环时间内角度自增值
- uint32_t ccr;
- float theta[6]; //霍尔传感器六个扇区的角度
- uint32_t count[6]; //经过六个扇区分别花费的计数值
- uint32_t last_valid_count[6]; //上一个扇区有效计数值,用于滤波
- uint8_t flag; //是否进入闭环控制的标志位
- float speed[6]; //六个扇区的角速度
- float Speed; //电机角速度,是对 speed[6] 取了平均值
- } Hall_TypeDef;
- /**
- * @brief 霍尔传感器定时器时钟频率
- * @details 设置为84MHz
- */
- #define HALL_TIM_CLOCK (u32)84000000
- /**
- * @brief 霍尔传感器采样频率
- * @details 设置为10kHz
- */
- #define HALL_SAMPLE_FREQ (u32)10000
- /**
- * @brief 相位偏移角度
- * @details 设置为60度,转换为弧度
- */
- // #define PHASE_SHIFT_ANGLE (float)(60.0f/360.0f*2.0f*PI)
- #define PHASE_SHIFT_ANGLE (float)(26.36f/360.0f*2.0f*PI)
- /**
- * @brief 角度计算因子
- * @details 用于将计数值转换为角度增量
- */
- #define HALL_ANGLE_FACTOR (float)((float)HALL_TIM_CLOCK/(float)HALL_SAMPLE_FREQ*PI/3.0f)
- /**
- * @brief 速度计算因子
- * @details 用于将计数值转换为电机速度
- */
- #define HALL_SPEED_FACTOR (float)((float)HALL_TIM_CLOCK/6.0f)
- Hall_TypeDef* Hall_Get(void);
- #endif
|