Skip to content

[request] Increase number of supported PWM channels from 3 to 5 #156

Description

Summary

As per my post in the /silabs subreddit, it seems as though this core doesn't allow Arduino users to make use of more than 3 PWM pins, despite the MCU supporting more than that.

It was confusing to me because the Arduino Nano Matter product page specifies that up to 5 PWM channels can be used concurrently.

I know this repo isn't accepting community PRs right now, but here's what I've tried so far (without success):

  1. On cores/gecko/pwm.h, change line 127 from:
  static const uint8_t max_pwm_channels = 3u;

to:

  static const uint8_t max_pwm_channels = 5u;
  1. On cores/gecko/pwm.cpp, add below line 27:
#include "em_cmu.h"

and change line 74 from:

  this->pwm_pins[pwm_channel_idx].inst.channel = pwm_channel_idx;

to:

  // Map pwm_channel_idx to (timer, channel) pairs
  // Each timer has 3 channels (0, 1, 2)
  // Channels 0-2 use TIMER0, channels 3-5 use TIMER1, etc.
  uint8_t timer_num = pwm_channel_idx / 3;
  uint8_t channel_num = pwm_channel_idx % 3;

  TIMER_TypeDef* timer_map[] = {TIMER0, TIMER1, TIMER2, TIMER3, TIMER4};
  this->pwm_pins[pwm_channel_idx].inst.timer = timer_map[timer_num];
  this->pwm_pins[pwm_channel_idx].inst.channel = channel_num;

  // Enable the clock for the timer peripheral
  CMU_Clock_TypeDef timer_clocks[] = {cmuClock_TIMER0, cmuClock_TIMER1, cmuClock_TIMER2, cmuClock_TIMER3, cmuClock_TIMER4};
  CMU_ClockEnable(timer_clocks[timer_num], true);

and change line 78 from:

sl_pwm_init(&this->pwm_pins[pwm_channel_idx].inst, &pwm_config);

to:

  // Initialize the PWM - check if it succeeds
  sl_status_t status = sl_pwm_init(&this->pwm_pins[pwm_channel_idx].inst, &pwm_config);
  if (status != SL_STATUS_OK) {
    // PWM init failed - mark channel as free again
    this->pwm_pins[pwm_channel_idx].pin = PIN_NAME_MAX;
    return false;
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions