Skip to content

Commit cdfa11f

Browse files
author
Daniel Campora
committed
cc3200: In Timer.callback() only use value param if in edge count mode.
1 parent e78a8c9 commit cdfa11f

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

cc3200/mods/pybtimer.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
/// tim = pyb.Timer(4) # create a timer object using timer 4
6464
/// tim.init(mode=Timer.PERIODIC) # initialize it in periodic mode
6565
/// tim_ch = tim.channel(Timer.A, freq=2) # configure channel A at a frequency of 2Hz
66-
/// tim_ch.callback(handler=lambda t:led.toggle()) # toggle a led on every cycle of the timer
66+
/// tim_ch.callback(handler=lambda t:led.toggle()) # toggle a LED on every cycle of the timer
6767
///
6868
/// Further examples:
6969
///
@@ -765,12 +765,14 @@ STATIC mp_obj_t pyb_timer_channel_callback (mp_uint_t n_args, const mp_obj_t *po
765765
break;
766766
case TIMER_CFG_A_CAP_COUNT:
767767
ch->timer->intflags |= TIMER_CAPA_MATCH << shift;
768+
// set the match value and make 1 the minimum
769+
MAP_TimerMatchSet(ch->timer->timer, ch->channel, MAX(1, args[3].u_int));
768770
break;
769771
case TIMER_CFG_A_CAP_TIME:
770772
ch->timer->intflags |= TIMER_CAPA_EVENT << shift;
771773
break;
772774
case TIMER_CFG_A_PWM:
773-
// special case for the match interrupt
775+
// special case for the PWM match interrupt
774776
ch->timer->intflags |= ((ch->channel & TIMER_A) == TIMER_A) ? TIMER_TIMA_MATCH : TIMER_TIMB_MATCH;
775777
break;
776778
default:
@@ -833,18 +835,6 @@ STATIC mp_obj_t pyb_timer_channel_callback (mp_uint_t n_args, const mp_obj_t *po
833835
// create the callback
834836
_callback = mpcallback_new (ch, args[1].u_obj, &pyb_timer_channel_cb_methods);
835837

836-
// get the value if given
837-
uint32_t c_value = MAX(0, args[3].u_int);
838-
ch->duty_cycle = MIN(100, c_value);
839-
840-
// reload the timer
841-
uint32_t period_c;
842-
uint32_t match;
843-
compute_prescaler_period_and_match_value(ch, &period_c, &match);
844-
MAP_TimerLoadSet(ch->timer->timer, ch->channel, period_c);
845-
// set the appropiate match value
846-
MAP_TimerMatchSet(ch->timer->timer, ch->channel, (_config == TIMER_CFG_A_PWM) ? match : c_value);
847-
848838
// enable the callback before returning
849839
pyb_timer_channel_callback_enable(ch);
850840
}

0 commit comments

Comments
 (0)