May I make a suggestion? Instead of trying to process an interrupt every 62.5 uS. You can use some of the hardware available in the STM32F205. What might work for you would be to
- Setup your ADC to use DMA.
- setup your timer to instead of interrupting you, to tell the ADC to sample. and when it is done to tell the DMA that a sample is finished.
- setup a buffer that is twice the size you want to deal with. The size will determine how much real time you have from the time you detect the first half of the buffer is full, untill you have to have cleared it (untill the second half of the buffer is full).
4 Set the DMA to interrupt you at the half-full mark and the full mark and to wrap around at the end of the buffer.
so what all this gets you is this. You can sample your signal at very high rates with very little CPU overhead. You will only have to deal with a buffer every time it gets half full. This let’s you sample in your case at 16000 and if your buffer is 2048 samples you will get an interrupt every 64 mS. in that 64mS you must deal with the data in the half of the buffer that was just captured. Then you have what is left of the 64mS to do whatever before the next half buffer full and you need to deal again.
I am using this technique to capture audio at 8000 and run FFT on it to get the level in the bins and then display it on a LED matrix. (looks cool). The limit for me is the time it takes to do FFT on the M3 core. But it seems that your speed would be limited by the size of the buffer. (I also ran out of RAM, the FFT needs some arrays.).
The one comment I will make about the technique of getting an interrupt every 62.5 uS on a system like the Particle which is running a small OS. Your code may not run a deterministic time after the actual interrupt due to higher priority interrupts and the system disabling interrupts when it needs to do things, This results in jitter in your sample. This technique is much better suited to an bare-metal system where you have control of the priorities of interrupts and when they get disabled or not.
The technique I described does suffer from this issue. In fact what I did in the interrupt was to set a flag that the loop code checked and when set the loop code would process that half of the buffer that was ready. Then it would clear the flag. If the interrupt ever got a buffer full interrupt and the next buffer flag wasn’t clear it marked an overrun.
anyway I have some test code that does exactly what I described, that I can put up somewhere if you would like to see it.