nRF|nRF PWM配置注意事项

/* 1-channel PWM, 2700Hz, output on BUZZER pins. */app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(365L, BUZZER_01); /* Switch the polarity of the second channel. */pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_LOW; /* Initialize and enable PWM. */err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback); APP_ERROR_CHECK(err_code); app_pwm_enable(&PWM1); app_pwm_channel_duty_set(&PWM1, 0, 50); APP_PWM_DEFAULT_CONFIG_1CH中第一个周期参数对应PWM波形频率。(默认5000L -> 对应200Hz)app_pwm_channel_duty_set(&PWM1, 0, 50); 表示占空比,即所选通道极性占比50%nrf_gpio_pin_clear(BUZZER_01); app_pwm_channel_duty_set(&PWM1, 0, 100); app_pwm_disable(&PWM1); /* Uninitialize and disenable PWM. */err_code = app_pwm_uninit(&PWM1); APP_ERROR_CHECK(err_code);

【nRF|nRF PWM配置注意事项】
注:在关闭PWM时若想直接关闭(应用场景:无源蜂鸣器):则首先要将电平置于关闭后再将占空比设为100%,而后失能及关闭PWM通道

    推荐阅读