From 764eb6747fd01e065d33732c585af5eca3d1d886 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Fri, 28 Dec 2018 12:03:03 +0100 Subject: [PATCH] Control of PWM duty cycle requires change of match value. --- drivers/sctimers.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/sctimers.c b/drivers/sctimers.c index 976d515..672f034 100644 --- a/drivers/sctimers.c +++ b/drivers/sctimers.c @@ -135,8 +135,13 @@ int sctimer_get_counter_val(uint8_t timer_num, uint32_t* val) /* Change the match value of a single timer channel */ int sctimer_set_match(uint8_t timer_num, uint8_t channel, uint32_t val) { - /* FIXME : To be done */ - return 0; + struct lpc_sct_timer* sct = LPC_SCTIMER; + + if ((timer_num != LPC_SCT) || (channel >= MAX_CHANNELS)) { + return -EINVAL; + } + sct->match_reload[ channel + 1 ] = val; + return sct->match[ channel + 1 ]; } struct common_operations sct_ops = { @@ -192,8 +197,6 @@ int sctimer_pwm_config(uint8_t timer_num, const struct lpc_timer_pwm_config* pwm /* Use a single state */ sct->state_var = 0; - /* No need to reload, match registers will keep their values */ - sct->config |= LPC_SCT_NORELOAD; /* All match/capture regs act as match registers */ sct->mode = 0; @@ -202,6 +205,7 @@ int sctimer_pwm_config(uint8_t timer_num, const struct lpc_timer_pwm_config* pwm uint32_t evt_ctrl = 0; sct->match[ i + 1 ] = pwm->match_values[i]; + sct->match_reload[ i + 1 ] = pwm->match_values[i]; /* Enable one event for state 0 for this match */ sct->event[ i + 1 ].state = LPC_SCT_EVT_EN_STATE(0); /* Setup the event to happen on given match channel and control the requested output */ @@ -221,6 +225,7 @@ int sctimer_pwm_config(uint8_t timer_num, const struct lpc_timer_pwm_config* pwm /* Select the channel 0 as the timer limit value to generate the PWM period. * Use autolimit, but configure an event anyway as we want to toggle the outputs as well */ sct->match[0] = pwm->period; + sct->match_reload[0] = pwm->period; sct->config |= LPC_SCT_AUTOLIMIT; sct->event[0].state = LPC_SCT_EVT_EN_STATE(0); sct->event[0].control = (LPC_SCT_MATCHSEL(0) | LPC_SCT_COMB_MODE_MATCH); -- 2.43.0