To give you an example, you can use TBASIC SETPWM command to setup Pulse Width modulated output to connect to a small motor
SETPWM 1,5000, 2000
The above setup the output to 50% duty cycle, by varying the duty cycle you can change the average amount of DC voltage applied to the motor and hence the speed can change.
To close the loop, you can use the PMON command to setup a pulse measurement function to measure incoming pulse frequency or period on Pulse Measurement channel #1
PMON 1 ' execute this in a 1st.Scan custom function
You will then use a 0.05s clock pulse to trigger another custom function, which will measure the PULSEFREQUENCY to calculate the actual speed of the motor. If it is below the desired speed, then you will have to increase the duty cycle to PWM. If it is above, then you decrease the PWM duty cycle. This is a simple but crude method. A more elegant method is to apply the PID method to control the motor speed. But you need some PID control background to understand how to scale the input and output for PID control.
However, please note that you can't simulate this program because it is difficult to simulate the incoming pulse stream