On Thursday, September 06, 2018, Guenter Roeck wrote: > > > + if (counter > 255) > > > + counter = 0; > > > > This is difficult to understand. > > > > > + > > > + priv->count = 256 - counter; > > > > It sets priv->count to 256, meaning that 0x5B00 instead of > > 0x5Axx will be written into the counter register. That really > > asks for some explanation. > > > > No, wait, priv->count is an 8-bit variable, so this really sets > priv->counter to 0. I am getting more and more confused. Why > not just set "counter = 256" above to make it obvious if that > is what is supposed to happen ? That's a good point. The math is supposed to be: 256 - [number of ticks you want] = [register value] Where [number of ticks you want] must be <= 256 Of course it's 8-bit variable so it will work...but that's not obvious at first. I'll change it to: if (counter > 256) counter = 256; Chris