Tuesday, February 15, 2022

Simple pendulum simulation using LabVIEW

 

A simple harmonic oscillator is a linear oscillator which is governed by the following linear characteristics equation:

 A pendulum is a non-linear system due to presence of sine term in its characteristics equation.  It exhibits harmonic motion only for small angle oscillations.


 
 

 For small values of θ, sinθ = θ. Thus the non-linear equation becomes



Let us put the above equations in ordinary differential equation form.

 We can assume any initial condition to solve the above ODEs. Let’s assume the following:

 

The position of Pendulum bob can be found out using simple trigonometric equations:



We will use above sets of equation to write our code and simulate the behavior of a simple harmonic oscillator and a non-linear pendulum.

Symbols used:

m= mass of the pendulum (neglecting mass of the hanging string)

L= Length of the string

b = damping coefficient

g = acceleration due to gravity = 9.81 m/s2

θ = angle subtended by the string with vertical position

 

LabVIEW implementation

Small initial angle; x1(0) = 25

The response of both linear (simple harmonic oscillator) and non-linear (Pendulum) system overlaps and identical. It holds true because for small θ, sinθ = θ. Thus equation (5) and (6) become same.

 

For large value of initial angle x1(0), the response of Linear and Non-linear pendulum varies as they have different angular displacements.

 

 

The “Damping enable” button allows us to enable or disable damping in our simulation.

 

Block Diagram of code

 

 

 

Tuesday, January 11, 2022

Micro second pulse train generation using Arduino

A very fast pulse train generator can be made using Arduino if we let go of the default instructions of Arduino IDE. The digitalWrite() command has inbuilt steps which makes the execution altogether slower. using this instruction we cannot achieve a pulse train faster than 150 kHz.

If we make changes at register level, pulses as fast as 4 MHz can be generated using Arduino UNO which houses a 16 MHz oscillator.

void setup(){

pinMode (13, OUTPUT);

}
void loop(){
while (1){ // this skips the loop() processing in the background
PORTB = 0b00100000; // write D13 (on Uno) to a 1
delayMicroseconds (5);// 5us delay, I believe it needs to be multiples of 4 on an Uno
PORTB = 0b11011111; // D13 to a 0
delayMicroseconds (20); // 20us delay
} // end while()
} // end loop()


The resulting pulse train from above code is shown. we can see there is jitter in the pulses. This is due to the instruction pinMode() which add problem with the code.

Let us make slight change in the code as below.

void setup(){
//pinMode (13, OUTPUT);

DDRB |= 0B00100000;
cli();
TIMSK0 &= ~(1 << TOIE0);
sei();

}
void loop(){
while (1){ // this skips the loop() processing in the background
PORTB = 0b00100000; // write D13 (on Uno) to a 1
delayMicroseconds (5);// 5us delay, I believe it needs to be multiples of 4 on an Uno
PORTB = 0b11011111; // D13 to a 0
delayMicroseconds (20); // 20us delay
} // end while()
} // end loop()

 

The resulting pulse train is stable even with lower pulse width and higher frequency. We can go for lower value of delay but the output pulse width will not be accurate as can be seen below. For the same code above where Ton is 5us, I am getting pulse width of 4us.

I could reach a pulse width of 60 ns for width set at 1us in code. This is interesting to get such a narrow pulse using a UNO though not accurate.The cause of this inaccuracy at lower pulse width is unknown to me.




 

Sunday, August 8, 2021

Sinusoidal wave generation using NI USB 6008

 National Instruments (NI) offers a wide range of data acquisition (DAQ) solutions to engineer and scientists since its inception. However a small time hobbyist may feel afraid to get one due to their high cost.

NI USB 6008/6009 offers a low cost alternative to hobbyist and college students. Its plug and play ability is convenient and offers less setup time.

In this post I will post the setup and code for generating sinusoidal waveform using analog output channel of USB6008.

Before that I must mention that analog output in USB 6008 is software timed. Software timed analog output means that your analog channel will update only once for every iteration of the program's while loop. It is important to remember that these devices allow a maximum update rate of 150 samples per second on each channel. Therefore the main program's while loop cannot iterate faster than once every 6 ms.

Secon important thing to keep in mind is that USB 6008 can output analog voltage in the range of 0...5VDC. So the output sinewave is not truly AC but a unipolar sinusoid. The code below will generate a sinusoid around 2.5 VDC offset.




On the front panel, we select the appropriate Physical channel, set the output rate and points per cycle to get the desired frequency of sinewave.


The output sine wave will have an approximate frequency = 1 / (output rate * points per cycle).  

Thursday, December 3, 2020

LabVIEW case structure: Making variables for inactive case invisible

 Hello,


Recently my friend gave me a situation where he need to build a case structure in LabVIEW such that the front panel display variables required in active/ selected case only.

This is actual problem that he gave me. Lets go ahead and see what I had done.

Case-1: Active variables "K" and "L"


Case-2: Active variables "h"



Case-3: Active variable "Sigma" and "F"

Lets us see the block diagram.

Case 1:

Case 2:


Case 3:
 


I have used visible property in property node for each variable in each case. Only the one need to show up is set TRUE and rest other are set FALSE.

I hope you like it.






Modbus and OPC comparison Table

  Modbus vs OPC Comparison between Modbus and OPC Feature Modbus OPC (OLE f...