So I'm currently attempting to write a routine that checks the output power level of an amplifier, if the power level is within 1% of where it's expected to be, it takes a THD measurement. It then increases the frequency by 3% and repeats the sequence until the THD reaches a set limit. (Say 2%) Once the upper THD limit has been reached, the routine needs to go back to the starting frequency and decrease by 3% then take measurements until THD hits the lower limit.
My question is, is it possible to do both the upper and lower frequency measurements in one loop? Or would it make more sense to break them into two separate loops? I've only just begun construction on this routine, so I don't have anything helpful to submit as an example.