Firefly开源社区

标题: QUINTIC的pwm [打印本页]

作者: thong    时间: 2015-4-20 10:31
标题: QUINTIC的pwm
最近准备用QUINTIC的PWM,把自带的PWM例程烧到板子里面去发现IO并没有PWM输出,不知道有没有试过PWM,所以想请教下问题在哪儿?
作者: FireBLE_blue    时间: 2015-4-20 14:41
本帖最后由 FireBLE_blue 于 2015-4-21 15:30 编辑

hi,thong
你说的自带的pwm例程是否是 \FireBLE\Demo_driver\pwm 下编译而来?如是请看确认main 函数和如下代码一致
  1. int main (void)
  2. {
  3.     SystemInit();

  4.     pwm_init(PWM_CH0);
  5.     pwm_io_config();
  6.     //P2.7 will output pwm wave with period for 1000us and pulse for 400us
  7.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(400, PWM_PSCAL_DIV));
  8.     pwm_enable(PWM_CH0, MASK_ENABLE);
  9.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));
  10.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(1000, PWM_PSCAL_DIV));
  11.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(0, PWM_PSCAL_DIV));
  12.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(400, PWM_PSCAL_DIV));
  13.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));
  14.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(1000, PWM_PSCAL_DIV));
  15.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(0, PWM_PSCAL_DIV));
  16.     pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));
  17.     pwm_enable(PWM_CH0, MASK_DISABLE);
  18.     pwm_io_dis_config();

  19.     pwm_init(PWM_CH1);
  20.     pwm_io_config();
  21.     //P2.6 will output pwm wave with period for 1500us and pulse for 1000us
  22.     pwm_config(PWM_CH1, 119, PWM_COUNT_US(1500, 119), PWM_COUNT_US(1000, 119));
  23.     pwm_enable(PWM_CH1, MASK_ENABLE);
  24.     pwm_io_dis_config();

  25.     while (1)                                /* Loop forever */
  26.     {

  27.     }
  28. }
复制代码


该份代码在单步仿真的情况下能得到pwm 输出,
如果你是编译后烧录进去的话,需要对代码做些小改动,至于怎么改动,请分析源码
作者: thong    时间: 2015-4-30 11:20
FireBLE_blue 发表于 2015-4-20 14:41
hi,thong
你说的自带的pwm例程是否是 \FireBLE\Demo_driver\pwm 下编译而来?如是请看确认main 函数和如 ...

void pwm_io_dis_config(void)
{

    syscon_SetPMCR1(QN_SYSCON, P27_GPIO_23_PIN_CTRL         //P2.7 GPIO
                             | P26_GPIO_22_PIN_CTRL         //P2.6 GPIO
                             );
    gpio_set_direction_field(GPIO_P27|GPIO_P26, GPIO_INPUT);
}
PWM不是输出吗,为什么这个地方的IO方向会是输入呢?
作者: FireBLE_blue    时间: 2015-5-4 08:56
  1. pwm_io_config();
复制代码

是配合pwm io 的配置
  1. pwm_io_dis_config();
复制代码

是配合pwm io 的反配置,注意关键字眼dis = disable




欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/) Powered by Discuz! X3.1