summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-04-11 14:08:23 +1000
committerDamien George <damien.p.george@gmail.com>2018-04-11 14:09:09 +1000
commitaebd9701a78d267cb264d400804b02c5b7a00e9a (patch)
treef8595c61c5f3ce259726c4d296e90f285ef1309a
parent4f40fa5cf4de7a8eabe073493e2df54c8a08ea89 (diff)
stm32/adc: Optimise read_timed_multi() by caching buffer pointers.
-rw-r--r--docs/library/pyb.ADC.rst7
-rw-r--r--ports/stm32/adc.c6
2 files changed, 7 insertions, 6 deletions
diff --git a/docs/library/pyb.ADC.rst b/docs/library/pyb.ADC.rst
index c2d09ad40..1256c6a3c 100644
--- a/docs/library/pyb.ADC.rst
+++ b/docs/library/pyb.ADC.rst
@@ -125,9 +125,10 @@ Methods
The maximum rate depends on factors including the data width and the
number of ADC's being read. In testing two ADC's were sampled at a timer
- rate of 140KHz without overrun. Samples were missed at 180KHz. At high
- sample rates disabling interrupts for the duration can reduce the risk
- of sporadic data loss.
+ rate of 210kHz without overrun. Samples were missed at 215kHz. For three
+ ADC's the limit is around 140kHz, and for four it is around 110kHz.
+ At high sample rates disabling interrupts for the duration can reduce the
+ risk of sporadic data loss.
The ADCAll Object
-----------------
diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c
index ba1ca5ce5..f765870d5 100644
--- a/ports/stm32/adc.c
+++ b/ports/stm32/adc.c
@@ -475,12 +475,14 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(buf_array[0], &bufinfo, MP_BUFFER_WRITE);
size_t typesize = mp_binary_get_size('@', bufinfo.typecode, NULL);
+ void *bufptrs[nbufs];
for (uint array_index = 0; array_index < nbufs; array_index++) {
mp_buffer_info_t bufinfo_curr;
mp_get_buffer_raise(buf_array[array_index], &bufinfo_curr, MP_BUFFER_WRITE);
if ((bufinfo.len != bufinfo_curr.len) || (bufinfo.typecode != bufinfo_curr.typecode)) {
mp_raise_ValueError("size and type of buffers must match");
}
+ bufptrs[array_index] = bufinfo_curr.buf;
}
// Use the supplied timer object as the sampling time base
@@ -541,9 +543,7 @@ STATIC mp_obj_t adc_read_timed_multi(mp_obj_t adc_array_in, mp_obj_t buf_array_i
if (typesize == 1) {
value >>= 4;
}
- mp_buffer_info_t bufinfo_curr; // Get buf for current ADC
- mp_get_buffer_raise(buf_array[array_index], &bufinfo_curr, MP_BUFFER_WRITE);
- mp_binary_set_val_array_from_int(bufinfo_curr.typecode, bufinfo_curr.buf, elem_index, value);
+ mp_binary_set_val_array_from_int(bufinfo.typecode, bufptrs[array_index], elem_index, value);
}
}