ST电机库(encoder_speed_pos_fdbk)

#ifndef __ENCODER_SPEEDNPOSFDBK_H

#define __ENCODER_SPEEDNPOSFDBK_H

#ifdef __cplusplus

 extern "C" {

#endif /* __cplusplus */

#include "speed_pos_fdbk.h

#define GPIO_NoRemap_TIMx ((uint32_t)(0))

#define ENC_DMA_PRIORITY DMA_Priority_High

#define ENC_SPEED_ARRAY_SIZE  ((uint8_t)16)    /* 2^4 */

typedef struct

{

  SpeednPosFdbk_Handle_t _Super;

  /* SW Settings */

  uint8_t IRQnb; /*!< MC IRQ number used for TIMx capture update event.*/

  uint16_t PulseNumber; /*!< Number of pulses per revolution, provided by each

                              of the two encoder signals, multiplied by 4 */

  FunctionalState RevertSignal; /*!< To be enabled if measured speed is opposite

                                     to real one (ENABLE/DISABLE)*/

  uint16_t SpeedSamplingFreq01Hz; /*!< Frequency (01Hz) at which motor speed is to be

                                   computed. It must be equal to the frequency

                                   at which function SPD_CalcAvrgMecSpeed01Hz

                                   is called.*/

  uint8_t SpeedBufferSize; /*!< Size of the buffer used to calculate the average

                             speed. It must be <= 16.*/

  uint16_t InpCaptFilter; /*!< Time filter applied to validate ENCODER sensor

                                capture. This value defines the frequency

                                used to sample ENCODER sensors input and the

                                length of the digital filter applied.

                                The digital filter is made of an event

                                counter in which N events are needed to

                                validate a transition on the input.

                                0000: No filter, sampling is done at fCK_INT.

                                0001: fSAMPLING=fCK_INT , N=2.

                                0010: fSAMPLING=fCK_INT , N=4.

                                0011: fSAMPLING=fCK_INT , N=8.

                                0100: fSAMPLING=fCK_INT/2, N=6.

                                0101: fSAMPLING=fCK_INT/2, N=8.

                                0110: fSAMPLING=fCK_INT/4, N=6.

                                0111: fSAMPLING=fCK_INT/4, N=8.

                                1000: fSAMPLING=fCK_INT/8, N=6.

                                1001: fSAMPLING=fCK_INT/8, N=8.

                                1010: fSAMPLING=fCK_INT/16, N=5.

                                1011: fSAMPLING=fCK_INT/16, N=6.

                                1100: fSAMPLING=fCK_INT/16, N=8.

                                1101: fSAMPLING=fCK_INT/32, N=5.

                                1110: fSAMPLING=fCK_INT/32, N=6.

                                1111: fSAMPLING=fCK_INT/32, N=8 */

该段代码是一个定义了编码器的各种参数和状态的结构体。其中包括了一些SW设置,例如IRQnb是用于TIMx捕获更新事件的MC IRQ号码,PulseNumber是每个编码器信号提供的每转脉冲数乘以4,RevertSignal是用于测量速度与实际速度相反时启用的标志,SpeedSamplingFreq01Hz是计算电机速度的频率(01Hz),SpeedBufferSize是用于计算平均速度的缓冲区的大小,InpCaptFilter是用于验证ENCODER传感器捕获的时间过滤器。

  TIM_TypeDef* TIMx;    /*!< Timer used for ENCODER sensor management.*/

  volatile uint16_t TimerOverflowNb;    /*!< Number of overflows occurred since

                                        last speed measurement event*/

  bool SensorIsReliable;            /*!< Flag to indicate sensor/decoding is not

                                         properly working.*/  

  uint16_t PreviousCapture;            /*!< Timer counter value captured during

                                        previous speed measurement event*/

  int32_t DeltaCapturesBuffer[ENC_SPEED_ARRAY_SIZE]; /*!< Buffer used to store

                                        captured variations of timer counter*/

  volatile uint8_t DeltaCapturesIndex; /*! <Buffer index*/

  uint32_t U32MAXdivPulseNumber;       /*! <It stores U32MAX/hPulseNumber*/

  uint16_t SpeedSamplingFreqHz;        /*! <Frequency (Hz) at which motor speed

                                        is to be computed. */

  bool TimerOverflowError;              /*!< true if the number of overflow

                                        occurred is greater than 'define'

                                        ENC_MAX_OVERFLOW_NB*/

}ENCODER_Handle_t;

该代码定义了一个名为 ENCODER_Handle_t 的结构,其中包含与编码器传感器相关的各种变量和标志。该结构用于存储有关传感器状态的信息,并执行与电机速度和位置相关的计算。
该代码还包括与编码器传感器相关的几个功能。ENC_Init函数初始化传感器并设置
 

void * ENC_IRQHandler(void *pHandleVoid);

void ENC_Init(ENCODER_Handle_t *pHandle);

void ENC_Clear(ENCODER_Handle_t *pHandle);

int16_t ENC_CalcAngle(ENCODER_Handle_t *pHandle);

bool ENC_CalcAvrgMecSpeed01Hz(ENCODER_Handle_t *pHandle, int16_t *pMecSpeed01Hz);

void ENC_SetMecAngle(ENCODER_Handle_t *pHandle, int16_t hMecAngle);

ENCODER_Handle_t结构中的各种变量。

ENC_Clear功能可重置传感器并清除ENCODER_Handle_t结构中的各种变量。
ENC_CalcAngle功能根据编码器传感器读数计算电机的当前机械角度。ENC_CalcAvrgMecSpeed01Hz功能根据编码器传感器读数以 0.1 Hz 为单位计算电机的平均机械速度。

ENC_SetMecAngle功能设置电机在ENCODER_Handle_t结构中的当前机械角度。最后,ENC_IRQHandler函数是在发生计时器溢出时调用的中断处理程序。该函数更新ENCODER_Handle_t结构中的 TimerOverflowNb 变量,并执行其他必要的计算。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值