Data capture rates and Simulink for digital control

Hello I cannot get a straight answer on this and it seems simple. I am a very basic Arduino programmer. However I am a very strong user of Matlab and Simulink and I teach a class in Digital Control Systems. I what to use an Arduino Mega to demonstrate priniciples of Sample-Time control.

That being said I want to use autocode Simulink to do the job. I have got the arduino mega to accept the code and over External (option) I can get a consistant (set by me) sample rate of up to 25Hz. Is that the fastest I can expect? The reason for this is I need to log the data. If I use External Mode I can send it to Matlab workspace and view the data. however 25Hz is really slow with a very basic piece of code. AI in and a scope.

1.) is 25 Hz what is expected using External Mode?
2.) What are my other options to get closer to 100Hz or even 1kHz? Would I have to add an SD card and code that to record the data?
3.) I imagine it is feasible to go faster say 500Hz but NOT in External Model so I cannot see the data live or record it, but if I devise a control scheme (say PID) in autocode it I could see the system run under control but I could not send commands or read anything live. It would just go. that isn't a terrible option if it is just as easy as coding the controller with a AI and a PWM not in External mode and set the sampling time to 0.002 seconds in simulink.

Above all I need a consistant sample time. I would like to log the data and I would like to send setpoints to the arduino from Simulink.

Thanks
Jason

I don't know Matlab of Simulink. You can certainly get the Arduino to sample digital (or analog) inputs much faster than 1kHz.

The bottleneck for high speeds may be the rate at which data can be transferred to the PC. At 115200 baud the max will be about 11,000 bytes per second. The Arduino can use higher baud rates - up to 1,000,000 baud which would in theory allow close to 100,000 bytes per second.

...R

@jrkreme:These are excellent questions and discussion points. If you can live without real-time display of your data, then you can save the samples to local memory: SD card if it can keep up with the sample rate, otherwise RAM.

Please post any lessons / learned and corrective action details.

Hello!

I recently ran into a similar situation. I was working on a Matalb Simulink model used for speed regulation of a DC motor using a Discrete PID controller given the desired RPM. The problem was that I wasn't able to get the arduino's sample rate higher than 25 Hz, which was far too low for reading the RPM of the DC motor.

I solved the problem by coding with the Arduino Software, using the analogRead() function, then sending the acquired data via serial communication to the PC. That way I was able to get much faster sample rate (I used 1000Hz which was enough for my needs, but I think it could theoretically go even faster).
On the Simulink side, I used the "Serial Receive" block from "Instrument Control Toolbox" and it worked like a charm.

The problem was in the Arduino package for Matlab and not in Arduino itself.

Hope that helps you.