This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reassign PWM pin

I have 5 LEDs - ideally I would like to control the brightness of each one independently (i.e. 5 PWM channels). I'm using SDK 9.0 and SD 310. I have been looking at the PWM example, and it looks like I can configure 2 pwm channels per timer, so a total of 4 pwm channels if I use both timers. Is this correct?

Typically, I only use one LED at a time, so a less ideal solution would be to use a single PWM channel, and reassign it to the pin tied to the LED that I wish to control. In researching Nordic's PWM implementation, I fount that the current SDK 9.0 PWM example doesn't run with a SD loaded. However I read that in older SDKs pwm_init() had to be called prior to starting the stack.This would imply that changing the PWM output pin is not as simple as I had hoped. Nordic is constantly updating and improving their libraries. Is changing PWM output pins on the fly an option in SDK 9.0, if you are running SD 310? Is there anything unique that needs to be done when switching PWM output pins?

Thanks, Clint

Parents
  • You can have max 4 pwm channels, this is also limited to the number of GPIOTE channels on nRF51 which is 4.

    The PWM driver in the SDK runs with SoftDevice, but in SDK 9 there was problems regarding the app_pwm_init and app_pwm_enable functions. You should use the driver from SDK 10 (either do your project in this SDK or use the app_pwm files from this SDK). This driver have fixed a lot of things.

    You will have to uninit the pwm, assign a new pin and then init the pwm again to switch pin. More detailed:

    err_code = app_pwm_uninit(&PWM);
    APP_ERROR_CHECK(err_code);
    
    pwm_cfg.pins[0] = LED1;  //new pin
    
    err_code = app_pwm_init(&PWM,&pwm_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    
    app_pwm_enable(&PWM);
    
Reply
  • You can have max 4 pwm channels, this is also limited to the number of GPIOTE channels on nRF51 which is 4.

    The PWM driver in the SDK runs with SoftDevice, but in SDK 9 there was problems regarding the app_pwm_init and app_pwm_enable functions. You should use the driver from SDK 10 (either do your project in this SDK or use the app_pwm files from this SDK). This driver have fixed a lot of things.

    You will have to uninit the pwm, assign a new pin and then init the pwm again to switch pin. More detailed:

    err_code = app_pwm_uninit(&PWM);
    APP_ERROR_CHECK(err_code);
    
    pwm_cfg.pins[0] = LED1;  //new pin
    
    err_code = app_pwm_init(&PWM,&pwm_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    
    app_pwm_enable(&PWM);
    
Children
No Data
Related