Frequency Generator

int eq = ((16*10^6)/(2*8*500))-1;

10^6 is one million which won't fit in a 16-bit integer. You would be better off working out the constants yourself and using long integers.

[EDIT] Tested, it works [/EDIT]

int eq = 1000000L/freq-1;

Pete