This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Cortex M4 (LPC4370): how do I detect ADC threshold crossing while moving data in a DMA driven double buffer?

Hi to you all,

I'm currently working on a project involving the LPC-Link2 as a eval. board for it's LPC4370 (for a complete explanation see this question).
What I'm trying to do is:

  • Continuously sample external analog signal (using on-board ADCHS)
  • Transfer data to RAM (I'm using a ping-pong buffer: let's call the sub-buffers s[0] and s[1])
  • When a threshold crossing is detected by the ADCHS -> begin data processing

At the moment I managed to be fine with the first 2 bullets, my question is: what is the fastest (and most elegant) way to process data without loosing (too much) samples and whitout interferring with DMA activity?

I tried the following procedure:

  • Use ADCHS interrupt (highest priority) to capture the address at which the DMA is currently pointing (eg. in sub-buffer s[0])
  • Process the data in the DMA ISR (eg. when s[1] is being filled)

BUT, it seems that I'm haviong troubles because of the cortex M4 ISR overhead. A drawing will better explain this:

The * in the image means:

  • ADCHS sampled the threshold-crossing responsible semple in s[1], thus flagging to process s[1]
  • By the time the DMA ISR gets the ADCHS flag s[1] is being filled and the DMA ISR won't process it.

How do I solve this? If anything isn't that clear I will be happy to explain it better.

Any help would be highly appreciated!

Regards,

Andrea

Parents
  • Hi Andrea,

    It is not clear to me whether you need to continuously process your data or only when your threshold is crossed.
    In the latter case, you may be able to use ADCHS comparison feature to trigger DMA transfer ...

    Please, give some more information regarding your needs:
    - continuous processing ?
    - if not, fixed number of samples to process ?
    ...

    Basically, you should never try to interact with DMA transfers in SW (except in order to start/stop transfers).
    I usually try to implement a state machine with DMA and other peripherals so that everything happens in hardware and at the end, software is informed about some work to do by a DMA or peripheral interrupt. Software processing is then less time constrained and you can deal with ISR delay by adjusting buffering size.

    Regards,
    Thibaut
Reply
  • Hi Andrea,

    It is not clear to me whether you need to continuously process your data or only when your threshold is crossed.
    In the latter case, you may be able to use ADCHS comparison feature to trigger DMA transfer ...

    Please, give some more information regarding your needs:
    - continuous processing ?
    - if not, fixed number of samples to process ?
    ...

    Basically, you should never try to interact with DMA transfers in SW (except in order to start/stop transfers).
    I usually try to implement a state machine with DMA and other peripherals so that everything happens in hardware and at the end, software is informed about some work to do by a DMA or peripheral interrupt. Software processing is then less time constrained and you can deal with ISR delay by adjusting buffering size.

    Regards,
    Thibaut
Children