Hi everyone,
So I am having this weird behavior when i try to use the PWM with pin(1,9). In my case, i want to do pwm with a number of pin most of them are in port 0 like (2 ,28, 29, 30, 9, 31, 11, 15), and one of them in port 1 pin 9. My problem is when i reset and start up my program, if i include P(1,9) to my initialization, i always get all of the led to turn on after it finish initialization. But if i exclude port 1 pin 9 and use only pins from port 0, it works normally. So I just want to ask is there any way this can be explain and if it is can you tell me how to fix it. I think i might miss some extra flag or something. I also include my code for initialization. In it, i use 2 for-loops to dynamically putting all pin number (denote by pwm_config->pin_io[ ]) to a list of 4 in nrf_config_pwm.output_pins[ ] and init them in chunk of for one by one according to the nrf_config_pwm struct.
static nrf_drv_pwm_t g_pwm_array[4] = {NRF_DRV_PWM_INSTANCE(0), NRF_DRV_PWM_INSTANCE(1), NRF_DRV_PWM_INSTANCE(2), NRF_DRV_PWM_INSTANCE(3)};
nrfx_pwm_config_t nrf_config_pwm = {
.irq_priority = APP_IRQ_PRIORITY_MID,
.base_clock = pwm_cfg->freq,
.count_mode = NRF_PWM_MODE_UP_AND_DOWN,
.top_value = pwm_cfg->max_value,
.load_mode = NRF_PWM_LOAD_INDIVIDUAL,
.step_mode = NRF_PWM_STEP_AUTO};
uint8_t instance = CEIL_DIV(pwm_cfg->num_channel, 4);
for (uint8_t i = 0; i < instance; i++) {
for (uint8_t j = 0; j < 4; j++) {
if ((i * 4 + j) < periph_pwm->num_channel) {
nrf_config_pwm.output_pins[j] = pwm_cfg->pin_io[4 * i + j];
} else
nrf_config_pwm.output_pins[j] = NRF_DRV_PWM_PIN_NOT_USED;
}
nrf_drv_pwm_init(&g_pwm_array[i], &nrf_config_pwm, NULL);
}
I am using a NRF52833 SoC and NRF-SDK for thresh and zigbee 4.1.0
Thank you in advance and please reply soon.
Best regards,
Tu

