Some electrophysiology experiments require periodically firing neurons. One example is when measuring a neuron's phase response curve (PRC) where a neuron is stimulated with a synaptic input and the perturbation in the neuron's period is measured as a function of when the stimulus is applied. However, even regular spiking cells have considerable variations in their period. These variations can be categorized into two types: jitter, which characterizes the rapid changes in interspike intervals (ISIs) from spike to spike, and drift, which is a slow change in firing rate over seconds. The jitter is removed by averaging the phase advance of a synaptic input applied at a particular phase several times. The drift over long time scales results in a systematic change in the period over the duration of the experiment which cannot be removed by averaging. To compensate for the drift of the neuron over minutes, we designed a linear proportional-integral (PI) controller to slowly adjust the applied current to a neuron to maintain the average firing rate at a desired ISI. The parameters of the controller were calculated based on a first-order discrete model to describe the relationship between ISI and current. The algorithm is demonstrated on pyramidal cells in the hippocampal formation showing ISIs from the neuron in an open loop (constant applied current) and a closed loop (current adjusted by a spike rate controller). The advantages of using the controller can be summarized as: (1) there is a reduction in the transient time to reach a desired ISI, (2) the drift in the ISI is removed allowing for long experiments at a desired spiking rate and (3) the variance is diminished by removing the slow drift. Furthermore, we implemented an auto-tuning algorithm that estimates in real time the coefficients for each clamped neuron. We also show how the controller can improve the PRC estimation. The program runs on Real-Time eXperiment Interface (RTXI), which is Linux-based software for real-time data acquisition and control applications.