打印
[STM32F1]

大家帮忙看一下这个官方的例程

[复制链接]
1140|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
小小小小白|  楼主 | 2014-4-26 19:32 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
TE, TI, ST, AN, Value
  TIM1 DMA Transfer example -------------------------------------------------
  TIM1CLK = SystemCoreClock, Prescaler = 0, TIM1 counter clock = SystemCoreClock
  SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density
  and Connectivity line devices and to 24 MHz for Low-Density Value line and
  Medium-Density Value line devices.

  The objective is to configure TIM1 channel 3 to generate complementary PWM
  signal with a frequency equal to 17.57 KHz:
     - TIM1_Period = (SystemCoreClock / 17570) - 1
  and a variable duty cycle that is changed by the DMA after a specific number of
  Update DMA request.

  The number of this repetitive requests is defined by the TIM1 Repetition counter,
  each 3 Update Requests, the TIM1 Channel 3 Duty Cycle changes to the next new
  value defined by the SRC_Buffer .

  /* Compute the value to be set in ARR register to generate signal frequency at 17.57 Khz */
  TimerPeriod = (SystemCoreClock / 17570 ) - 1;
  /* Compute CCR1 value to generate a duty cycle at 50% */
  SRC_Buffer[0] = (uint16_t) (((uint32_t) 5 * (TimerPeriod - 1)) / 10);
  /* Compute CCR1 value to generate a duty cycle at 37.5% */
  SRC_Buffer[1] = (uint16_t) (((uint32_t) 375 * (TimerPeriod - 1)) / 1000);
  /* Compute CCR1 value to generate a duty cycle at 25% */
  SRC_Buffer[2] = (uint16_t) (((uint32_t) 25 * (TimerPeriod - 1)) / 100);

大概意思就是每产生三个更新请求就把SRC_Buffer的值通过DMA传送到比较寄存器。但是实际运行时占空比一直是37.5,通过串口打印出的结果也一直没变。这是什么原因?按理说占空比应该不断变化,从50、37.5、25


沙发
airwill| | 2014-4-26 22:45 | 只看该作者
这个功能是没有问题的. 我在 103上用过.  是不是设置有问题?

使用特权

评论回复
板凳
小小小小白|  楼主 | 2014-4-27 11:16 | 只看该作者
airwill 发表于 2014-4-26 22:45
这个功能是没有问题的. 我在 103上用过.  是不是设置有问题?

今天用示波器测了一下,3种占空比都有,不过50%的有六个,37.5%的有三个,25%的只有一个。感觉有点奇怪。

使用特权

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

本版积分规则

63

主题

515

帖子

4

粉丝