From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
11-05-2017 06:56 AM
Hello
I'm using arduino mega and i need to create some control system in Labview in real time.
I'm using a control and simulation loop and VISA to get a signal from arduino. My code in arduino:
volatile unsigned int counter = 0; void setup() { Serial.begin (9600); pinMode(2, INPUT); pinMode(3, INPUT); digitalWrite(2, HIGH); digitalWrite(3, HIGH); attachInterrupt(0, ai0, RISING); attachInterrupt(1, ai1, RISING); } void loop() { // Send the value of counter Serial.println (counter); delay(10); } void ai0() { // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH // Check pin 3 to determine the direction if(digitalRead(3)==LOW) { counter++; }else{ counter--; } } void ai1() { // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH // Check with pin 2 to determine the direction if(digitalRead(2)==LOW) { counter--; }else{ counter++; } }
Then i made a sketch. But i can't understand how to get visa read signal and control simulation synchronously. I'm trying to vary delay() in arduino code but the precision is not good. Maybe someone have ideas about this?
Solved! Go to Solution.
11-05-2017 10:54 AM
How can I read VISA signal with program sinusoidal signal in one loop to use them together later??
if I try to read them together, then the SINE signal is displayed in real time, but the VISA signal gives me something wrong with big delays.
But separately in 2 loops all ok.
11-05-2017 11:21 AM
This is just a rough approximation, but still a very good one: With a baud-rate of 9600 the sending of 1 byte already takes about 1 ms, and that's without the additional delays from drivers on the PC AND your Arduino board. And you probably want to read more than 1 byte.
Regards, Jens
11-05-2017 12:01 PM - edited 11-05-2017 12:05 PM
OK. When I press 'Simulate acquision timing' in my Simulate sine when it displayes the sine in real time but the data from VISA does not change at all. But if i press 'Run as fast as possible' the data from VISA ok, but the sinus time is very fast. What i need to do?
11-06-2017 02:49 AM
may be you have to use LIFA Encoder, with the attached file. Try it ..
upload "LIFA_Base.on" to you arduino. then you can get the readings using the attached vi.
11-06-2017 07:08 AM - edited 11-06-2017 07:09 AM
Yes,it'sworking in one loop now. Thank you.
But in order to do this it was necessary not to use 2 and3 arduino pin and change version of arduino ide to 1.022
07-03-2018 05:11 PM
please see my topic and help me