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

NRF51 polarity low on reinit

When I init, uninit, and re-init a PWM with pin_polarity set to APP_PWM_POLARITY_ACTIVE_HIGH, the actual polarity of the signal is active low. This also happens when I init and enable, disable and uninit, then init and enable again, which is closer to my true use case.

I'm using nRF51_SDK 8.1.0, with the PWM driver from the devzone thread:
devzone.nordicsemi.com/.../ contained in the file: pwm_20150806.7z

Example code (error handling removed):

APP_PWM_INSTANCE(PWM2_RG,2);
uint32_t m_blue_pin = 25;

void pwm_init_instance_b()
{
  app_pwm_config_t pwm_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, m_blue_pin);

  pwm_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;

  app_pwm_init(&PWM1_B, &pwm_cfg, pwm1_ready_callback);
  app_pwm_uninit(&PWM1_B);
  app_pwm_init(&PWM1_B, &pwm_cfg, pwm1_ready_callback);
  app_pwm_enable(&PWM1_B);

  while (app_pwm_channel_duty_set(&PWM1_B,  0, 10) == NRF_ERROR_BUSY);
}
Parents
  • If you want to have good hold on pin state before and after PWM init and unit, then you need to initialize the pin to correct state using nrf_gpio.h nrf_gpio_cfg_xxx();

    Then when you init pwm, GPIOTE will own the pins and will initialize pin to the state configured with PWM API, after disabling pwm (or initializing) then gpio will take control.

    However, I remember that there were issues with PWM disable/enable features which were fixed in SDK10, look into this thread for more info regarding this.

  • Thank you for your reply. To clarify, the problem was with the behavior of the pwm when it was initted and running, not with the pin state when it wasn't running.

    I pulled in the app_pwm.[ch] files from version 10.0, keeping the rest of the SDK at 8.1, and this seems to have resolved the problem. I am a bit uncomfortable mixing files from different versions, but it seems to be the best solution for our project right now.

Reply
  • Thank you for your reply. To clarify, the problem was with the behavior of the pwm when it was initted and running, not with the pin state when it wasn't running.

    I pulled in the app_pwm.[ch] files from version 10.0, keeping the rest of the SDK at 8.1, and this seems to have resolved the problem. I am a bit uncomfortable mixing files from different versions, but it seems to be the best solution for our project right now.

Children
No Data
Related