Continuous data transfer between µC[AVR/ARM] and PC running Matlab.

Status
Not open for further replies.

David_

Advanced Member level 2
Joined
Dec 6, 2013
Messages
573
Helped
8
Reputation
16
Reaction score
8
Trophy points
1,308
Location
Sweden
Visit site
Activity points
12,242
Hello.

This thread is kind of the next step in a project based on what is discussed in https://www.edaboard.com/threads/325824/ which is about a USB-RS232 dongle.

Now I have that part taken care of, for now I am talking to a Arduino Due through its on-board ATmega chip which in turn talks to the PC through USB but I might(in time I will) switch to a solution with DTR/DSR, RTS/CTS but that don't impact this subject much(I think).

First of, I'm not looking for a matlab specific solution but rather a general principal for how to do it when dealing with serial communication to PC's.

I am running Matlab on my laptop and use it to fetch ADC data from the Due(SAM3X8E), its the Due's internal 12bit ADC but in the end I will have a external 16bit ADC. But my current software allows me to send a string to the Due from Matlab in order to request certain things.
Like if I send "read|A0|200|" the Due will read the ADC channel A0 and send its result through serial with a blank space after and the have a delay of 10mS 200 times, after which a CR/LF is sent.
I can't request more than 1000 values because Matlab's variables don't allow me to store more than that and I am know trying to set up a continuous communication that analyses and plots the results as the new values comes in.

But I don't know how to do such a thing, does any one have any advice?

I am really stuck and I appreciate any and all inputs, if my current solution is of interest to see I can elaborate.
One other subject that is relevant to this thread is the most efficient way to send values over 255, I am sending 12bit values a 0-4095 but later it will be 0-65536.

Regards, David_
 

I can't request more than 1000 values because Matlab's variables don't allow me to store more than that
Where do you see this limitation? Matlab data objects are effectively only limited by available computer memory.
 

This is wierd, yesterday when I tried to read 1000 ADC readings it went okey, but when I tried to do more than 1000 it said something about not enough space even when the inputbuffer was not full.
Reading you post I increased the inputbuffer 5 fold and tried to read 1500 values and know it works without the error from last night, thanks for pointing that out. I was quite perplexed with a limit like that, I have had to read wrong cous I was sure of the messages meaning, though I have both ADD and dyslexia so I probably did missread.

However, that do solve some problems for me but I would still like to program a continuous transfer.
I suppose FIFO's will be involved, I have never done anything like this so I'm just guessing.

SAM3X8E(the micro in Due) do have DMA and PDC, those can't be used through the arduino IDE. Not any way I know or understand other than through directly accessing the registers but I do need the ASF examples to be able to implement anything like that, but I am trying to get ATMEL Studio to work in order to get access to use those functions, I have a problem with getting AS to upload the file to the board and I will open a thread on some AVR forum.

I have read the datasheet and the DMA transfers sound pretty straight forward, there are 32bit pointers to the register location of the data to be sent and 32bit pointers to the registers to be receiving as well as 16bit counters to control how much or how many bytes to transfer but I do not get how I do determine the actual registers to be transferred between, I'm very new to this chip or any chip really.

But if or more likely when I get to grips with that I should be able to get the Due to read the ADC and send the results to Matlab through UART using PDC/DMA, in that case the next thing would be to tackle sample rate.

I will have to dive down in the datasheet, but to the subject of continuous transfer. I'm thinking that I can us FIFOs to store, send and then store in matlab in arrays to then be analyzed but how to do it for maximum sample rate. This is where I feel strangled by the Arduino IDE but I have to solve the ATMEL studio problem first.

Thanks for pointing out my faulty assumption.
 

One problem I have is how to send a 12bit value, I had never thought that I would have such a hard time with it but I have been punching my keyboard for hours and hours only to end up with crazy numbers.

One way I have used which works is to simply send the value as Serial.print(analogRead(A0));
Serial.print(" ");
in a for loop and right after the loop a Serial.println(); to terminate the line, and then I get one line with values which I then in matlab use:
raw = fscanf(s);
data = srt2num(raw);

and then I end up with a array named data containing the requested number of values. But each value takes 5 bytes to transfer...

I have been trying to take the ADC reading and split that up into two byte sized variables to send in order to then re-assemble them but it will not go as I want it to. I did manage it a couple of days ago but that seams to be something I am missing.

What do you think about which way is best to transfer a 12bit value most efficient?

regards
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…