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

[PWM DRIVER] Using PWM with Port 1 Pin 9 problem when reset

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

  • Is it only pin 9 or port 1, or any pins on port1? Is it the same if you remove pins from port0?

    Can it be that the code is asserting or hard fault?

    Can you manually readback or set the PSEL.OUT[] register for comparison?

    Kenneth

  • Hi Kenneth,

    I am only test with pin(1,9) i have not tried with any pin because apparently with package of 41 pins that i am using, there are no others pin from port 1 rather than pin(1,9).

    I also tried to remove pins from port 0, but it did not make any difference. I have a hard fault handler in my code so whenever it reset i would have know. Also,  I took this code from the example of pwm_driver in the SDK.

    And I can also feel that you are not fully understand my problem, so it is like this. When i have pin(1,9) in my list of pwm pins, i am always see a weird behaviuor that the led is fully lit right after i initialized the pwm and because i initialize pwm everytime i start my application, the led alway light up by default. After that, i can control the pwm of every pin normally. And when i exclude the Pin(1,9) the bug just go away. So I guess that there are some special things that need to be done when using port 1 as PWM.

    Thank you and have a nice day, i will try to read back the PINSEL reg before and after init for you

    Best regards,

    TU

  • Can you make a simplified example I can run on an nRF52833-DK to recreate this? If I understand your latest description correctly it may look like the default polarity of the pwm pins are inverted when p1.9 is configured. Don't quite see how that is may occur, does configuring the pin using nrf_gpio() have any impact?

    Kenneth

  • Hi Kenneth,

    Sorry for the late reply, I was in quarantine for the last 2 weeks so i could not make an example for you. I made a bare minimal example to init and set all value of PWM to 0. In the real code, I also do the same, but use a timer to increase/decrease the value of PWM in time accroding to my application. However, I can not share my full code base to you, so may be you have to add some library in makefile yourself to run it in the DK. Also setting the pin using nrf_gpio have no impact to the code.

    Sorry for the inconvinience,

    Best regards,

    Tu

    pwm_example.zip

  • Hi Kenneth,

    Is there any update on the problem?

    Please inform me if there is something I can do to fix the problem.

    Tu

Related