[STM32F1]

FOC里面的一个大bug?

[复制链接]
647|4
手机看帖
扫描二维码
随时随地手机跟帖
jishanlaike|  楼主 | 2020-10-24 11:34 | 显示全部楼层 |阅读模式
BUG, FOC, TI, TE, IO
1、TIM1定时器里先初始化,其中有一句
  if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
  {
    /* Set the Repetition Counter value */
    TIMx->RCR = Structure->RepetitionCounter;//Structure->RepetitionCounter == 1
  }

  /* Generate an update event to reload the Prescaler
     and the repetition counter (only for advanced timer) value immediately */
  TIMx->EGR = TIM_EGR_UG;
}
以上程序说明先设置了RCR并且用UG进行了更新。

之后程序执行到启动定时器的语句:
startTimers();    //先设置了RCR,再启动了定时器,而RCR=1为奇数,所以上溢发生更新事件。

而FOC的更新中断必须在下溢出时调用,来设置电流采样点,这就产生了矛盾,百思不得其解。。。。。

使用特权

评论回复
yiyigirl2014| | 2020-10-24 17:02 | 显示全部楼层
不至于吧?这是老型号啊。

使用特权

评论回复
airwill| | 2020-10-25 10:57 | 显示全部楼层
没有看明白你的问题点,   不知道是哪个版本,  溢出更新是硬件实现的. 通过寄存器的配置完成设置.
RCR 只是个重复计数器,  更上下溢出没有相关性

使用特权

评论回复
jishanlaike|  楼主 | 2020-10-25 21:39 | 显示全部楼层
airwill 发表于 2020-10-25 10:57
没有看明白你的问题点,   不知道是哪个版本,  溢出更新是硬件实现的. 通过寄存器的配置完成设置.
RCR 只是 ...

当RCR等于奇数时,比如1时,可以在上溢出时产生更新中断,也可以在下溢出时产生更新中断,如果在上更新时产生就会出问题,必须要在下更新时产生才可以,参考手册里有说明:
In center-aligned mode, for odd values of RCR, the update event occurs either on the
overflow or on the underflow depending on when the RCR register was written and when
the counter was started. If the RCR was written before starting the counter, the UEV occurs
on the overflow. If the RCR was written after starting the counter, the UEV occurs on the
underflow. For example for RCR = 3, the UEV is generated on each 4th overflow or
underflow event depending on when RCR was written

使用特权

评论回复
airwill| | 2020-10-26 10:27 | 显示全部楼层
对于 中心对称 的 PWM 方式,  你可以设定下溢更新, 完全可以避免上溢更新的呢

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

10

主题

21

帖子

1

粉丝