Hi All!
I have a problem running simple PWM output on NRF5340 board. I have a following code:
static nrf_pwm_values_individual_t values;
static nrf_pwm_sequence_t sequences;
const tPtHalPwm_device* nordic_device = device_get_binding( "PWM_0" );
const tPtHalPwmNrfxConfig *config = nordic_device->config;
config->initial_config.base_clock = NRF_PWM_CLK_125kHz;
config->initial_config.count_mode = NRF_PWM_MODE_UP;
config->initial_config.load_mode = NRF_PWM_LOAD_INDIVIDUAL;
config->initial_config.step_mode = NRF_PWM_STEP_AUTO;
config->initial_config.top_value = 62;
nrfx_pwm_uninit( &config->pwm );
nrfx_err_t res = nrfx_pwm_init( &config->pwm,
&m_ptHalPwm_configs[id],
pwmEventHandler,
( void* ) 0 );
values.channel_0 = ( 50UL | 1UL << 15 ); // High pulses
sequences.values.p_individual = &values;
sequences.length = NRF_PWM_VALUES_LENGTH(values);
sequences.repeats = 0;
sequences.end_delay = 0;
nrfx_pwm_simple_playback( &config->pwm, &sequences, 1, NRFX_PWM_FLAG_LOOP );
Now what i'm trying to achieve is to get 50% of duty cycle with frequency of 2 kHz. Just simple wave coming out of pin in PWM_0.
What i'm currently getting is indeed almost perfect 2 kHz frequency wave, but with duty cycle of 80%?
I was trying to test other duty cycle values, but results on the scope is following;
1% -> 1,6%
5% -> 8%
20% -> 32%
40% -> 64%
60% -> 96%
More than 70% -> always 100%.
Could you please give me a clue what is wrong with following code?