This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

51802 pwm

HELLO,

I am trying to generate a 125kHz pwm siginal using nrf51802(sdk version12.3). I use the oscilloscope to observe the wave form.I change the macro value of PERIOD_IN_US for different number, but the frequency did not change.The period of waveform is fixed 0.4ms,unless the frequency setting is less than 250 Hz .If I set frequency graeter than 250Hz, there is only one siginal in 0.4ms,but the width of the siginal is correct.

Thanks.

#define PERIOD_IN_US  8
#define ID_125K       17
APP_PWM_INSTANCE(m_pwm0,0);
static volatile bool ready_flag;            // A flag indicating PWM status.

static void pwm_callback(uint32_t pwm_id){
    ready_flag = true;
}
void pwm_init(){
    ret_code_t ret;
    nrf_gpio_cfg_output(ID_125K);
    nrf_gpio_pin_clear(ID_125K);
    app_pwm_config_t pwm_config = APP_PWM_DEFAULT_CONFIG_1CH(PERIOD_IN_US,ID_125K);
    pwm_config.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
    ret = app_pwm_init(&m_pwm0,&pwm_config,pwm_callback);
    if(ret){
        SEGGER_RTT_printf(0,"app_pwm_init fail!\r\n");
    }
    app_pwm_enable(&m_pwm0);
    app_pwm_channel_duty_set(&m_pwm0, 0, 50);

}

Related