Here is my power consumption (3.0V):
no app_pwm: 0.010mA
after app_pwm_init(): 0.295mA
after app_pwm_enable(): 0.891mA
If I do app_pwm_uninit(), power consumption goes back down to 0.010mA as expected.
The problem is that pwm will not work correctly after I run app_pwm_init()/app_pwm_enable() again.
APP_PWM_INSTANCE(PWM1,1);
static volatile bool ready_flag;
void pwm_ready_callback(uint32_t pwm_id) {
ready_flag = true;
}
void pwm_init() {
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, 28);
pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
APP_ERROR_CHECK(app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback));
app_pwm_enable(&PWM1);
//Adding the following four lines don't give the same behavior as not having them at all.
APP_ERROR_CHECK(app_pwm_uninit(&PWM1)); //does app_pwm_disable
pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH; //this should not be needed again and does not do anything the second time around
APP_ERROR_CHECK(app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback));
app_pwm_enable(&PWM1);
}
void test_pwm() {
while(app_pwm_channel_duty_set(&PWM1, 0, 5) == NRF_ERROR_BUSY);
}
This is not my actual code, but it demonstrates my problem. The code without the extra four lines in pwm_init() works as I expect. Why would adding those four lines not give the exact same behavior? For some reason, the pwm then acts as if its polarity is active_low.
Thanks.