4200L Best way to scan mutiple Channel with ADC_SAR

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello,

   

witch is the best way to scan multiple Channel with PSoC4 4200L with Multiplexer and ADC_SAR (see picture)? With DMA?

   

I need a continius anf fast Scan of all 14 Channels.

   

Any Code Samples available? 

   

Regards,

   

Michael

0 Likes
18 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Use DMA and the SARMUX ADC. When you right-click on a component, you can select example projects. There are also example projects available when you create a new project. And there are quite a number of application notes when you search the Cypress website ('AN DMA ADC').

0 Likes
Anonymous
Not applicable

Yes I already looked at sample codes on PSoC Creator, but nothing found with multiple ADC Channels and DMA.

0 Likes
Anonymous
Not applicable

I want a ASAP continuous scan into single memory buffer.

   

But I also have to calculate average values from each Channel.

   

Or rather, how is the best and fastest way to get average values from each of the 14 Channels?

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

The sequencing ADC is able to average the measurements. And: The result is stored into a result array. Read the datasheet thoroughly, it is mentioned there.

   

 

   

Bob

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

I changed the ADC to average measurements. but now I get Error: Unable to find a solution for the analog routing.

   

I have already a ready PCB for this Project...

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Rough estimation: try as appended.

   

At the sdone switch the MUX, when last channel is transmitted via DMA re-enable DMA.

   

 

   

Bob

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

I made you said, but I get always '0' as result of all 14 Channels. So something is worng...

   

SDONE and DMA IRQ are running.

   

Is this right? 

   

DMA_ADC_Start((void *)ADC_SAR_CHAN0_RESULT_PTR, (void *)&ADC_Buffer);

   

ADC is running in single channel mode, AMuxSeq seems to be switching and DMA collect 14 uint16 to ADC_Buffer[1-14]

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

You need to increase the "Heap size" (System view) to at least 0x0100 when using formatted printing!

   

Your project tends to get complicated, I would suggest to isolate the ADC-part into a separate project until it works, then re-integrate the code into your current project.

   

 

   

Bob

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

I reduced the Project to a minimum, but still get 0 as result.

   

DMA_ADC_Start((void *)ADC_SAR_CHAN0_RESULT_PTR, (void *)&ADC_Buffer);

   

Is "ADC_SAR_CHAN0_RESULT_PTR" right if I use only one ADC Channel?

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

See attached project. You need to set the transfer size of DMA to 32 bits -> 16 bits.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thank you for your help, but still not running correctly.

   

Now I get Data like this:

   

CY8CKIT-043 PSoC4-M/n/rBuffer: 0 , Data: 17521
Buffer: 1 , Data: 15981
Buffer: 2 , Data: 14157
Buffer: 3 , Data: 18007
Buffer: 4 , Data: 16156
Buffer: 5 , Data: 15624
Buffer: 6 , Data: 16310
Buffer: 7 , Data: 14206
Buffer: 8 , Data: 18214
Buffer: 9 , Data: 16411
Buffer: 10 , Data: 14038
Buffer: 11 , Data: 17985
Buffer: 12 , Data: 15869
Buffer: 13 , Data: 16015
Buffer: 0 , Data: 14119
Buffer: 1 , Data: 18150
Buffer: 2 , Data: 15870
Buffer: 3 , Data: 14438
Buffer: 4 , Data: 18121
Buffer: 5 , Data: 15961
Buffer: 6 , Data: 15557
Buffer: 7 , Data: 16260
Buffer: 8 , Data: 14071
Buffer: 9 , Data: 17834
Buffer: 10 , Data: 15897
Buffer: 11 , Data: 14843
Buffer: 12 , Data: 16744
Buffer: 13 , Data: 14654
Buffer: 0 , Data: 15909
Buffer: 1 , Data: 14260
Buffer: 2 , Data: 17770
Buffer: 3 , Data: 15995
Buffer: 4 , Data: 15928
Buffer: 5 , Data: 15842
Buffer: 6 , Data: 14103
Buffer: 7 , Data: 18311
Buffer: 8 , Data: 16293
Buffer: 9 , Data: 14493
Buffer: 10 , Data: 17594
Buffer: 11 , Data: 15450
Buffer: 12 , Data: 16397
Buffer: 13 , Data: 15920
Buffer: 0 , Data: 16877

   

But  4095 is the highest value at 12 Bit

   

And I see you disables the DMA IRQ, only for testing or does not work? 

   

Better the DMA generates always IRQ when done, to get the newest data anytime.

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

The "Averaging Mode" of the ADC is set to "Accumulate" and not to "Fixed Resolution".

   

"I see you disabled the DMA IRQ, only for testing or does not work? " Because it is not needed at all and only consumes MIPS.

   

"Better the DMA generates always IRQ when done, to get the newest data anytime." There is not too much time left to spend in interrupt handlers. The project already generates an interrupt for every sample to switch the Mux, a second interrupt with the same high frequency could consume too much CPU time. On the other hand: Why are you using DMA when you want to do it using interrupts???

   

 

   

Bob

0 Likes
Anonymous
Not applicable

OK the I must all div by 16 (16 Samples averaged). But the Results are still wrong.

   

At the MUX0-12 is a Voltage about 1.65V +- 1mV and I testet MUX13-14 to GND (0V) but the output of all the 14 ADC always in range of  13600 to 19000 / 16 is 850 to 1187 that's are 0,68 to 0,96 mV. Far away from 1.65 or 0V???

   

Yes I see in your sample is the pinout differend but a few pins are correct with mine... 

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

Please show actual test project.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

??? I worked with your Sample Project, the problems come form there.

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

My project is configured for 5V, I am using a CY8CKit-044 and did not care for the pinouts.

   

You do not need to divide result values by 16, use "Fixed Resolution" for ADC.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Yes I changed it to 3.3V and Pinout. A 0V Input must generate about 0 not bigger the 14000 something is wrong. I think the multiplexer switches not correctly...

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

Change line to

   

        while(!(CyDmaGetStatus() == CYDMA_IDLE)) Wait(); // Not & but ==

   

You might need to insert a DMA_ADC_ChEnable(void) after validating the descriptor.

   

For a general test: Set the mux to a fixed channel and read out this channel only. Provide the pin with a defined voltage and compare the results.

   

 

   

Bob

0 Likes