- * EXAMPLE: Assuming that SMCLK runs at 1 MHz the following command fills the
- * user buffer with 2000 conversion results sampled on channel A2 with a
- * sampling rate of 4000 Hz, i.e. the multipleDataReady() event is signalled
- * after 500 ms. Note that the sampling rate is defined by the combination of
- * SAMPCON_SOURCE_SMCLK, SAMPCON_CLOCK_DIV_1 and the "jiffies" parameter of
- * 250.
- *
- *
- * uint16_t buffer[2000];
- * msp430adc12_channel_config_t config = {
- * INPUT_CHANNEL_A2, REFERENCE_VREFplus_AVss, REFVOLT_LEVEL_1_5,
- * SHT_SOURCE_SMCLK, SHT_CLOCK_DIV_1, SAMPLE_HOLD_64_CYCLES,
- * SAMPCON_SOURCE_SMCLK, SAMPCON_CLOCK_DIV_1
- * };
- *
- * event void Resource.granted()
- * {
- * if (call SingleChannel.getMultipleData(&config, buffer, 2000, 250)
- * == SUCCESS)
- * {
- * // .. multipleDataReady() event will be signalled in 500ms
- * } else {
- * // check error
- * }
- * }
+ * EXAMPLE: Assuming that SMCLK runs at 1 MHz the following code snippet
+ * performs 2000 ADC conversions on channel A2 with a sampling period of 4000 Hz.
+ * The sampling period is defined by the combination of SAMPCON_SOURCE_SMCLK,
+ * SAMPCON_CLOCK_DIV_1 and a "jiffies" parameter of (1000000 / 4000) = 250.
+
+ #define NUM_SAMPLES 2000
+ uint16_t buffer[NUM_SAMPLES];
+
+ msp430adc12_channel_config_t config = {
+ INPUT_CHANNEL_A2, REFERENCE_VREFplus_AVss, REFVOLT_LEVEL_NONE,
+ SHT_SOURCE_SMCLK, SHT_CLOCK_DIV_1, SAMPLE_HOLD_64_CYCLES,
+ SAMPCON_SOURCE_SMCLK, SAMPCON_CLOCK_DIV_1
+ };
+
+ event void Boot.booted()
+ {
+ call Resource.request();
+ }
+
+ event void Resource.granted()
+ {
+ error_t result;
+ result = call SingleChannel.configureMultiple(&config, buffer, BUFFER_SIZE, 250);
+ if (result == SUCCESS)
+ call SingleChannel.getData();
+ }
+
+ async event uint16_t* SingleChannel.multipleDataReady(uint16_t *buf, uint16_t length)
+ {
+ // buffer contains conversion results
+ }