Carbon deposits can cause a rise in compression ratio. That rise in compression ratio will cause detonation if everything else stays the same. Try running some of that cleaner that is supposed to get rid of carbon deposits and see what happens.
Or try stepping up in the octane rating of the gas you use. That would also get rid of your knocking.