Hi all?
Firstly, I really hope that all of you guys are safe and healthy due to this emergency that we are facing up.
I'm writing about a problem with the Interfacing Arduino with MATLAB. For some reasons I need to reach really high sampling rate in MATLAB, in particular, because I'm going to record some EMG data through 2 Arduino analogue channels, and EMG signal needs to sampled at 10KHz for good quality, which means 10000 samples/sec.
Currently, I'm using Arduino Nano or M0. For the last one, I've uploaded some code that needs to get Data from IMUs (inertial measurements unit) and send data to MATLAB and there I'm able to reach 100 Hz that is good enough for motion extraction.
The idea is to send a trigger from the M0 (using as a Master) to the Nano one (as Slave) in order to start the EMG recording when the user asks for that.
For this, I have no still clear idea of how to reach this problem, but for now is not the main topic. Of course, if you have any suggestions, please let me know.
Now the problem is that I set up TCCR1A and TCCR1B registers in Arduino nano in order to overflow the interrupt over 10KHz, and I even modified ADC's Prescaler in order to have the availability to transduce analog data when needed. Here the code, please if you have any suggestions to improve let me know:
const unsigned char PS_2 = (1 << ADPS0) ;
const unsigned char PS_4 = (1 << ADPS1) ;
const unsigned char PS_8 = (1 << ADPS1) | (1 << ADPS0) ;
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
void setup()
{
TCCR1B = 0;
TCCR1A = 0;
TCCR1B |= (1<<CS10); // prescaler 1
TIMSK1 |= (1<<TOIE1); // enable timer overflow
TCNT1 = 63936; // (65536-(f_clock/(prescaler*f_target))
ADCSRA &= ~PS_128;
ADCSRA |= PS_4;
Serial.begin(115200);
pinMode(A0, INPUT);
}
ISR(TIMER1_OVF_vect) {
Serial.println(analogRead(A0));
Serial.println(analogRead(A1));
TCNT1 = 63936;
}
Then, the problem is in Serial.println() function, I guess. This is the part that should take a lot and decrease the speed of my communication.
To sort out that do you have guys any suggestions? Is there any possibility to communicate directly with MATLAB and increase the velocity? I'd like to try Serial.write(), but I think doesn't change a lot more.
I'm happy to hear another possibility to save data (avoiding MATLAB it's fine) provided to have synchronized Data between EMG and IMUs.
Please if something else to understand the situation is needed, feel free to let know.
Your help would be really appreciated.
Thanks a lot.