FireBLE/PWM driver

来自Firefly wiki
跳转至: 导航搜索

Introduction

PWM(pulse-width modulation)refers to the pulse width modulation technology,with each pulse width were listed as equal pulse PWM waveform,by changing the pulse cycle can be frequency modulation ,Change the pulse width or duty cycle can pressure regulating,using appropriate coordination control method can make the voltage and frequency change.QN902xContains two road PWM ,cycle and duty cycle are 8 bit PWM output channel.

Initialization

Refer to routines system_init to initialize,configuration GPIO.

    SystemInit();
    pwm_io_config();

PWM_CH0 Use

First test PWM_CH0 (GPIO_P27).
Initialize PWM_CH0 and open the PWM interrupt.

pwm_init(PWM_CH0);

Configuration PWM output parameters

pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(400, PWM_PSCAL_DIV));

  • PWM_PSCAL_DIV as the clock points frequency coefficient of the PWM,in the use of open timer bypass for 63,when you don't open for 15,open by default.
  • <code>PWM_COUNT_US(1000, PWM_PSCAL_DIV)express configuration PWM clock cycle is 1000 us.
  • <code>PWM_COUNT_US(400, PWM_PSCAL_DIV) express configuration of the PWM pulse width is 400 us.


Enable PWM_CH0 output

    pwm_enable(PWM_CH0, MASK_ENABLE);

After enabling,change the PWM configuration directly,can realize different duty ratio output

    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(1000, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(0, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(400, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(1000, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(0, PWM_PSCAL_DIV));
    pwm_config(PWM_CH0, PWM_PSCAL_DIV, PWM_COUNT_US(1000, PWM_PSCAL_DIV), PWM_COUNT_US(800, PWM_PSCAL_DIV));

Disable PWM_CH0 output

    pwm_enable(PWM_CH0, MASK_DISABLE);

Disable PWM IO multiplex

    pwm_io_dis_config();

PWM_CH1 use

PWM_CH1 adopted more custom configure PWM_CH1 output frequency coefficient.


Initialize PWM_CH1 first, open the interrupt.

    pwm_io_config();
    pwm_init(PWM_CH1);

Configure PWM_CH1 output parameters,using the custom points frequency coefficient

    //P2.6 will output pwm wave with period for 1500us and pulse for 1000us
    pwm_config(PWM_CH1, 119, PWM_COUNT_US(1500, 119), PWM_COUNT_US(1000, 119));

Disable PWM_CH1 output

    pwm_enable(PWM_CH1, MASK_ENABLE);
    pwm_io_dis_config();