LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino Current and Voltage Monitering and labview

Hi all

 

This is the second time i am using labvew and the arduino i have limited experience with labview programming and i am trying to understand how to achieve the same results from the below arduino code. basically i have a CT conneted to the arduino and it uses this code 

const int currentPin = 3;
const unsigned long sampleTime = 100000UL;// sample over 100ms, it is an exact number of cycles for both 50Hz and 60Hz mains
const unsigned long numSamples = 250UL; 
const unsigned long sampleInterval = sampleTime/numSamples; // the sampling interval, must be longer than then ADC conversion time
const int adc_zero = 510;void setup()
{
  Serial.begin(9600);
}

void loop()
{
  unsigned long currentAcc = 0;
  unsigned int count = 0;
  unsigned long prevMicros = micros() - sampleInterval ;
  while (count < numSamples)
  {
    if (micros() - prevMicros >= sampleInterval)
    {
      int adc_raw = analogRead(currentPin) - adc_zero;
      currentAcc += (unsigned long)(adc_raw * adc_raw);
      ++count;
      prevMicros += sampleInterval;
    }
  }
  
  float rms = sqrt((float)currentAcc/(float)numSamples) * (75.7576 / 1024.0);
  Serial.println(rms);
}

 

I would like to read AC Voltage and current of a motor and also control a contractor from labview .Currently i have interfacing  circuit that gives me an AC wave form with a refrence of 2.5V the curcuit looks like this below

Image

The output of this circuit will have a bias of 2.5V of which it will oscillate around and remain positive .Both my current and voltage circuits has the same type of analog output signal . There are arduino libraries already created to do these functions . I am just trying to do the same thing in labview . below is a link to the libraries .

[url]http://openenergymonitor.org/emon/buildingblocks/arduino-sketch-voltage-and-current/url]

i have been trying to get this to work but i am not having much luck .i used the analog read example and modified it a bit , i see the loop frequency is 130Hz . i am trying to read a a sin wave that has a ref of 2.5 the idea is to square the sample values then find the average of at least at least 120 samples then sqrt that value and scale it to match my current range . so far this works but the accuracy of the measurements are off a bit . There are also other stuff to consider such as phase shift in sampling and calibration .

 

i would have to read at least 9 analog inputs at once. I am not to sure i can achieve this.

I am also considering program the arduino since there are libraries already created to take the readings .I will then have labview display them by serial data sent from the arduino . i would also like to control a contractor via labview via serial communication also .

I have to sample at least twice the frequency of the mains and would also have to sample multiple analog inputs at the same time also

 

Can anyone give me some advise about if this is even possible ??

 

Attached is the vi i have created so far 

 

 

 

Thank you

gary

 

GR
0 Kudos
Message 1 of 9
(5,767 Views)

 

No one here is going to translate that C code to LabVIEW for you, you will need to take the LabVIEW tutorials.

http://www.ni.com/academic/students/learn-labview/ 

I don't know what makes you think that you can just do something like your current project without actually learning a programming language.

 

0 Kudos
Message 2 of 9
(5,715 Views)

@nyc_(is_out_of_here) wrote:

 

No one here is going to translate that C code to LabVIEW for you, you will need to take the LabVIEW tutorials.

http://www.ni.com/academic/students/learn-labview/ 

I don't know what makes you think that you can just do something like your current project without actually learning a programming language.

 


Good day 

I am not looking for any one to translate c code to labview for me . i am in the learning process and i am doing the tutorials . What i would like to know is  

 

1. am i able to samples faster than 120Hz

2. would reading multiple inputs slow down the sampling rate

3. If i am not satisfied with sample rates of labview (slower due to serial) could i just program the the arduino and send serial date to labview to show reading and also send back date from labview to control stuff . would doing this make a difference ?

 

As i said my labview programming is skills are basic i am doing tutorials and trying to improve and understand  .i would just like to know if i am going in the right direction.

 

Thank You

 

 

GR
0 Kudos
Message 3 of 9
(5,700 Views)

@gready123456 wrote:

@nyc_(is_out_of_here) wrote:

 

No one here is going to translate that C code to LabVIEW for you, you will need to take the LabVIEW tutorials.

http://www.ni.com/academic/students/learn-labview/ 

I don't know what makes you think that you can just do something like your current project without actually learning a programming language.

 


 

 

1. am i able to samples faster than 120Hz

Yes.

 

2. would reading multiple inputs slow down the sampling rate

No.

 

3. If i am not satisfied with sample rates of labview (slower due to serial) could i just program the the arduino and send serial date to labview to show reading and also send back date from labview to control stuff . would doing this make a difference ?

Yes.

Yes. It will require a different LabVIEW program and for you to learn C.


 

 


 

0 Kudos
Message 4 of 9
(5,693 Views)

 


@nyc_(is_out_of_here) wrote:

@gready123456 wrote:

@nyc_(is_out_of_here) wrote:

 

No one here is going to translate that C code to LabVIEW for you, you will need to take the LabVIEW tutorials.

http://www.ni.com/academic/students/learn-labview/ 

I don't know what makes you think that you can just do something like your current project without actually learning a programming language.

 


 

 

1. am i able to samples faster than 120Hz

Yes.

 

2. would reading multiple inputs slow down the sampling rate

No.

 

3. If i am not satisfied with sample rates of labview (slower due to serial) could i just program the the arduino and send serial date to labview to show reading and also send back date from labview to control stuff . would doing this make a difference ?

Yes.

Yes. It will require a different LabVIEW program and for you to learn C.


 

 


 

Thank You


Can u point me in a good direction on how i can achive a incresed sample rate ? i am using LINX and a mega i have moded the analog read example a little the loop frequanct is 130Hz  and i am just find the rms  value and scaling it .

GR
0 Kudos
Message 5 of 9
(5,681 Views)

@gready123456 wrote:

 


@nyc_(is_out_of_here) wrote:

@gready123456 wrote:

@nyc_(is_out_of_here) wrote:

 

No one here is going to translate that C code to LabVIEW for you, you will need to take the LabVIEW tutorials.

http://www.ni.com/academic/students/learn-labview/ 

I don't know what makes you think that you can just do something like your current project without actually learning a programming language.

 


 

 

1. am i able to samples faster than 120Hz

Yes.

 

2. would reading multiple inputs slow down the sampling rate

No.

 

3. If i am not satisfied with sample rates of labview (slower due to serial) could i just program the the arduino and send serial date to labview to show reading and also send back date from labview to control stuff . would doing this make a difference ?

Yes.

Yes. It will require a different LabVIEW program and for you to learn C.


 

 


 

Thank You


Can u point me in a good direction on how i can achive a incresed sample rate ? i am using LINX and a mega i have moded the analog read example a little the loop frequanct is 130Hz  and i am just find the rms  value and scaling it .


I don't understand what using LINX and an Arduino Mega has anything to do with changing how often a LabVIEW WHILE loop iterates.

If you don't understand a simple WHILE, you had better seriously reconsider taking the LabVIEW tutorials.

 

 

 

 

0 Kudos
Message 6 of 9
(5,666 Views)

@nyc_(is_out_of_here) wrote:

@gready123456 wrote:

 


@nyc_(is_out_of_here) wrote:

@gready123456 wrote:

@nyc_(is_out_of_here) wrote:

 

No one here is going to translate that C code to LabVIEW for you, you will need to take the LabVIEW tutorials.

http://www.ni.com/academic/students/learn-labview/ 

I don't know what makes you think that you can just do something like your current project without actually learning a programming language.

 


 

 

1. am i able to samples faster than 120Hz

Yes.

 

2. would reading multiple inputs slow down the sampling rate

No.

 

3. If i am not satisfied with sample rates of labview (slower due to serial) could i just program the the arduino and send serial date to labview to show reading and also send back date from labview to control stuff . would doing this make a difference ?

Yes.

Yes. It will require a different LabVIEW program and for you to learn C.


 

 


 

Thank You


Can u point me in a good direction on how i can achive a incresed sample rate ? i am using LINX and a mega i have moded the analog read example a little the loop frequanct is 130Hz  and i am just find the rms  value and scaling it .


I don't understand what using LINX and an Arduino Mega has anything to do with changing how often a LabVIEW WHILE loop iterates.

If you don't understand a simple WHILE, you had better seriously reconsider taking the LabVIEW tutorials.

 

 

 


Ok right now i am not using any loop timing . This means the whille is looping as fast as possible . So if its runng at 130 Hz  max what is keeping it back ? 

Is it the fact that every time linx sends data it waits for a response from the arduino and this communication is keeping the sampling frequancy down ?

Are you sure u can increase the loop time ?

GR
0 Kudos
Message 7 of 9
(5,655 Views)



@nyc_(is_out_of_here) wrote:
I don't understand what using LINX and an Arduino Mega has anything to do with changing how often a LabVIEW WHILE loop iterates.If you don't understand a simple WHILE, you had better seriously reconsider taking the LabVIEW tutorials.

Ok right now i am not using any loop timing . This means the whille is looping as fast as possible . So if its runng at 130 Hz  max what is keeping it back ? 

Is it the fact that every time linx sends data it waits for a response from the arduino and this communication is keeping the sampling frequancy down ?

Are you sure u can increase the loop time ?


 

 

nyc ?? 

GR
0 Kudos
Message 8 of 9
(5,618 Views)

Hi, how are you?

 

you finished this proyect?

 you can helpme, i'm doing something very similar to openenergy.

 Thanks
0 Kudos
Message 9 of 9
(4,732 Views)