10 years, 1 month ago.

Is there any way to control sampling speed of ADC

Specifically I want to increase the sampling rate on the FRDM-KL46Z. It seems like the maximum sampling rate is about 20 ksps. But the hardware can support 10x that amount. Does not seem there are any control options in AnalogIn().

1 Answer

10 years, 1 month ago.

You can manually set the registers of the KL46Z to change it. If you do that after making your AnalogIn object it will keep those settings and you can still use AnalogIn. Problem is that contrary to the LPC1768 for example, it isn't simply a max clock rate you can set, there is roughly a max, and all kind of settings to trade resolution/power against speed.

There is https://mbed.org/users/Sissors/code/FastAnalogIn/, which currently is only for the LPC1768, but Frank is working on a KLxx port, which should be finished soonish (read: expected coming days). It is more limitted though: the KL46 can only continiously convert a single channel, while the LPC1768 can do all sequentially. So it can do an instantanious read of the last conversion only on one pin. However it also allows for regular reads something like 4 times current speed (could still be faster as you point out, but at least it is a nice start).

Accepted Answer

This seems like a good solution. The register map from datasheet is a bit too complex for me to figure out. If the KLxx port is coming soon as you mentioned this would be ideal. The current 20 ksps rate for AnalogIn does not allow for very interesting audio processing. Thanks for the quick and helpful response.

posted by Near Margalit 06 Mar 2014

FastAnalogIn has been reworked. It now supports LPC1768 and KLxx. As Erik mentioned, do read the wiki as there are some limitations.

posted by Frank Vannieuwkerke 09 Mar 2014