Sampling rate verification

[quote]This piece of code, generates a pulse of 29.41kHz on pin 6 - far from the expected 0.5MHz ...

.5Mhz means 2u or 32 ticks at 16MIPS. Your isr latency will take 10 - 20 ticks and that doesn't leave much to execution. One way to check for latency is to eliminate all code other than the pin flipping statement and see if you gain speed. If you do, latency is the issue.

Having said, 29.41khz sounds too low.