ADC_SAR DMA UART

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,

   

 

   

I’m trying to transfer data from ADC-SAR to UART using the DMA. For this I followed the Configuration showed in AN52705, but I’ve got this error:

   

 .\main.c: In function 'DMA_Config':

   

.\main.c:83:36: error: 'ADC_SAR_1_WRK0_PTR' undeclared (first use in this function)

   

Could anyone help me?

   

Best regards

   

Hosam

   

 

   
   

Main + DMA configuration:
 

   

 

   

#include <project.h>

   

 

   

/* DMA Configuration constants for DMA_1 */

   

#define DMA_1_BYTES_PER_BURST (1u)

   

#define DMA_1_REQUEST_PER_BURST (1u)

   

#define DMA_1_SRC_BASE (CYDEV_PERIPH_BASE)

   

#define DMA_1_DST_BASE (CYDEV_PERIPH_BASE)

   

 

   

void DMA_Config(void);

   

 

   

 

   

int main()

   

{

   

    ADC_SAR_1_Start();

   

   

   

    DMA_Config();

   

 

   

    ADC_SAR_1_StartConvert();

   

   

   

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

   

 

   

    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */

   

    for(;;)

   

    {

   

        /* Place your application code here. */

   

    }

   

}

   

 

   

 

   

 

   

 

   

void DMA_Config()

   

{

   

    /* Variable declarations for DMA_1 */

   

    uint8 DMA_1_Chan;

   

    uint8 DMA_1_TD[1] = {0};

   

 

   

    /* Iniitialize DMA channel */

   

    DMA_1_Chan = DMA_1_DmaInitialize(DMA_1_BYTES_PER_BURST, DMA_1_REQUEST_PER_BURST,

   

                                     HI16(DMA_1_SRC_BASE), HI16(DMA_1_DST_BASE));

   

 

   

    /* Allocate TD */

   

    DMA_1_TD[0] = CyDmaTdAllocate();

   

 

   

    /* TD configuration setting */

   

    CyDmaTdSetConfiguration(DMA_1_TD[0], 1u, DMA_INVALID_TD, DMA_1__TD_TERMOUT_EN);

   

 

   

    /* Set Source and Destination address */

   

    CyDmaTdSetAddress(DMA_1_TD[0], LO16((uint16)ADC_SAR_1_WRK0_PTR), LO16((uint16)UART_TXDATA_REG));

   

 

   

    /* TD initialization */

   

    CyDmaChSetInitialTd(DMA_1_Chan, DMA_1_TD[0]);

   

 

   

    /* Enable the DMA channel */

   

    CyDmaChEnable(DMA_1_Chan, 1u);

   

}

0 Likes
28 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

It is always advisable to post the complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file (do NOT use chrome, that still may not work).

   

Probably you have made a typo regarding your Component's name.

   

 

   

Bob
 

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Maybe datasheet is in error becuse in its table definition vs example furthere on in

   

datasheet there is this typing -

   

 

   

result = CY_GET_REG16( ADC_SAR_1_SAR_WRK0_PTR  );

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Here is the Project

0 Likes
Anonymous
Not applicable

thank you Dana for your hint, its working know 🙂
i just posted the Project before I read your reply

   

thank you Bob too

   

Hosam

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

     Hi,

   

               

   

here I’m again,

   

after successful compiling I implemented the Project on CY8KIT-001(PSoC 5LP), unfortunately I couldn’t get any data throw the UART-port when using the DMA.

   

I just tested the communication throw UART by sending the ADC-data without DMA und it works.

   

Could someone take a look at it, that would be nice?

   

Best regards

   

Hosam

0 Likes
Anonymous
Not applicable

     I tried to use the DMA wizard as described here (Page 32)but the UART didn’t appear in the “Destination” field. Maybe I have to activate the UART to be reached by DMA ??

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

In CyDmaTdSetConfiguration() you specified DMA_INVALID_TD as the next TD, I think you should use the TD[0] to transfer multiple bytes and not only one. Additionally i would set SAR-bits to 8.

   

You will get a maximum of about 10000 bytes/second over the UART line, but the SAR delivers more samples, you must find a solution for that problem.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

     Thanks Bob, I’ll try it on Monday and give a feedback

   

               

   

Actually, for further processing on a PC I want to transfer the data with up to 400KSps. But I think it’ll not work as I wish. So i’ll try to implement the data processing on chip, eg. FFT or maybe use another interface.

   

I’m a beginner in PSOC and this project becomes complicated but still interesting  🙂

   

Hosam

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You m ight want to file a CASE to solve this using full res of

   

SAR. Looking at forum no one seems to have done this yet.

   

And post back the solution for others.

   

 

   

    

   

          

   

To create a technical case at Cypress -

   

 

   

www.cypress.com

   

“Support”

   

“Technical Support”

   

“Create a Case”

   

 

   

You have to be registered on Cypress web site first.

   

 

   

Regards, Dana.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

     Hi,

   

               

   

It still doesn’t work…

   

I could read the nrq-Signal of the DMA with a oscilloscope out, it is pulses with the frequency of 857143Hz which is the Sample rate of the ADC, that means, the samples are written in the memory (register of UART) but not transferred out.

   

I found this on PsocDevelopper,  it seems to be a similar problem like mine but somehow I couldn’t open the zip-file. Besides is it you Bob and Dana in this conversation?

   

Regards

   

Hosam

   

Ps. I filed a case about “Transmit High-Rate ADC_Samples through UART” and soon I’ll post the/a solution

0 Likes
Anonymous
Not applicable

*                    I found this on PsocDevelopper....

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Maybe I should reread thread, but looking at latest posted

   

project -

   

 

   

1) Your ADC is set for 1M SPS, 8 bits, so thats 8 Mbyte/sec or

   

8 Mbits/sec, + some overhead for EOC and read and DMA.

   

 

   

2) Your UART is set to 115K bits/sec, or ~ 14 Kbytes/sec.

   

 

   

In short you are producing far more data that the UART can handle.

   

 

   

Try reversing the rates, eg slow SAR down to its min of 74 K SPS or use

   

a trigger for conversion, to get rate down << UART, and thens ee if data

   

stream starts making sense. Or average enough samples to get rate <<

   

UART.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Correct this -

   

 

   

1) Your ADC is set for 1M SPS, 8 bits, so thats 8 Mbyte/sec or

   

8 Mbits/sec, + some overhead for EOC and read and DMA.

   

 

   

to this -

   

 

   

1) Your ADC is set for 1M SPS, 8 bits, so thats 1 Mbyte/sec or

   

8 Mbits/sec, + some overhead for EOC and read and DMA.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Hosam,

   

You have different choices based on your environment or your needs:

   

You may sample data with a high rate for a short time, buffer the data and then transmit the chunk over the UART.

   

You may setup a timer at 400kHz, set your SAR for single conversion and trigger each conversion. At eoc get and transmit the result. This method can come near the availlable MIPs of the core, so using DMA will free some of the needed instructions.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

     Hi Bob,

   

               

   

That’s exactly what I did today. Fist suggestion

   

-          Sampling with “Actual conv, rate (SPS) = 666667”, so I’m expecting 666667 sample/s

   

-          Use the  ADC_SAR_IRQ  the buffer 40 samples und then stop the interrupt

   

-          Transfer them via URAT

   

The signal on Pin_2  is pulses with the frequency 666667 Hz, so far so good, cause I’m sampling with 666667 sample/s

   

so now, how could I check, that every sample has been transferred without losing any of them, in other words, dose the interrupt routine as fast as the sample rate?

   

I did this:

   

(666667 sample/s)/ 40 samples = 16666,675 1/s

   

If I had an input signal with frequency of 16666,675 Hz, the 40 samples should represent one period, but instead I get two periods  ->  the interrupt routine is as half fast as the sample rate

   

Why???

   

How could I buffer high sample rate data in a variable?

   

Hosam

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Since you are using the CPU to transfer the data from ADC to RAM you should increase the CPU clock. First try should be 48MHz and an adaption of the ADC sps to 666666.

   

 

   

To get more headroom, I would suggest you to have a look (and get acquainted to) DMA. There is an ADC / DMA example.

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I cannot find your interrupt routine for your ADC. A good practice is to use

   

CY_ISR_PROTO(), CY_ISR(), an isr component connected to eoc and  isr_StartEx().

   

The first two are documented in "System Reference Gude" to be found from Creator's Help-menu.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

It is in ADC_SAR_IRQ.c, see also attached pic

How could i increase the CPU clock?

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

In workspace explorer, there is a file close to top, suffix *.cydwr, double

   

click that and then pick clocks tab, then edit clock.

   

 

   

Regards, Dana.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

In the intrerrupt routine, have a ptr to an array[ 40 ], inc the ptr, store the sample.

   

Then test if ptr == 39, if so make it 0 to point at beginning of array for the next

   

buffer fill. Also if it is 39, UART the data out.

   

 

   

Declare the array and ptr as volatile.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Open the .cdwr file and click on the "Clocks" tab, then double-click on any system clock.

   

BTW: you should update your Creator to latest version, use the update manager

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks, I’ll give an update tomorrow

   

Hosam

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello,

   

sorry for the delay.

   

Hier ist my latest project regarding sampling und buffering with high sample rate.

   

It samples und buffers the values with ca. 600 ksps then calculate the 128-points-DFT und send the result via UART to the PC.

   

I thoght it could be helpful for other members

   

Best regards

   

Hosam

0 Likes
Anonymous
Not applicable

Hello Hosam,

   

As I am unable to open the "TopDesign" because of 2.2 version so can you upload the snapshot of the TopDesign and configuration setting of ADC and UART?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@Nisargshah

   

What do you think about upgrading your Cypress Creator to version 3.0? There are new devices, new components and some errors corrected.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

@Bob Marlowe,

   

 

   

This is not possible at this moment.. Later on it may possible.. but currently I have to use this..

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Creator 2.2 and Creator 3.0 are co-existent. You may download and install 3.0, open the project and copy the settings and code with cut&paste to your 2.2 project.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

But this is not possible.. If some can take the snapshot of this then it will be ok for me.

0 Likes