L298n speed control not working

You use "break;" eleven times. As you describe, it causes functions to get POPped off the stack before completion. You should write your code to avoid using "break;"... it seems to be a holdover from BASIC computer language.