static void init_direct_pwm(void) { // Get the base PWM instance (PWM20 for pwm_led0) pwm_hw = NRF_PWM20; // Configure PWM pins for direct access - use an array for pins uint32_t pin_array[NRF_PWM_CHANNEL_COUNT] = { NRF_GPIO_PIN_MAP(0, 3), // P0.03 from overlay for first channel NRF_PWM_PIN_NOT_CONNECTED, // Unused channels NRF_PWM_PIN_NOT_CONNECTED, NRF_PWM_PIN_NOT_CONNECTED }; // Set up pins properly with array nrf_pwm_pins_set(pwm_hw, pin_array); // With 16MHz clock, each tick is 62.5ns (1/16MHz) // For a period of 5000ns (5μs), we need 80 ticks // Formula: period_ticks = desired_ns / 62.5 uint32_t period_ns = 5000; // 10μs expressed in ns period_ticks = period_ns / 62.5; // Convert ns to PWM ticks (160 ticks) // Configure PWM parameters - 16MHz clock, counting up mode, period in ticks nrf_pwm_configure(pwm_hw, NRF_PWM_CLK_16MHz, // Use fastest clock (16MHz) NRF_PWM_MODE_UP, // Count up mode period_ticks); // Period in ticks (calculated from ns) // Set up sequence for continuous PWM output static nrf_pwm_sequence_t seq = { .values.p_common = pwm_seq_values, .length = 1, .repeats = 0, .end_delay = 0 }; // Configure PWM decoder for simple mode nrf_pwm_decoder_set(pwm_hw, NRF_PWM_LOAD_COMMON, NRF_PWM_STEP_AUTO); // Set up the sequence nrf_pwm_sequence_set(pwm_hw, 0, &seq); // Configure for infinite looping nrf_pwm_loop_set(pwm_hw, 0xFFFF); // Loop indefinitely // Enable PWM peripheral nrf_pwm_enable(pwm_hw); // Start PWM generation nrf_pwm_task_trigger(pwm_hw, NRF_PWM_TASK_SEQSTART0); pwm_seq_values[0] = period_ticks / 2; nrf_pwm_task_trigger(pwm_hw, NRF_PWM_TASK_SEQSTART0); LOG_INF("PWM Test: Set initial 50%% duty cycle (%u)", pwm_seq_values[0]); LOG_INF("Direct PWM hardware access initialized"); } /looping pwm code /* Calculate PWM duty cycle */ uint16_t pwm_value = (uint16_t)(((uint64_t)period_ticks * value) / 16383U); /* Direct hardware update */ pwm_seq_values[0] = pwm_value; nrf_pwm_task_trigger(pwm_hw, NRF_PWM_TASK_SEQSTART0);
Hi
I am trying to port some PWM code from the NRF54L15 it uses HAL access because i have found it has faster writes which are useful for my application (testing latency and reproducing a signal) but it is building but i am not getting any outputs on the oscilloscope connected to the port 0, 03 pin. I have atteched the init code. It worked when i was using the nrf52840.