Algorithm speed controller


I use a motor driver to drive two small motors (

The motors are controlled using PWM values from 0 to 255. I use a USB controller (with a small VB interface) to send PWM values to the arduino. I works something like this:

Every time a specific button is pressed a fixed value is added to the PWM value:

PWM = PMW + 5 (for example).

The problem is this builds up the PWM values linear. A disadvantage of this is that is takes a few steps before the motors really gain speed (the first few steps don't let the motors turn)

I would like to implement a logarithmic function that quickly builds up the first few steps. With a maximum of 255 and a minimum of 0 (I think zero will be a problem).

Is there anyone with some experience or some (other) ideas?

Use a lookup table.

Work out, say 10 speeds that actually make a difference, and put those values into a 10 entry constant arraay. Your commands now simple index the table, which yields a 0..255 PWM value.