Frequency-modulated atomic force microscopy (FM-AFM; also called non-contact atomic force microscopy) is the prevailing operation mode in (sub-)atomic resolution vacuum applications. A major obstacle that prohibits a wider application range is the low frame capture rate. The speed of FM-AFM is limited by the low bandwidth of the automatic gain control (AGC) and frequency demodulation loops. In this work we describe a novel algorithm that can be used to overcome these weaknesses. We analysed the settling times of the proposed loops and that of the complete system, and we found that an approximately 70-fold improvement can be achieved over the existing real and virtual atomic force microscopes. We show that proportional-integral-differential controllers perform better in the frequency demodulation loop than conventional proportional-integral controllers. We demonstrate that the signal to noise ratio of the proposed system is 5.7 × 10(-5), which agrees with that of the conventional systems; thus, the new algorithm would improve the performance of FM-AFMs without compromising the resolution.