cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve the data converted by ADC using DMA on simulink ?

Abdelhak GOUDJIL
Associate II
Posted on March 18, 2018 at 18:06

Hello,

I want to use the ADC and the DMA on Simulink

as follows

:

The ADC is triggered by

the rising edge

of Timer 2 which generates a PWM signal with a frequency of 100

kHz

.

So, I want to retrieve the 132 first data converted by ADC at every 1 second.

Any idea how to use DMA (or buffer) on

Simulink

and how to retrieve the 132 first data converted by ADC at every 1 second.

Thank you

very much.

Note: this post was migrated and contained many threaded conversations, some content may be missing.
9 REPLIES 9
Andrew Neil
Evangelist III
Posted on March 18, 2018 at 20:06

Any idea how to use DMA (or buffer) on

Simulink

Is that not covered in the Simulink Documentation?

https://uk.mathworks.com/help/simulink/index.html

 
Posted on March 19, 2018 at 16:33

Thank you Andrew for your response,

But I want to

know

how to

configure ADC and DMA on CubeMX and how to read DMA data under Simulink?

Thanks in advance

Posted on March 19, 2018 at 18:34

So that's two separate questions - isn't it:

  1. how to

    configure ADC and DMA on CubeMX
  2. how to read DMA data under Simulink?

Is the fact that it came via DMA even relevant to Simulink?

Posted on March 19, 2018 at 19:09

Yes, exactly, two separate questions.

Regarding the fact that the data comes from DMA,

w

hat I want is to recover the data stored on DMA and do a processing on this data every second .

Until now: I configure the ADC and DMA as shown by the attached pictures.

Unfortunately I do not have an idea how to recover the data stored on DMA to simulink every second.

Thanks in advance for your response

________________

Attachments :

Capture.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxoG&d=%2Fa%2F0X0000000b1i%2Flup.X6_yCVZ6xxeivX.T.yelQ2RbkfVa.lubqUpTpn4&asPdf=false

Capture1.PNG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxsb&d=%2Fa%2F0X0000000b1h%2Fe90pZEholcLmVhb339AgSYju1n5Lh7ZmHWCAzXxJODw&asPdf=false
Posted on March 19, 2018 at 19:41

The DMA just puts the data into memory. Once it's there, the fact that it arrived by DMA is entirely irrelevant - it is just data in memory.

You are going to have to study the Simulink documentation to learn how it can access data in memory.

https://uk.mathworks.com/products/simulink/getting-started.html

  
Posted on March 20, 2018 at 07:50

Unfortunately I do not have an idea how to

...

Studying the documentation - in this case the Reference Manual - will never hurt.

The DMA just puts the data into memory. Once it's there, the fact that it arrived by DMA is entirely irrelevant - it is just data in memory.

I would not entirely agree.

The 'problem' with DMA is, as soon as the first ADC value of the next set is ready, DMA begins to overwrite your buffer in the background (assuming circular DMA).

It is usually a good idea to hook onto the TC (transmission complete) interrupt, and immediately move the results for processing.

...recover the data stored on DMA to simulink every second.

And watch out for bandwidth.

Assuming 'to simulink' means a PC running Mathlab/Simulink, your uplink must accomodate for the amount of data your ADC produces.

For a 100kHz sample rate, UART seems already out of question.

Posted on March 20, 2018 at 09:31

AvaTar wrote:

The 'problem' with DMA is, as soon as the first ADC value of the next set is ready, DMA begins to overwrite your buffer in the background (assuming circular DMA).

True.

But the main point is that this has nothing specifically to do with Simulink - exactly the same would apply to anything trying to 'consume' that data.

It is usually a good idea to hook onto the TC (transmission complete) interrupt, and immediately move the results for processing.

Indeed.

Then, again, as far as Simulink is concerned, it is simply a matter of accessing data in memory - the fact that it arrived via DMA is still irrelevant.

Another option is to 'double-buffer' the DMA - so that the DMA fills one buffer while the application is processing the other.

The basic problem here seems to be that the OP is using a tool (s)he doesn't understand, and without sufficient understanding of how the microcontroller works.

It is seldom a good idea to try to climb two mountains at once!

At this stage, it seems that Simulink is confusing the issue.

abdelhak.goudjil90

‌: I think you need to set Simulink aside for a while, and spend some time getting to grips with how the microcontroller works, and how to program it.

For some microcontroller getting-started tips, see:

https://community.st.com/thread/46923-stm32l162#comment-182758

Posted on March 20, 2018 at 09:34

Thank you

meyer.frank

and

Neil.Andrew

.

'AvaTar: It is usually a good idea to hook onto the TC (transmission complete) interrupt, and immediately move the results for processing.' --

Yes I agree with you.

Neil.Andrew

. Regarding access data in memory, I will study the Simulink

documentation. Thank you again.

Posted on March 20, 2018 at 10:23

The basic problem here seems to be that the OP is using a tool (s)he doesn't understand, and without sufficient understanding of how the microcontroller works.

It is seldom a good idea to try to climb two mountains at once!

Exactly !

I view this as a negative side effect of Cube - seductive laziness ...