Hi,
May be it's some what basic but I'm not able to update my pwm value.
I'm using sdk 14.02 with softdevice in SES.
This is my code:
PWM Config:
static uint16_t const base_pwm_top = 10000;
static uint16_t const base_pwm_step = 100;
static uint8_t pwm_phase;
static nrf_pwm_values_individual_t pwm_seq_values;
static nrf_pwm_sequence_t const pwm_seq =
{
.values.p_individual = &pwm_seq_values,
.length = NRF_PWM_VALUES_LENGTH(pwm_seq_values),
.repeats = 0,
.end_delay = 0
};
PWM init:
//Base PWM config
ret_code_t err_code_base;
// configure nrf driver
nrf_drv_pwm_config_t const config1 =
{
.output_pins =
{
BASE_PWM_PIN,//| NRF_DRV_PWM_PIN_INVERTED, // channel 0
NRF_DRV_PWM_PIN_NOT_USED,
NRF_DRV_PWM_PIN_NOT_USED,
NRF_DRV_PWM_PIN_NOT_USED,
},
.irq_priority = APP_IRQ_PRIORITY_LOWEST,
.base_clock = NRF_PWM_CLK_1MHz,
.count_mode = NRF_PWM_MODE_UP,
.top_value = base_pwm_top,
.load_mode = NRF_PWM_LOAD_INDIVIDUAL,
.step_mode = NRF_PWM_STEP_AUTO
};
err_code_base = nrf_drv_pwm_init(&m_base_pwm, &config1, base_pwm_event_handler);
APP_ERROR_CHECK(err_code_base);
if (err_code_base != NRF_SUCCESS)
{
// Initialization failed. Take recovery action.
NRF_LOG_INFO("PWM initialization failed");
}
Update pwm value in pwm event handler:
//base_pwm_event_handler
static void base_pwm_event_handler(nrf_drv_pwm_evt_type_t event_type)
{
if (event_type == NRF_DRV_PWM_EVT_FINISHED)
{
pwm_seq_values.channel_0 = base_pwm_val;
}
}
Update pwm sequence:
static void pwm_timer_timeout_handler(void *p_context)
{
UNUSED_PARAMETER(p_context);
pid_control_loop();
/* Update duty cycle cap PWM ... */
nrf_drv_pwm_simple_playback(&m_base_pwm, &pwm_seq, 1, NRF_DRV_PWM_FLAG_LOOP);
}