找回密码
 立即注册
查看: 411|回复: 4

PWM编码器计数溢出中断怎么用?

[复制链接]
  • 打卡等级:初来乍到
  • 打卡总天数:1
  • 最近打卡:2024-07-03 08:37:21

2

主题

6

回帖

32

积分

新手上路

积分
32
发表于 2024-7-3 13:04:10 来自手机 | 显示全部楼层 |阅读模式
PWM用于增量编码器正反转计数,计数最大65536,计数溢出时可以设置中断吗?在中断中可以判断是向上,还是向下溢出?百度查的都是stm的资料,我们stc的资料好少
回复

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:51
  • 最近打卡:2025-05-02 10:07:51

73

主题

5883

回帖

1万

积分

超级版主

积分
12079
发表于 2024-7-3 14:14:47 | 显示全部楼层
在中断使能寄存器PWMx_IER的bit0[UIEn]设置允许更新中断。
状态寄存器PWMx_SR1的bit0[UIFn]位中断标志,响应中断时由软件清0。
回复 支持 反对

使用道具 举报 送花

  • 打卡等级:初来乍到
  • 打卡总天数:1
  • 最近打卡:2024-07-03 08:37:21

2

主题

6

回帖

32

积分

新手上路

积分
32
发表于 2024-7-3 14:19:47 | 显示全部楼层
梁*** 发表于 2024-7-3 14:14
在中断使能寄存器PWMx_IER的bit0[UIEn]设置允许更新中断。
状态寄存器PWMx_SR1的bit0[UIFn]位中断标志,响 ...

/*   interrupt vector */
#define                INT0_VECTOR                0
#define                TIMER0_VECTOR        1
#define                INT1_VECTOR                2
#define                TIMER1_VECTOR        3
#define                UART1_VECTOR        4
#define                ADC_VECTOR                5
#define                LVD_VECTOR                6
#define                PCA_VECTOR                7
#define                UART2_VECTOR        8
#define                SPI_VECTOR                9
#define                INT2_VECTOR                10
#define                INT3_VECTOR                11
#define                TIMER2_VECTOR        12
#define                INT4_VECTOR                16
#define                UART3_VECTOR        17
#define                UART4_VECTOR        18
#define                TIMER3_VECTOR        19
#define                TIMER4_VECTOR        20
#define                CMP_VECTOR                21
#define                I2C_VECTOR                24
#define                USB_VECTOR                25
#define                PWMA_VECTOR                26        /* ¸ß¼¶PWMA */
#define                PWMB_VECTOR                27        /* ¸ß¼¶PWMB */
#define                TKSU_VECTOR                35        /* ´¥Ãþ°´¼üÖÐ¶Ï */
#define                RTC_VECTOR                36        /* RTCÖÐ¶Ï */
#define                P0INT_VECTOR        37        /* P0.0~P0.7ÖÐ¶Ï */
#define                P1INT_VECTOR        38        /* P1.0~P1.7ÖÐ¶Ï */
#define                P2INT_VECTOR        39        /* P2.0~P2.7ÖÐ¶Ï */
#define                P3INT_VECTOR        40        /* P3.0~P3.7ÖÐ¶Ï */
#define                P4INT_VECTOR        41        /* P4.0~P4.7ÖÐ¶Ï */
#define                P5INT_VECTOR        42        /* P5.0~P5.4ÖÐ¶Ï */
#define                P6INT_VECTOR        43        /* P6.0~P6.7ÖÐ¶Ï */
#define                P7INT_VECTOR        44        /* P7.0~P7.7ÖÐ¶Ï */
中断处理时应该用那个中断号

点评

PWMA_VECTOR或 PWMB_VECTOR  详情 回复 发表于 2024-7-3 14:31
回复 支持 反对

使用道具 举报 送花

  • 打卡等级:偶尔看看III
  • 打卡总天数:51
  • 最近打卡:2025-05-02 10:07:51

73

主题

5883

回帖

1万

积分

超级版主

积分
12079
发表于 2024-7-3 14:31:44 | 显示全部楼层
yangt*** 发表于 2024-7-3 14:19
/*   interrupt vector */
#define                INT0_VECTOR                0
#define                TIMER0_VECTOR        1

PWMA_VECTOR或 PWMB_VECTOR
回复 支持 反对

使用道具 举报 送花

  • 打卡等级:初来乍到
  • 打卡总天数:4
  • 最近打卡:2025-05-01 06:58:22

5

主题

184

回帖

1333

积分

金牌会员

积分
1333
发表于 2024-7-4 04:26:54 | 显示全部楼层
梁*** 发表于 2024-7-3 14:14
在中断使能寄存器PWMx_IER的bit0[UIEn]设置允许更新中断。
状态寄存器PWMx_SR1的bit0[UIFn]位中断标志,响 ...

If interrupts are enabled, the common 0xFFFF -> 0x0000 interrupt can be expected.
- but Quad can count both ways, so what happens on 0x000 -> 0xFFFF case ?

A rough extension is possible by checking timer HIGH byte, but that has a flaw if the counter overflows, and then immediately another pulse in the other direction reverses all bits, the correct action is no overflow at all, but the sticky interrupt flag says 'do 65k overflow' action.

To work properly, this needs two overflow flags, one for each direction.
回复 支持 反对

使用道具 举报 送花

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳国芯人工智能有限公司 ( 粤ICP备2022108929号-2 )

GMT+8, 2025-5-3 00:50 , Processed in 0.133334 second(s), 76 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表