In general there are two ways to control DC motor speed: by varying supply voltage and pulse width modulation (PWM). First control method is not convenient especially in digital systems. It requires analog circuitry and so on. Second motor speed control method is very convenient for digital systems, because all control is made using only digital signals.
As you already know PWM (Pulse Width Modulation) is all about switching speed and pulse width (duty cycle). Duty cycle is ratio of signal time ON/T. T is period of signal.
In above diagram you see two signals. First duty cycle is about t1/T=1/3 and another’s duty cycle would be about t2/T=2/3. And notice the period of signals are the same.
If we apply these signals to switching transistor we would get control over effective voltage across motor:
Where tON-signal on time over one period T.
In this way you can control motor speed using microcontrollers PWM output or if you need you may use simple control motor PWM schematic constructed using IC555 timer circuit:
Without going too deep in to 555 timer’s performance analysis I can mention that duty cycle can be changed using potentiometer RV1. The period of signal won’t change as over all resistance between Vcc and 555 pin 6 does not change.
For more information about IC555 and its applications refer to: https://www.uoguelph.ca/~antoon/gadgets/555/555.html