AnsweredAssumed Answered

LPC4370: ADCHS, GPDMA and CMSIS DSP

Question asked by Andrea Bettati on Aug 11, 2016
Latest reply on Aug 11, 2016 by Andrea Bettati

Hi to you all,
it's my first experience in using a complex MC, I'm doing it for my thesis and I'm really enjoying it, but I might be doing some obvious mistakes.
First of all I'd like to thank all the people that worked on the LPC4370 and posted useful hints here on the forum, I think I read almost all the posts and followed them while setting up the system.
This is my actual configuration:

  • Hardware/Software: I'm using 2 lpclink2, one as a debuggr and oe as an eval board and programming it from LPCXpresso v8.1.0 on Ubuntu 14.04.
  • ADCHS up and running in background with CLK_ADCHS @80Mhz (real sample rate is 40Mhz, can't figure out why, but that's not the matter right now), thanks Benjamin Artes for this post: How to achieve 80MHz using DMA from LPC4370's HSADC?
  • GPDMA running in background and transferring samples from the ADCHS FIFO to a buffer in memory.
    • I'm using 2 LLI, and therefore 2 Buffers. To set this up I followed mch0 posts (many thanks for this 2 posts!):
    • The GPDMA is set to raise the TC bit at the end of each LLI.

Here is my problem: I need to process the data in the buffer that is not being filled by the DMA and I'm trying to do this while serving the IRQ.

For my maths I need some of the CMSIS DSP function and since I'm not a Qformat expert i decided to use the float version of them: in order to achieve this I wrote a simple conversion function which takes the twos complement uint32_t from the 12bits ADCHS and converts them into float32_t.

This is my code:

 

void Twos2Dec_Remapp(uint32_t *twosBuff, float32_t* decBuff, uint32_t buffLenght)
{
    for(int i = 0; i < buffLenght; i++)
    {
        twosBuff[i] &= 0xFFF;
        /*Checks for 1 in 12th pos: negative number from ADCHS*/
        if(twosBuff[i] & (0x01 << 11))
        {
            decBuff[i] = (-1)*(float32_t)((((uint32_t)((~twosBuff[i]) & 0xFFF))+1));
        }
        else decBuff[i] = (float32_t)(twosBuff[i] & 0xFFF);

        if(decBuff[i]>2047 || decBuff[i]<-2048)
        {
            /*!!VALUE OUT OF RANGE!!*/
            Board_LED_Set(0,true);
        }

    }

 

Unfortunately sometimes the value does go out of range.
I'm trying to debug this thing right now printing some values using the UART and I saw that the out of range conversion occurs in random positions across the whole buffer.
My guess is that my conversion is to slow and that the DMA often overwrites my buffer while I'm processing it, but a piece of advise from an expert eye would be highly appreciated.

 

I hope I described what's going on here, but if it wasn't so please let me know: I can also post the whole firmware if it helps.

 

Thanks in advance,
Andrea

Outcomes