How can i add more pwms in nrf52840 example

I am working on CAF example Module and it has 4 pwms in overlay file.

1. Is it possible to add another PWM?

2. Is there any limit to number of PWMs and number of channels i can use on each pwm?

3. Can you please point me to any resource available?

4. Also how can i add more channels in single pwm?

Parents Reply Children
  • Thank you for your response. I am working on CAF module example and it has 4 pwm configured. correct me if i am wrong,
    1. but i believe those are 4 unique PWMs where each PWM can has 4 different channels.
    2. Each PWM can be set to a unique frequency and all channels of that PWM will share same frequency?
    3. The only thing channels on a single PWM can have different is Duty cycle?
    4. Now i want to modify that example to add more channels in a single PWM Instance so i can provide those signals to an RGB LED with different duty cycles on 3 channels of a single PWM Instance for color mixing. I could not find any example on how to do that.


  • Answers to your questions

    akay47 said:
    1. but i believe those are 4 unique PWMs where each PWM can has 4 different channels.

    Yes,  Can see instances here and four channel count which can be used in the nrfx_pwm_config as below

    nrfx_pwm_config_t const pwm_config = {
        .output_pins = { 22,                      // Channel 0 pin (set to your desired GPIO pin)
                         NRF_PWM_PIN_NOT_CONNECTED, // Channel 1
                         NRF_PWM_PIN_NOT_CONNECTED, // Channel 2
                         NRF_PWM_PIN_NOT_CONNECTED }, // Channel 3
                         ....

    akay47 said:
    3. The only thing channels on a single PWM can have different is Duty cycle?

    Yes, that is correct. In the nRF52840 PWM peripheral, all channels within a single PWM instance share the same frequency and period (top value), but they can have individual duty cycles

    akay47 said:
    Now i want to modify that example to add more channels in a single PWM Instance so i can provide those signals to an RGB LED with different duty cycles on 3 channels of a single PWM Instance for color mixing. I could not find any example on how to do that

    Yes, Something like this

    nrfx_pwm_t pwm_instance = NRFX_PWM_INSTANCE(0); // Use PWM instance 0
    
    nrfx_pwm_config_t const pwm_config = {
        .output_pins = { X,   // Red LED pin (Channel 0)
                         Y,   // Green LED pin (Channel 1)
                         Z,   // Blue LED pin (Channel 2)
                         NRF_PWM_PIN_NOT_CONNECTED }, // Channel 3 is not used
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_1MHz,  // 1 MHz base clock
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 1000,              // Adjust for PWM frequency (e.g., 1 kHz)
        .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
        .step_mode    = NRF_PWM_STEP_AUTO
    };

Related