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 Thibaut, I looked at the doc (here it is for your reference) and this is what I found.

    In chapter 48, section 48.7.4.1 DMA read:


    The FIFO can be read by DMA channel 8. A DMA transfer request is generated when the FIFO fill level is equal to or more than set by FIFO_LEVEL. This is the same behavior that will raise the interrupt flag FIFO_FULL. The burst size can be set to one in the DMA channel control register (see Table 350). If the FIFO fill level is not equal to one of the other DMA-supported burst sizes (applicable DMA burst sizes are 1, 4, 8 or 16), set the burst size to 1. Reading an empty FIFO will result in a value 0x00008000 or 0x80008000.

    And that's it. The problem is that looking back to scetion 4.6.9 threshold A/B register a detection can occur only after conversion, in fact:

    If, for two successive conversion results on a given channel, one result is below a
    threshold and the other is equal-to or above this threshold, then a threshold crossing has
    occurred. In this case the THCMP_CROSS (see Section 48.6.10) status bits will indicate
    that a threshold crossing has occurred. A threshold crossing event will also generate an
    interrupt 1 request if enabled to do so via the SET_EN1 bits associated with each channel
    in the SET_EN1 register.

    So I suspect the ADC must be up and running all the time.
    Plus, there is the option to external-trigger the ADC conversion, but that can be done only through standard GPIO which I believe are digital comparators. The amplitude of my input signal changes over time (that's where the physical information I'm interested in is hidden): I think I would need to design a specific analog amplifier in order to work this way.

    I'd love to know if there's a way to fill the fifo only after a threshold cross, this should work if combined with the DMA read request at a certain fifo level.

    Many thanks for your help Thibaut.

    Regards,
    Andrea

Reply
  • Hi Thibaut, I looked at the doc (here it is for your reference) and this is what I found.

    In chapter 48, section 48.7.4.1 DMA read:


    The FIFO can be read by DMA channel 8. A DMA transfer request is generated when the FIFO fill level is equal to or more than set by FIFO_LEVEL. This is the same behavior that will raise the interrupt flag FIFO_FULL. The burst size can be set to one in the DMA channel control register (see Table 350). If the FIFO fill level is not equal to one of the other DMA-supported burst sizes (applicable DMA burst sizes are 1, 4, 8 or 16), set the burst size to 1. Reading an empty FIFO will result in a value 0x00008000 or 0x80008000.

    And that's it. The problem is that looking back to scetion 4.6.9 threshold A/B register a detection can occur only after conversion, in fact:

    If, for two successive conversion results on a given channel, one result is below a
    threshold and the other is equal-to or above this threshold, then a threshold crossing has
    occurred. In this case the THCMP_CROSS (see Section 48.6.10) status bits will indicate
    that a threshold crossing has occurred. A threshold crossing event will also generate an
    interrupt 1 request if enabled to do so via the SET_EN1 bits associated with each channel
    in the SET_EN1 register.

    So I suspect the ADC must be up and running all the time.
    Plus, there is the option to external-trigger the ADC conversion, but that can be done only through standard GPIO which I believe are digital comparators. The amplitude of my input signal changes over time (that's where the physical information I'm interested in is hidden): I think I would need to design a specific analog amplifier in order to work this way.

    I'd love to know if there's a way to fill the fifo only after a threshold cross, this should work if combined with the DMA read request at a certain fifo level.

    Many thanks for your help Thibaut.

    Regards,
    Andrea

Children