06-10-2022 04:30 PM
Hi,
I'm tiring to read an Accelerometer sensor sent by Arduino UNO via VISA connection (115200 baud rate) and then control the Amplitude of vibration to get specific g force.
but the problem is this: after a while of iterations, the data which receive to PID controller got delay for some seconds and therefore PID control can not react in proper time because it is belong to too past.
I use two separate while loop, one for producing waveform and sent it to vibrator and another for reading sensor and calculating PID output which is used in first while loop for controlling of amplitude of waveform.
I need just REAL-TIME data read by sensor to process the PID calculations. what should I consider about that.
my vi is very large so I can't attach it here.
VISA byte return count number is around 18 and I set byte count to 20. I tried to use flash buffer and VISA clear to handle it but didn't help.
any suggestion is appreciated.
Solved! Go to Solution.
06-10-2022 05:11 PM
How quickly is the Arduino sending the data (how often are the data messages being sent)? You may need to use a Producer/Consumer where you have one loop do nothing but read from the port and have that data passed on to another loop for processing.
06-11-2022 03:15 AM
thanks for answer,
I'm using ADXL345 sensor with 3 axis accelerometer which set to 800Hz sample rate, but considering the time for reading data and reporting that, I set a 1 micro second delay in Arduino program. Also the baud rate of serial communication via USB is 115200.
I think the amount of data rate received via USB is more than the amount of CPU capability for handling it because of very large vi code.
so because I need most recent data to control by PID, and ignore most past data. I don't know how can I reduce as possible as memory/CPU consumption and how can get rid of FIFO data queue in VISA line.
I will look closely at your mentioned Producer/Consumer method by the way, but if this information remind you something else, it will be welcome. thanks.
06-11-2022 07:38 AM
Well, let's do a little math...
(18 bytes/message)*(10 bits/byte)/(115200 bits/second) = 1.5625ms/message
NOTE: The 10 bits/byte is because you have to include the start and stop bits
1/(800 Samples/second) = 1.25 ms/sample
So your messages are taking longer than your samples.
There is no way a normal loop could keep up with that unless all it does is read from the port. Even then, if Windows is involved there will be "hiccups" causing you to fall behind. This also means that your processing has to consistently be faster than 1.25ms. For simple PIDs, this is probably very doable. A Producer/Consumer may solve the problem.
Is there a reason you couldn't move the PID calculations, etc. into the Arduino? Removing the serial communications would definitely help your propagation issue and getting Windows out of the way would help the jitter issue.