To drive a dc motor, we need to add a capacitor in parallel with the motor. How do we decide the capacitance of the capacitor?
In case of a stepper motor, there are two coils. Do we need to use two capacitors? If we use a single capacitor for both coils, how do we decide the capacitance of the capacitor?
The cap you see in parallel with most brushed dc motors is to help reduce the electrical noise that the motor produces from the brushes moving across the contacts. It filters the fast spikes that can cause problems in the rest of the circuit.
The diode is used to provide a safe path for the current in the motor coils. Called a "flyback diode" This is to provide a current path when the motor is freewheeling (power is removed, or pwm off cycle) so that voltage doesn't rise and damage the circuit.
Brushless motors and Stepper motors generally have less electrical motor noise than brushed motors, You don't normally see the capacitor across the coils. You still need good decoupling for your power source however.