digital output that will change at a frequency

So I have a motor project that I'm working on that will use a pid controller. The thing is that my motor will only turn on or off, so my pwm pin won't change the speed. It's a 24vdc motor. To do this I will need a way to turn my motor on or off rapidly so that it will control how fast the motor is. The motor is hooked up to an h-bridge that allows me to change the power from the 24v power supply on or off. How should I go about doing this?

weisserm9182:
The thing is that my motor will only turn on or off, so my pwm pin won't change the speed. It's a 24vdc motor. To do this I will need a way to turn my motor on or off rapidly so that it will control how fast the motor is. The motor is hooked up to an h-bridge that allows me to change the power from the 24v power supply on or off.

Controlling the speed of a motor via an H-bridge is a common use for the Arduino PWM output. Usual practice is to set the direction inputs on the H-bridge with Arduino digital outputs then switch the
** **en** **
able pin on the H-bridge with the PWM output (using analogWrite) to vary motor speed. By delving into the Arduino's control registers you can also manipulate the base PWM frequency.