Most people, even “history teachers,” have no idea why the compromise was written into the Constitution nor the debate surrounding the issue.
Southerners wished to count slaves as a whole person at the Philadelphia Convention, with one delegate from North Carolina even calling them “rational beings,” while Northerners rejected the idea and insisted that slaves were nothing more than chattel. You are correct that the heart of the debate was representation, and the underlying issue was specifically the taxing power of the government. Southerners feared that the North would tax them out of existence with direct taxes and navigation laws; thus, a higher population toward representation meant a better chance of blocking these laws. Mason even proposed a prohibition on navigation laws without a 2/3 majority. The 3/5 compromise was born out of an agreement between the SC and CT delegations.