ADC platform interface proposal

classic Classic list List threaded Threaded
1 message Options
BogdanM BogdanM
Reply | Threaded
Open this post in threaded view

ADC platform interface proposal


Following is my proposal for a platform interface for the ADC peripheral. I
have only very limited experience with ADCs/DACs, in fact the only two
"serious" applications that I wrote and used ADCs were based on external
components and were quite basic on the data acquisition part, so you might
find this specification incomplete or just plain strange. If so, please let
me know so we can refine it to a better form.
I tried to extract a common set of features of ADCs from all the CPUs that
eLua currently supports, and this is what I came up with:

- most (or maybe all) of them support both "single shot" and "continous"
- some of them let the user select ADC timings (like startup time and
sample&hold time). This seems to be quite rare though, so I won't include it
in the platform interface.
- some of them also support a special mode in which they are "paired" with a
hardware timer and use that timer as a conversion clock. This is useful, and
it can be emulated even on platforms that don't support this feature.

With this in mind, this is what I came up with:

int platform_adc_exists( unsigned id ); // generic, it will be part of
u16 platform_adc_sample( unsigned id ); // sample the specified ADC channel
void platform_adc_start( unsigned id ); // starts a conversion on the
specified ADC channel and returns immediately
int platform_adc_is_done( unsigned id ); // returns 1 if the conversion on
the specified channel ended, 0 otherwise
void platform_adc_set_mode( unsigned id, int mode ); // sets the mode on the
specified ADC channel to either "single shot" or "continuous"
void platform_adc_burst( unsigned id, u16* buf, unsigned count, u32
frequency ); // burst conversion: read "count" samples from the ADC channel
"id", storing the results in "buf". The samples are read at periodic
intervals, the period is given by "frequency".

That's about it for now. What do you think?

-------------- next part --------------
An HTML attachment was scrubbed...