[技术问答] PWM与定时器不能同是开?

[复制链接]
1336|4
 楼主| liu210802 发表于 2016-5-26 15:00 | 显示全部楼层 |阅读模式
最近在调试100时遇到PWM与定时器只能使用一个的问题,两个外设同时用在调试是程序就会卡死
代码如下:基本使用的都是官方的库函数,请大家帮我看看问题出在什么地方
  1. #include "nano1xx.h"
  2. //#include <stdio.h>
  3. #include "nano1xx_gpio.h"
  4. #include "nano1xx_pwm.h"
  5. #include "nano1xx_timer.h"
  6. void GPIOInit(void);
  7. void TimerInit(void);
  8. void PWMInit(uint8_t pwmch);
  9. void delay(uint16_t cnt);
  10. int32_t main()
  11. {
  12.                 SystemInit();
  13.                 GPIOInit();
  14.                 PWMInit(0);               
  15.                 TimerInit();
  16.                 TIMER_Start(TIMER1);
  17.                 PWM_Enable(0);
  18.                 while(1)
  19.                 {
  20.                                 GPIO_ClrBit(GPIOB,10);        
  21.                 }

  22. }       
  23. void GPIOInit(void)
  24. {
  25.         GPIO_Open(GPIOB, GPIO_PMD_PMD10_OUTPUT, GPIO_PMD_PMD10_MASK);
  26. }
  27. void PWMInit(uint8_t pwmch)
  28. {
  29.                 S_DRVPWM_TIME_DATA_T PWMcfg;
  30.                 GCR->PA_H_MFP = (GCR->PA_H_MFP & ~(PA12_MFP_MASK | PA13_MFP_MASK)) |
  31.                                                         PA12_MFP_PWM0_CH0 | PA13_MFP_PWM0_CH1;
  32.                 GPIO_Open(GPIOA, GPIO_PMD_PMD12_OUTPUT|GPIO_PMD_PMD13_OUTPUT, GPIO_PMD_PMD12_MASK|GPIO_PMD_PMD13_MASK);
  33.                 PWM_Init(pwmch);
  34.                 PWMcfg.u8Mode = PWM_CTL_CHMOD_AUTO_RELOAD;
  35.                 PWMcfg.u8PreScale = 1;                // actually 1 + 1
  36.                 PWMcfg.u8Div = PWM_CLKSEL_CLKSEL_DIV1;
  37.                 PWMcfg.u32Cn = 6000000 / 500 - 1;                                //set FREQ
  38.                 PWMcfg.u16Cm = (PWMcfg.u32Cn / 10)*3;                //set PWM_DUTY
  39.                 PWMcfg.u8Inv = 0;
  40.                 PWM_SetClk(pwmch, &PWMcfg);
  41.                 PWM_ConfigOutput(0, 1);
  42.                 PWM_EnableInt(0);
  43. }
  44. void TimerInit()
  45. {
  46. //        TIMER_Init(TIMER0, 11, 10000, TIMER_CTL_MODESEL_PERIODIC);
  47.         TIMER_Init(TIMER1, 11, 10000, TIMER_CTL_MODESEL_PERIODIC);
  48. //        TIMER_EnableInt(TIMER0, TIMER_IER_TMRIE);
  49.         TIMER_EnableInt(TIMER1, TIMER_IER_TMRIE);
  50. }
  51. void delay(uint16_t cnt)
  52. {
  53.         uint16_t i;       
  54.         for(i = 0;i < cnt;i++);
  55. }
wahahaheihei 发表于 2016-5-26 15:19 | 显示全部楼层
好多人都说共用一个定时器是不行的,你还是分别用一个就可以了吧。
 楼主| liu210802 发表于 2016-5-26 15:27 | 显示全部楼层
wahahaheihei 发表于 2016-5-26 15:19
好多人都说共用一个定时器是不行的,你还是分别用一个就可以了吧。

没看明白,哪里公用一个定时器了?请说的详细写以前没用过cotex-M0的片子
Thethree 发表于 2016-5-26 21:03 | 显示全部楼层
两个好像不能够同时用一个定时器
天灵灵地灵灵 发表于 2016-5-26 23:52 | 显示全部楼层
应该说PWM的时候是会使用到定时器的,而使用的这个定时器你就不能再去玩定时器中断了,冲突了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部