On Fri, Jun 5, 2020 at 11:51 AM Lee Jones <lee.jones@xxxxxxxxxx> wrote: > On Thu, 04 Jun 2020, Michael Walle wrote: ... > > + cycle = state->duty_cycle * config->max_duty_cycle; > > + do_div(cycle, state->period); > > Forgive my ignorance (I'm new here!), but what are these 2 lines > doing? Here we are multiplying the current duty_cycle with the > maximum value, then dividing by the period. > > So in the case of PWM_MODE_1KHZ with a 50% duty cycle, you'd have: > > (500000 * 0x20[16]) / 1000000 = [0x10]16 > > Thus, the above gives as a proportional representation of the maximum > valid value for placement into the cycle control register(s), right? > > Either way (whether I'm correct or not), I think it would be nice to > mention this in a comment. Maybe even clarify with a simple example. IIRC PWM has a helper for that (to calc period based on PWM state and new duty cycle %). -- With Best Regards, Andy Shevchenko