[Open_electroporator] culture shock ADC and DMA

Nathan McCorkle nmz787 at gmail.com
Mon Aug 27 10:48:51 UTC 2018


On Wed, May 30, 2018 at 12:53 PM Nathan McCorkle <nmz787 at gmail.com> wrote:
> On Wed, May 9, 2018 at 8:20 AM, John Griessen <john at cibolo.com> wrote:
>> On 05/08/2018 03:37 AM, Nathan McCorkle wrote:
>>>  docs report 210kHz with no dropped samples from 2 ADCs. -- So that seems to be about the best we're going to do in a C loop reading the ADC in an ungated situation (i.e. as fast as we can go, since faster than this they were not getting the expected number of readings).
>>
>> Sounds good for using micropython code without getting into C language except for some register writes
>> and using DMA.
>
>
> I made some progress finding out how to quickly perform the register writes from C,
> https://forum.micropython.org/viewtopic.php?f=3&t=4847&p=27917#p27912
>
> So we're starting on our way to a control loop.


Alright, I believe I'm not seeing noise, and if correct then I must
have got the ADC hooked up so that both ADC channels are sampled in
series, and their values sent into RAM via DMA. Since they're sampling
in sequence, the ADC/DMA buffer has the values interleaved, but I've
'upgraded' (hacked for now) the GUI to de-interleave the data and
display both plots.

Now unless I've messed up somewhere, which is possible given the time
of night... the plots don't look that much different from each other:
https://imgur.com/7taOpRF
the upper should be the voltage
the lower should be the current

I can only imagine with real cells the current-graph will look a bit
different, or that's my hope anyway that it will show a positive spike
when the cells open up.


I also added other local changes I was using and had sitting around
(like enabling USB in boot.py, and some playing around before I update
mpboardconfig to fix the UART). Also there's the ADC patch for
MicroPython 1.9.4 (only single-channel ADC DMA)... which as discussed
before still isn't flashing for me... but I didn't want the file to
get lost on my machine in case we end up wanting 1.9.4 enough to get
the flashing to work.


Also, I realized that we've already got a busy-loop in place waiting
until the DMA buffer runs out and ADC conversions stop:
STATIC mp_obj_t adc_read_timed_stop(mp_obj_t self_in) {
  pyb_obj_adc_t *self = self_in;
  // wait for DMA to complete: could use ISR/callback
  // could do some control looping here!
  while (self->DMA_Handle.Instance->CR & DMA_SxCR_EN); // spin stream 0
  HAL_ADC_Stop_DMA(&self->handle);
  return mp_const_none;
}

so I think my next goal is to shove some simple voltage clamp code in
that loop instead of doing nothing... will need to sync on the timer
so we make sure we always have a push AND pull pulse before shutting
off the GPIO/PWM drivers (with quick reg-write). Another challenge
with the ADC grabbing two channels now is I have to ensure I'm only
working off of the last Voltage sample, which might be tricky since I
think we're running the ADC as fast as it can convert samples (rather
than syncing readings to the pulse timer).


-- 
-Nathan


More information about the open_electroporator mailing list