QEP (正交编码器脉冲)
简介
Quadrature Encoder Pulse (QEP) 正交编码器脉冲配合外部正交码盘,通过检测电机编码 输出信号,获取电机转速、位置、方向等信号,用于高性能的位置及速度控制系统。
功能概述
兼容 CW/CCW 格式信号、方向脉冲格式信号输入
支持独立的 T 法测速,单位距离可通过软件编程
支持独立的 M 法测速,单位时间可通过软件编程
支持失速检测
支持内部计数器的多种复位模式、初始化模式、锁存模式
内置位置计数比较功能,比较匹配后送出可扩展宽度电平于 INDEX 或 STROBE 引脚
支持 A、B、INDEX 相输入源来自芯片内部 SRPWM、ACMP 模块,完成芯片内部自测
除了编码器 A、B、IINDEX 相信号,还支持 STROBE 相信号做位置指示;该 STROBE信号同样可来自 SRPWM 模块
支持管脚信号滤波
输入选择及模式适配处理单元(PROC)
QEP 模块兼容 CW/CCW 模式输入,将 CW/CCW 信号格式转换为方向脉冲模式。并且对 CW/CCW 模式下的默认值也做了 0/1 两种情况兼容(QMA), 完成 CW/CCW 信号对内部位置计数值的控制; 兼容方向脉冲模式输入(SWAP)。兼容 A/B 相任意一路为方向指示信号,另一路作为脉冲信号;
- 适配处理单元拥有以下计数模式:
正交时钟模式:输入 A、B 为相差 90°的信号,硬件通过相位差判断计数方向,计数脉冲为 A/B 的上下沿;
方向计数模式:输入信号 A 的上下沿代表了计数脉冲,B 信号代表了计数方向,高为正方向,低为反方向;
增计数模式:固定方向为 1(正向),计数脉冲为交换后 A 信号上升沿或双沿;
减计数模式:固定方向为 0(反向),计数脉冲为交换后 A 信号上升沿或双沿;
不同的模式下处理单元接收A/B相信号,按照相应规则处理后吐出QCLK供后面模块使用。
- 库函数功能:
QEP_setDecoderConfig()设置编码器配置与模式QEP_setQMAModuleMode()设置信号源的“空闲/无效状态”
捕获功能(T法测速)
T法示意图:
T 法测速原理为预设单位距离,测量该单位距离所需时长即可得到转速:用高频时钟量出相邻两个编码器边沿之间隔了多长时间,速度与这个周期成反比。QEP 为此专门有一个边沿捕获单元(capture),全部硬件自动完成,不需要软件在 GPIO中断里打时间戳。
部件 |
作用 |
|---|---|
捕获定时器 |
自由运行计数,时钟 = SYSCLK/CCPS(CCPS 分频) |
捕获定时器锁存 |
QCLK 边沿到来瞬间,cnt 的值被硬件锁进去同时被清除开始新一轮计时 |
捕获周期寄存器 |
记录相邻两次捕获事件之间的定时器计数差 |
捕获周期锁存 |
单元位置事件(unit position event,UPPS 分频)时锁存捕获周期 |
- 换算成转速(正交模式):
QCLK 是编码器解码后的时钟,频率 = 4 × 编码器线频(4X 模式下每线 4 个 QCLK)。测得 QCLK 周期为 T_qclk, 则n(转/秒) = 1 / (4 × PPR × T_qclk),PPR = 编码器每转脉冲线数。
数值例子:PPR=1000,测得 T_qclk = 25µs → QCLK=40kHz → 线频=10kHz → n = 1/(4×1000×25µs) = 10 转/秒 = 600 RPM。
- 库函数功能:
QEP_setCaptureConfig()— 对应 CCPS/UPPS 两个分频;QEP_getCaptureTimer()— 对应 QCTMR 当前值;QEP_getCapturePeriod()— 对应 QCPRD;QEP_getCaptureTimerLatch()/QEP_getCapturePeriodLatch()— 对应 QCTRL/QCPRDLAT 两个硬件锁存值。
位置计数器(M法测速)
M法示意图:
M法测速原理为预设单位时间,测量该单位时间内所前进距离即可得到转速:在固定时间窗内,统计位置计数器的增量(即该窗口内来过的正交边沿数),用”位置增量 ÷ 时间”得到转速。它与 T 法(测周法,由边沿捕获单元实现)方向相反:一个数脉冲,一个测脉冲间隔。
M 法测速相关部件 部件
作用
位置计数器PCCU
对解码后的时钟计数,带方向,正转加、反转减
单元定时器 UTIME
自由运行的 32 位定时器,时钟为 SYSCLKOUT,计到 UPRD 时产生**单元超时事件**
位置锁存
单元超时瞬间,PCCU的当前值被硬件锁存,作为窗口结束时刻的位置快照
UTO 中断
单元超时中断,软件在中断里读取锁存值并计算速度
- 工作流程:
使能单元定时器,设定周期 QUPRD(即测速窗口 T);电机转动,位置计数器 QPOSCNT 连续增减;每当单元定时器计时到 QUPRD,硬件**同时**完成两件事:把 QPOSCNT锁存到 QPOSLAT,并产生 UTO 中断,定时器归零重新开始;
- 软件在 UTO 中断中计算:
ΔP = QPOSLAT(本次) − QPOSLAT(上次),得到一个窗口内的位置增量,代入公式得到转速,窗口周而复始。
- 速度计算:
设编码器每转 PPR 线,4X 模式下每转位置计数为4 × PPR,测速窗口为T:
n [r/s] = ΔP / (4 × PPR × T) n [rpm] = 60 × ΔP / (4 × PPR × T) ω [rad/s] = 2π × ΔP / (4 × PPR × T) ΔP 带符号,方向信息天然包含在内,无需额外判断正反转。
数值示例(PPR = 1000,T = 1 ms,即每转 4000 计数):
3000 rpm = 50 r/s → ΔP = 50 × 4000 × 0.001 = 200 计数 30 rpm = 0.5 r/s → ΔP = 0.5 × 4000 × 0.001 = 2 计数 6 rpm ≈ 0.1 r/s → ΔP = 0.4 → 实际只能数到 0 或 1,基本失效
- 误差分析:
相对误差 ≈ 1/ΔP:转速越高,窗口内计数越多,误差越小—— 这正是 M 法适合高速的原因;
转速低到 ΔP 只有 0~2 个计数时,误差高达 50% 甚至完全无输出, 此时应切换到 T 法(测周法,相对误差 ≈ Tclk/Tp,低速时反而极小);
速度分辨率为
1/(4 × PPR × T)r/s:窗口越长分辨率越好, 但测量延迟和更新率变差——是分辨率与带宽的折中。
- 库函数功能:
QEP_setPositionCounterConfig()位置计数器复位模式与最大计数配置QEP_enableUnitTimer()/QEP_loadUnitTimer()使能/装载单元定时器周期(即测速窗口)QEP_getPosition()读取位置计数器当前值(每个窗口末采样一次即可)QEP_getDirection()读取当前旋转方向QEP_INT_UNIT_TIME_OUT()单元超时中断(M 法的采样节拍来源)
比较输出模式
QEP 内部支持对位置计数值进行比对,并将比较结果进行输出到 INDEX 管脚或 STROBE 管脚,告知对应状态。
- 比较值的设定支持影子加载,可设置以下两种事件作为影子模式下更新条件:
位置计数值为 0 时更新比较值
上一次位置比较匹配成功更新比较值
- 库函数功能:
QEP_enableCompare()使能位置比较单元(置 CTRL2_CFG 的 CMP_EN 位),QEP_disableCompare()禁用。QEP_setCompareConfig()一次配完比较单元。compareValue 比较匹配值,QPOSCNT 计到它(实际为 +1)就产生匹配事件。
config.compareOutputEn 匹配时是否向引脚输出同步脉冲。
config.compareOutputPinSel 输出走哪个脚:index 引脚或 strobe。
config.Outputpolarity 输出脉冲的极性。
config.shadowModeEn + config.shadowSigSel 影子寄存器使能及装载时机:过零时装载(QEP_COMPARE_LOAD_ON_ZERO)或每次匹配后装载(QEP_COMPARE_LOAD_ON_MATCH),避免运行中改值丢匹配。
cycles 同步输出脉宽,单位 4×SYSCLKOUT,范围 1~4096,不能写 0。
QEP_setComparePulseWidth()运行中单独更新脉宽。
锁存/复位/初始化模式
三个功能都是围绕位置计数器PCCU的事件驱动机制——区别在于事件发生时对计数器做什么:复位是清零、初始化是装入设定值、锁存是拍快照。
复位(Reset)
复位功能可以在事件触发后将设位置计数器清0。
- 内部位置计数值拥有多种复位模式:
第一次 INDEX 复位:此模式下位置计数值只在第一次 INDEX 为高时的 A/B 边沿信号进行复位,此后的 INDEX 不触发复位
INDEX 复位:此模式下第一次复位发生在 INDEX 为高时的 A/B 边沿处,并记录此时的方向信息,及边沿类别(A 上升沿、A 下降沿、B 上升沿、B 下降沿);此后的复位发生在 INDEX 为高,若此时方向与记录方向相同,则在相同的边沿信号进行复位,若不同则在相反的边沿信号复位
超时复位:位置计数值在超时中断给出时进行复位
最值复位:注意以上三种模式都存在该复位,只要位置计数值超过预设最值,则复位
- 库函数功能:
QEP_setPositionCounterConfig()设置复位模式
初始化(Init)
- 初始化功能可以在事件触发后将设定值装入位置计数器。内部位置计数值支持多种初始化模式有:
INDEX 触发
STROBE 触发
软件触发
- 位置计数值的 INDEX 初始化可配模式:
在 INDEX 上升沿初始化
在 INDEX 下降沿初始化
INDEX 不影响初始化
- 位置计数值的 STROBE 初始化可配模式:
在 STROBE 上升沿初始化
正向 STROBE 上升沿初始化或反向 STROBE 下降沿初始
STROBE 不影响初始化
软件写 1 到一特定寄存器(cfg2pccu_swi)的写 1 动作触发初始化,该寄存器不会自动清零
- 库函数功能:
QEP_setInitialPosition()要装入的值,不必是 0,可以是机械标定值。QEP_setPositionInitMode()选哪个事件触发装入(et6x_qep.h:126-130):index 上升/下降沿、strobe 上升沿、strobe 边沿+方向(QEP_INIT_EDGE_DIR_STROBE 正转沿上升沿、反转沿下降沿),也可以 index 和 strobe 事件相或组合。QEP_setSWPositionInit()软件立即触发一次装入。
锁存(Latch)
针对不同事件,可将当前的位置计数值锁存到对目的寄存器:事件瞬间硬件拍快照,主计数器继续跑,软件随时来取,没有“读数时刻和事件时刻不同步”的问题
- 1.支持位置计数值 INDEX 来临时锁存到相应寄存器 (PCINTILAT) 模式:
INDEX 上升沿锁存
INDEX 下降沿锁存
标记时刻锁存
不锁存;
- 2.支持位置计数值的 STROBE 锁存到相应寄存器(PCNTSLAT)模式:
STROBE 上升沿锁存
正向时,STROBE 的上升沿锁存;或反向时,STROBE 的下降沿
备注
注意当位置计数值的复位模式为 INDEX 复位,则直接为标记时刻锁存,忽略该配置
标记时刻定义第一次 INDEX 为高时的 A/B 的边沿处,并记录此时的方向信息,及边沿类别(A 上升沿、A 下降沿、B 上升沿、B 下降沿); 此后在 INDEX 为高电平期间,若方向与记录方向相同,则称相同的边沿信号为标记时刻,若不同则记相反的边沿信号为标记时刻
- 库函数功能:
QEP_setLatchMode()设置锁存模式QEP_getCaptureTimerLatch()/QEP_getCapturePeriodLatch()/QEP_getIndexPositionLatch()/QEP_getStrobePositionLatch()获取对应事件的位置计数锁存值
软件配置流程
配置IOMUX 配置对应 QEP 引脚为 EQEP 模式
配置解码器 调用
EQEP_setDecoderConfig()传入EQEPx和解码器配置参数设置位置计数器的复位模式 调用
EQEP_setPositionCounterConfig()相关参数设置捕获的分频配置 调用
EQEP_setCaptureConfig()传入相关参数设置QMA模式 调用
EQEP_setQMAModuleMode()相关参数输入源选择 调用
EQEP_selectSource()传入EQEPx和配置参数设置输入级性 调用
EQEP_setInputPolarity()相关参数使能捕获 调用
EQEP_enableCapture()传入EQEPx使能模块 调用
EQEP_enableModule()传入EQEPx
选择 T 法或 M 法进行测速
应用示例
QEP测速示例:QEP/QEP_Velocity_Measurement。
API Reference
Header File
Functions
-
void EQEP_enableModule(EQEP_Type *EQEPx)
enable the eqep module
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
-
void EQEP_disableModule(EQEP_Type *EQEPx)
disable the eqep module
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
-
void EQEP_enableCapture(EQEP_Type *EQEPx)
Enables the eQEP module edge-capture unit.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
-
void EQEP_disableCapture(EQEP_Type *EQEPx)
disables the eQEP module edge-capture unit.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
-
void EQEP_enableUnitTimer(EQEP_Type *EQEPx, uint32_t period)
Enables the eQEP module unit timer.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
period – period is period value at which a unit time-out interrupt is set.
-
void EQEP_disableUnitTimer(EQEP_Type *EQEPx)
disables the eQEP module unit timer.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
-
void EQEP_loadUnitTimer(EQEP_Type *EQEPx, uint32_t period)
Loads the eQEP module unit timer period as number of SYSCLK cycles.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
period – period is period value at which a unit time-out interrupt is set.
-
void EQEP_setDecoderConfig(EQEP_Type *EQEPx, uint32_t config)
Configures eQEP module’s quadrature decoder unit.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
EQEP0
EQEP1
config – The config parameter provides the configuration of the decoder and is the logical OR of several values:
specify if both rising and falling edges should be counted or just rising edges, by the following options: EQEP_CONFIG_2X_RESOLUTION or EQEP_CONFIG_1X_RESOLUTION
specify if quadrature signals are being provided on QEPA and QEPB, if a direction signal and a clock are being provided, or if the direction should be hard-wired for a single direction with QEPA used for input, by the following options: EQEP_CONFIG_QUADRATURE, or EQEP_CONFIG_CLOCK_DIR, or EQEP_CONFIG_UP_COUNT or EQEP_CONFIG_DOWN_COUNT
specify if the signals provided on QEPA and QEPB should be swapped before being processed, by the following options: EQEP_CONFIG_NO_SWAP or EQEP_CONFIG_SWAP
specify if the gating of the index pulse should be enabled or disabled, by the following options: EQEP_CONFIG_IGATE_DISABLE or EQEP_CONFIG_IGATE_ENABLE
-
void EQEP_setPositionCounterConfig(EQEP_Type *EQEPx, EQEP_PositionResetMode mode, uint32_t maxPosition)
Configures eQEP module position counter unit.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
EQEP0
EQEP1
mode –
EQEP_POSITION_RESET_IDX
EQEP_POSITION_RESET_MAX_POS
EQEP_POSITION_RESET_1ST_IDX
EQEP_POSITION_RESET_UNIT_TIME_OUT
maxPosition – maxPosition is the maximum value of the position counter and is the value used to reset the position capture when moving in the reverse(negative) direction. range :0x0 ~ 0xFFFFFFFF
-
void EQEP_setCaptureConfig(EQEP_Type *EQEPx, EQEP_CAPCLKPrescaler capPrescaler, EQEP_UPEVNTPrescaler evntPrescaler)
Configures eQEP module edge-capture unit.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
capPrescaler – capPrescaler is the prescaler setting of the eQEP capture timer clk.
evntPrescaler – evntPrescaler is the prescaler setting of the unit position event frequency.
-
void EQEP_setQMAModuleMode(EQEP_Type *EQEPx, EQEP_QMAMode qmaMode)
Set the quadrature mode adapter (QMA) module mode.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
qmaMode –
-
void EQEP_setStrobeSource(EQEP_Type *EQEPx, EQEP_StrobeSource strobeSrc)
Set the strobe input source of the eQEP module.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
strobeSrc –
-
void EQEP_selectSource(EQEP_Type *EQEPx, EQEP_SourceSelect sourceConfig)
Selects the source for eQEPA/B/I signals.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
sourceConfig –
-
void EQEP_setInputPolarity(EQEP_Type *EQEPx, bool invertQEPA, bool invertQEPB, bool invertIndex, bool invertStrobe)
Sets the polarity of the eQEP module’s input signals.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
invertQEPA – is the flag to negate the QEPA input.
invertQEPB – is the flag to negate the QEPA input.
invertIndex – is the flag to negate the index input.
invertStrobe – is the flag to negate the strobe input.
-
void EQEP_setPosition(EQEP_Type *EQEPx, uint32_t position)
Sets the current encoder position.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
position – position is the new position for the encoder. range: 0x0 ~ 0xFFFFFFFF
-
void EQEP_setPositionInitMode(EQEP_Type *EQEPx, uint16_t initMode)
Configures the mode in which the position counter is initialized.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
initMode – The initMode parameter provides the mode as either EQEP_INIT_DO_NOTHING (no action configured) or one of the following strobe events, index events, or a logical OR of both a strobe event and an index event.
strobe events: specify which strobe event will initialize the position counter. EQEP_INIT_RISING_STROBE or EQEP_INIT_EDGE_DIR_STROBE
index events: specify which index event will initialize the position counter. EQEP_INIT_RISING_INDEX or EQEP_INIT_FALLING_INDEX
-
void EQEP_setSWPositionInit(EQEP_Type *EQEPx, bool initialize)
Sets the software initialization of the encoder position counter.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
initialize – initialize is a flag to specify if software initialization of the position counter is enabled.
-
void EQEP_setInitialPosition(EQEP_Type *EQEPx, uint32_t position)
Sets the init value for the encoder position counter.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
position – position is the value to be written to the position counter upon.initialization.
-
uint32_t EQEP_getPosition(EQEP_Type *EQEPx)
Gets the current encoder position.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint32_t The current position of the encoder.
-
uint16_t EQEP_getCapturePeriod(EQEP_Type *EQEPx)
Gets the encoder capture period.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint16_t The period count value between the last successive position events. range 0x0 ~ 0xFFFF
-
uint16_t EQEP_getCaptureTimer(EQEP_Type *EQEPx)
Gets the encoder capture timer value.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint16_t The capture timer value. range 0x0 ~ 0xFFFF
-
int16_t EQEP_getDirection(EQEP_Type *EQEPx)
Gets the current direction of rotation.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
int16_t
Return 1 if moving in the forward direction
return -1 if moving in the reverse direction
-
void EQEP_enableCompare(EQEP_Type *EQEPx)
Enables the eQEP module position-compare unit.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
-
void EQEP_disableCompare(EQEP_Type *EQEPx)
Disables the eQEP module position-compare unit.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
-
void EQEP_setCompareConfig(EQEP_Type *EQEPx, EQEP_CompareConfigParam config, uint32_t compareValue, uint16_t cycles)
Configures eQEP module position-compare unit.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
config –
compareValue – compareValue is the value to which the position count value is compared for a position-compare event. range:0x0 ~ 0xFFFFFFFF. actual value = compareValue + 1.
cycles – The cycles is used to select the width of the sync output pulse. The width of the resulting pulse will be cycles * 4 * the width of a SYSCLKOUT cycle. The maximum width is 4096 * 4 * SYSCLKOUT cycles.
-
void EQEP_setComparePulseWidth(EQEP_Type *EQEPx, uint16_t cycles)
Configures the position-compare unit’s sync output pulse width.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
cycles – cycles is the width of the pulse that can be generated on a position-compare event. It is in units of 4 SYSCLKOUT cycles. config range:1 ~ 4096; actual range: 1 * 4*SYSCLKOUT ~ 4096 * 4* SYSCLKOUT note: param cycles cannot write 0.
-
void EQEP_enableWatchdog(EQEP_Type *EQEPx, uint16_t period)
Enables the eQEP module watchdog timer.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
period – period is watchdog period value at which a time-out will occur if no quadrature-clock event is detected.
-
void EQEP_disableWatchdog(EQEP_Type *EQEPx)
disables the eQEP module watchdog timer.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
-
void EQEP_setWatchdogTimerValue(EQEP_Type *EQEPx, uint16_t value)
Sets the eQEP module watchdog timer value.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
value – value is the value to be written to the watchdog timer.
-
uint16_t EQEP_getWatchdogTimerValue(EQEP_Type *EQEPx)
Gets the eQEP module watchdog timer value.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint16_t Return the current watchdog timer value.
-
void EQEP_setLatchMode(EQEP_Type *EQEPx, uint32_t latchMode)
Configures the quadrature modes in which the position count can be latched.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
latchMode – This function configures the events on which the position count and several other registers can be latched. The latchMode parameter provides the mode as the logical OR of several values.
specify the event that latches the position counter. EQEP_LATCH_CNT_READ_BY_CPU or EQEP_LATCH_UNIT_TIME_OUT
specify which strobe event will latch the position counter into the strobe position latch register. EQEP_LATCH_RISING_INDEX or EQEP_LATCH_FALLING_INDEX or EQEP_LATCH_SW_INDEX_MARKER
specify which index event will latch the position counter into the index position latch register. EQEP_LATCH_RISING_STROBE or EQEP_LATCH_EDGE_DIR_STROBE
-
uint32_t EQEP_getIndexPositionLatch(EQEP_Type *EQEPx)
Gets the encoder position that was latched on an index event.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint32_t return The position count latched on an index event.
-
uint32_t EQEP_getStrobePositionLatch(EQEP_Type *EQEPx)
Gets the encoder position that was latched on a strobe event.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint32_t return The position count latched on a strobe event.
-
uint32_t EQEP_getPositionLatch(EQEP_Type *EQEPx)
Gets the encoder position that was latched on a unit time-out event.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint32_t return The position count latch register value.
-
uint16_t EQEP_getCaptureTimerLatch(EQEP_Type *EQEPx)
Gets the encoder capture timer latch.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint16_t return The edge-capture timer latch value.
-
uint16_t EQEP_getCapturePeriodLatch(EQEP_Type *EQEPx)
Gets the encoder capture period latch.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint16_t return The edge-capture period latch value.
-
void EQEP_enableInterrupt(EQEP_Type *EQEPx, uint16_t intFlags)
Enables eQEP module interrupt sources.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
intFlags – The intFlags parameter can be any of the following values OR or together: EQEP_INT_DIR_CHANGE - Quadrature direction change EQEP_INT_PHASE_ERROR - Quadrature phase error EQEP_INT_POS_CNT_ERROR - Position counter error EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch EQEP_INT_INDEX_EVNT_LATCH - Index event latch EQEP_INT_POS_COMP_READY - Position-compare ready EQEP_INT_POS_COMP_MATCH - Position-compare match EQEP_INT_UNDERFLOW - Position counter underflow EQEP_INT_OVERFLOW - Position counter overflow EQEP_INT_WATCHDOG - Watchdog time-out EQEP_INT_UNIT_TIME_OUT - Unit time-out EQEP_INT_QMA_ERROR - QMA error
-
void EQEP_disableInterrupt(EQEP_Type *EQEPx, uint16_t intFlags)
Disables eQEP module interrupt sources.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
intFlags – The intFlags parameter can be any of the following values OR or together: EQEP_INT_DIR_CHANGE - Quadrature direction change EQEP_INT_PHASE_ERROR - Quadrature phase error EQEP_INT_POS_CNT_ERROR - Position counter error EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch EQEP_INT_INDEX_EVNT_LATCH - Index event latch EQEP_INT_POS_COMP_READY - Position-compare ready EQEP_INT_POS_COMP_MATCH - Position-compare match EQEP_INT_UNDERFLOW - Position counter underflow EQEP_INT_OVERFLOW - Position counter overflow EQEP_INT_WATCHDOG - Watchdog time-out EQEP_INT_UNIT_TIME_OUT - Unit time-out EQEP_INT_QMA_ERROR - QMA error
-
void EQEP_enableInterruptMask(EQEP_Type *EQEPx, uint16_t intFlags)
Mask eQEP module interrupts.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1] pointer to QEP module instance, [EQP0~EQP1]
intFlags – The intFlags parameter can be any of the following values OR or together: EQEP_INT_DIR_CHANGE - Quadrature direction change EQEP_INT_PHASE_ERROR - Quadrature phase error EQEP_INT_POS_CNT_ERROR - Position counter error EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch EQEP_INT_INDEX_EVNT_LATCH - Index event latch EQEP_INT_POS_COMP_READY - Position-compare ready EQEP_INT_POS_COMP_MATCH - Position-compare match EQEP_INT_UNDERFLOW - Position counter underflow EQEP_INT_OVERFLOW - Position counter overflow EQEP_INT_WATCHDOG - Watchdog time-out EQEP_INT_UNIT_TIME_OUT - Unit time-out EQEP_INT_QMA_ERROR - QMA error
-
void EQEP_disableInterruptMask(EQEP_Type *EQEPx, uint16_t intFlags)
Unmask eQEP module interrupts.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1] pointer to QEP module instance, [EQP0~EQP1]
intFlags – The intFlags parameter can be any of the following values OR or together: EQEP_INT_DIR_CHANGE - Quadrature direction change EQEP_INT_PHASE_ERROR - Quadrature phase error EQEP_INT_POS_CNT_ERROR - Position counter error EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch EQEP_INT_INDEX_EVNT_LATCH - Index event latch EQEP_INT_POS_COMP_READY - Position-compare ready EQEP_INT_POS_COMP_MATCH - Position-compare match EQEP_INT_UNDERFLOW - Position counter underflow EQEP_INT_OVERFLOW - Position counter overflow EQEP_INT_WATCHDOG - Watchdog time-out EQEP_INT_UNIT_TIME_OUT - Unit time-out EQEP_INT_QMA_ERROR - QMA error
-
uint16_t EQEP_getInterruptStatus(EQEP_Type *EQEPx)
Gets the current interrupt status.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint16_t Returned, as a bit field of the following values: EQEP_INT_DIR_CHANGE - Quadrature direction change EQEP_INT_PHASE_ERROR - Quadrature phase error EQEP_INT_POS_CNT_ERROR - Position counter error EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch EQEP_INT_INDEX_EVNT_LATCH - Index event latch EQEP_INT_POS_COMP_READY - Position-compare ready EQEP_INT_POS_COMP_MATCH - Position-compare match EQEP_INT_UNDERFLOW - Position counter underflow EQEP_INT_OVERFLOW - Position counter overflow EQEP_INT_WATCHDOG - Watchdog time-out EQEP_INT_UNIT_TIME_OUT - Unit time-out EQEP_INT_QMA_ERROR - QMA error
-
uint16_t EQEP_getInterruptRawStatus(EQEP_Type *EQEPx)
gets the interrupt raw status.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint16_t Returned, as a bit field of the following values: EQEP_INT_DIR_CHANGE - Quadrature direction change EQEP_INT_PHASE_ERROR - Quadrature phase error EQEP_INT_POS_CNT_ERROR - Position counter error EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch EQEP_INT_INDEX_EVNT_LATCH - Index event latch EQEP_INT_POS_COMP_READY - Position-compare ready EQEP_INT_POS_COMP_MATCH - Position-compare match EQEP_INT_UNDERFLOW - Position counter underflow EQEP_INT_OVERFLOW - Position counter overflow EQEP_INT_WATCHDOG - Watchdog time-out EQEP_INT_UNIT_TIME_OUT - Unit time-out EQEP_INT_QMA_ERROR - QMA error
-
void EQEP_clearInterruptStatus(EQEP_Type *EQEPx, uint16_t intFlags)
Clears eQEP module interrupt sources.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
intFlags – The intFlags parameter can be any of the following values OR or together: EQEP_INT_DIR_CHANGE - Quadrature direction change EQEP_INT_PHASE_ERROR - Quadrature phase error EQEP_INT_POS_CNT_ERROR - Position counter error EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch EQEP_INT_INDEX_EVNT_LATCH - Index event latch EQEP_INT_POS_COMP_READY - Position-compare ready EQEP_INT_POS_COMP_MATCH - Position-compare match EQEP_INT_UNDERFLOW - Position counter underflow EQEP_INT_OVERFLOW - Position counter overflow EQEP_INT_WATCHDOG - Watchdog time-out EQEP_INT_UNIT_TIME_OUT - Unit time-out EQEP_INT_QMA_ERROR - QMA error
-
void EQEP_forceInterrupt(EQEP_Type *EQEPx, uint16_t intFlags)
Forces eQEP module interrupts.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
intFlags – The intFlags parameter can be any of the following values OR or together: EQEP_INT_DIR_CHANGE - Quadrature direction change EQEP_INT_PHASE_ERROR - Quadrature phase error EQEP_INT_POS_CNT_ERROR - Position counter error EQEP_INT_STROBE_EVNT_LATCH - Strobe event latch EQEP_INT_INDEX_EVNT_LATCH - Index event latch EQEP_INT_POS_COMP_READY - Position-compare ready EQEP_INT_POS_COMP_MATCH - Position-compare match EQEP_INT_UNDERFLOW - Position counter underflow EQEP_INT_OVERFLOW - Position counter overflow EQEP_INT_WATCHDOG - Watchdog time-out EQEP_INT_UNIT_TIME_OUT - Unit time-out EQEP_INT_QMA_ERROR - QMA error
-
bool EQEP_getError(EQEP_Type *EQEPx)
Gets the encoder error indicator. It is an error for both of the signals of the quadrature input to change at the same time.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
bool
Return true if an error has occurred
Return false otherwise.
-
uint8_t EQEP_getStatus(EQEP_Type *EQEPx)
Get content of the eQEP module status register.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
uint16_t The value it returns is an OR of the following values: EQEP_STS_POS_CNT_ERROR - Position counter error occurred EQEP_STS_1ST_IDX_FLAG - Set by the occurrence of the first index pulse EQEP_STS_CAP_DIR_ERROR - Direction change occurred between position capture events EQEP_STS_CAP_OVRFLW_ERROR - Overflow occurred in eQEP capture timer EQEP_STS_DIR_LATCH - If set, clockwise rotation occurred on last index event marker EQEP_STS_DIR_FLAG - If set, movement is clockwise rotation EQEP_STS_DIR_ON_1ST_IDX - If set, clockwise rotation (forward movement) occurred on the first index event EQEP_STS_UNIT_POS_EVNT - Unit position event detected
-
void EQEP_clearStatus(EQEP_Type *EQEPx, uint8_t statusFlags)
Clears selected fields of the eQEP module status register.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
statusFlags – This function clears the status register fields indicated by statusFlags. The statusFlags parameter is the logical OR of any of the following: EQEP_STS_1ST_IDX_FLAG - Set by the occurrence of the first index pulse EQEP_STS_CAP_DIR_ERROR - Direction change occurred between position capture events EQEP_STS_CAP_OVRFLW_ERROR - Overflow occurred in eQEP capture timer EQEP_STS_UNIT_POS_EVNT - Unit position event detected
-
void EQEP_enableFilter(EQEP_Type *EQEPx)
enbale eQEP input signal filter
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
* void
-
void EQEP_disableFilter(EQEP_Type *EQEPx)
disable eQEP input signal filter
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
- 返回:
* void
-
void EQEP_setFilterRange(EQEP_Type *EQEPx, uint16_t len)
set eEQP output signal filter window range
- 参数:
EQEPx – pointer to eQEP module instance, [EQP0~EQP1]
len –
- 返回:
* void
-
void EQEP_setEmulationMode(EQEP_Type *EQEPx, EQEP_EmulationMode emuMode)
Set the emulation mode of the eQEP module.
- 参数:
EQEPx – pointer to QEP module instance, [EQP0~EQP1]
emuMode –
Structures
-
struct EQEP_SourceSelect
-
struct EQEP_CompareConfigParam
Macros
-
EQEP_CONFIG_QUADRATURE
-
EQEP_CONFIG_CLOCK_DIR
-
EQEP_CONFIG_UP_COUNT
-
EQEP_CONFIG_DOWN_COUNT
-
EQEP_CONFIG_2X_RESOLUTION
-
EQEP_CONFIG_1X_RESOLUTION
-
EQEP_CONFIG_NO_SWAP
-
EQEP_CONFIG_SWAP
-
EQEP_CONFIG_IGATE_DISABLE
-
EQEP_CONFIG_IGATE_ENABLE
-
EQEP_INT_DIR_CHANGE
-
EQEP_INT_PHASE_ERROR
-
EQEP_INT_POS_CNT_ERROR
-
EQEP_INT_STROBE_EVNT_LATCH
-
EQEP_INT_INDEX_EVNT_LATCH
-
EQEP_INT_POS_COMP_READY
-
EQEP_INT_POS_COMP_MATCH
-
EQEP_INT_UNDERFLOW
-
EQEP_INT_OVERFLOW
-
EQEP_INT_WATCHDOG
-
EQEP_INT_UNIT_TIME_OUT
-
EQEP_INT_QMA_ERROR
-
EQEP_STS_POS_CNT_ERROR
-
EQEP_STS_1ST_IDX_FLAG
-
EQEP_STS_CAP_DIR_ERROR
-
EQEP_STS_CAP_OVRFLW_ERROR
-
EQEP_STS_DIR_LATCH
-
EQEP_STS_DIR_FLAG
-
EQEP_STS_DIR_ON_1ST_IDX
-
EQEP_STS_UNIT_POS_EVNT
-
EQEP_INIT_DO_NOTHING
-
EQEP_INIT_RISING_STROBE
-
EQEP_INIT_EDGE_DIR_STROBE
-
EQEP_INIT_RISING_INDEX
-
EQEP_INIT_FALLING_INDEX
-
EQEP_LATCH_CNT_READ_BY_CPU
-
EQEP_LATCH_UNIT_TIME_OUT
-
EQEP_LATCH_RISING_INDEX
-
EQEP_LATCH_FALLING_INDEX
-
EQEP_LATCH_SW_INDEX_MARKER
-
EQEP_LATCH_RISING_STROBE
-
EQEP_LATCH_EDGE_DIR_STROBE
Enumerations
-
enum EQEP_CompareSyncOut
Values:
-
enumerator EQEP_COMPARE_IDX_SYNC_OUT
-
enumerator EQEP_COMPARE_STROBE_SYNC_OUT
-
enumerator EQEP_COMPARE_IDX_SYNC_OUT
-
enum EQEP_Compare_ShadowSigSel
Values:
-
enumerator EQEP_COMPARE_LOAD_ON_ZERO
-
enumerator EQEP_COMPARE_LOAD_ON_MATCH
-
enumerator EQEP_COMPARE_LOAD_ON_ZERO
-
enum EQEP_PositionResetMode
Values:
-
enumerator EQEP_POSITION_RESET_IDX
-
enumerator EQEP_POSITION_RESET_MAX_POS
-
enumerator EQEP_POSITION_RESET_1ST_IDX
-
enumerator EQEP_POSITION_RESET_UNIT_TIME_OUT
-
enumerator EQEP_POSITION_RESET_IDX
-
enum EQEP_CAPCLKPrescaler
Values:
-
enumerator EQEP_CAPTURE_CLK_DIV_1
-
enumerator EQEP_CAPTURE_CLK_DIV_2
-
enumerator EQEP_CAPTURE_CLK_DIV_4
-
enumerator EQEP_CAPTURE_CLK_DIV_8
-
enumerator EQEP_CAPTURE_CLK_DIV_16
-
enumerator EQEP_CAPTURE_CLK_DIV_32
-
enumerator EQEP_CAPTURE_CLK_DIV_64
-
enumerator EQEP_CAPTURE_CLK_DIV_128
-
enumerator EQEP_CAPTURE_CLK_DIV_1
-
enum EQEP_UPEVNTPrescaler
Values:
-
enumerator EQEP_UNIT_POS_EVNT_DIV_1
-
enumerator EQEP_UNIT_POS_EVNT_DIV_2
-
enumerator EQEP_UNIT_POS_EVNT_DIV_4
-
enumerator EQEP_UNIT_POS_EVNT_DIV_8
-
enumerator EQEP_UNIT_POS_EVNT_DIV_16
-
enumerator EQEP_UNIT_POS_EVNT_DIV_32
-
enumerator EQEP_UNIT_POS_EVNT_DIV_64
-
enumerator EQEP_UNIT_POS_EVNT_DIV_128
-
enumerator EQEP_UNIT_POS_EVNT_DIV_256
-
enumerator EQEP_UNIT_POS_EVNT_DIV_512
-
enumerator EQEP_UNIT_POS_EVNT_DIV_1024
-
enumerator EQEP_UNIT_POS_EVNT_DIV_2048
-
enumerator EQEP_UNIT_POS_EVNT_DIV_1
-
enum EQEP_QMAMode
Values:
-
enumerator EQEP_QMA_MODE_BYPASS
-
enumerator EQEP_QMA_MODE_1
-
enumerator EQEP_QMA_MODE_2
-
enumerator EQEP_QMA_MODE_BYPASS
-
enum EQEP_Source
Values:
-
enumerator EQEP_SOURCE_DEVICE_PIN
-
enumerator EQEP_SOURCE_ACMP0B
-
enumerator EQEP_SOURCE_ACMP1B
-
enumerator EQEP_SOURCE_ACMP2B
-
enumerator EQEP_SOURCE_ACMP3B
-
enumerator EQEP_SOURCE_ACMP0A
-
enumerator EQEP_SOURCE_ACMP1A
-
enumerator EQEP_SOURCE_ACMP2A
-
enumerator EQEP_SOURCE_ACMP3A
-
enumerator EQEP_SOURCE_XBAR_GRP0_PFXB0
-
enumerator EQEP_SOURCE_XBAR_GRP0_PFXB1
-
enumerator EQEP_SOURCE_XBAR_GRP0_PFXB2
-
enumerator EQEP_SOURCE_XBAR_GRP0_PFXB3
-
enumerator EQEP_SOURCE_XBAR_GRP0_PFXB4
-
enumerator EQEP_SOURCE_XBAR_GRP0_PFXB5
-
enumerator EQEP_SOURCE_XBAR_GRP1_PFXB0
-
enumerator EQEP_SOURCE_DEVICE_PIN