viernes, 30 de mayo de 2014

(labVIEW) Semaphore

In this post i will explain what is the semaphore function and how to use.

The semaphore is used when you want a VI or a portion of the block diagram wait another VI or other end of the chart to not waste CPU resources because Windows can not run both at the same time, although seems so.

With this function you can have two parts are executed simultaneously or a wait for the other end but is often used to choose which part runs before another.

In this case I made a simple LED in which two alternates, so that program until one goes, the other does not turn on.

This is the block diagram.














In the first while loop, the first LED is on for three seconds and then turns off. When this happened, the second while loop do the second LED is on for three seconds.

And this is the front panel:




lunes, 26 de mayo de 2014

(labVIEW) ActiveX and DLL call

In this exercise i will explain how to use the DLL call to make a multiplication operation.

In "Functions - Connectivity - Libraries & Executables" have the function of "Call Library Function"








You double-click and choose the DLL, in this case, "calc.dll" ... At the bottom you can see the different functions having the DLL. Choose what you want. (I've chosen "multiply").













At the bottom you will see the inputs and outputs of the selected function and data type.














In the tab "Parameters" add inputs and outputs, indicated in the previous step, with its data type.














Now just add the inputs and outputs in graphical mode in the block diagram.














And the Fron panel...





But this is only the first step of the program. When done with the multiplier, a song is played with Windows Media Player and open up a web page with the Web browser.

To play the song I use the DLL calling to move the mouse and click on the play button, picking this DLL library from the folder C:\Windows\System32\user32.dll














This is the VI’s block diagram:










And this is the front panel:










viernes, 16 de mayo de 2014

(labVIEW) Database

I will explain how to make a database program with LABView to create and delete tables or write and read data and showing them in a multiplot waveform .

At first time, we have to create a database in Microsoft Access.















When we have a database created, the next step will be insert data and tables. In this case, I did 3 trables with the PRESSURE, TEMPERATURE and WIND SPEED, and I Inserted the data for 24 hours.














After doing this, we start with LABView.
The first step in LABView is create an .udl archive...
Click in Tools and Create Data Link...

















Now we have to click next, choose our database and click acept.


















The next step is to link the route of our udl with the program we're going to do to read and write to the database.

We now turn to the first part of the program, which will read the first three tables already created. This will index the data that come from tables and parse into an array that will read through a waveform chart with three graphs














And now we move to the second, and most important part of the program, where we will create and delete tables, write in the table, column and row you want.

To write to a table, it must be done through SQL code, and to write to the column and row you want, you must first create a reference column whenever we create a new table.

















To do this, when we activate the first case structure, we create a table, and using the for loop to created by constant first column with numbers from 0 to 99 as reference.

With this we create our first table with the column reference.

In the middle we have another case structure, which when activated it will delete the selected table.

In the largest case structure, is where we write in the table, column and row desired.

The complete SQL code would be: UPDATE TABLE SET COLUMN = "TEXT" WHERE ID = ROW, but we need table, column, and row are variable, so we do split and concatenate the end, getting the same result with our precious variables.

So here when we activate this case structure, write the text you want where you want.

Finally, these three case structures, serve to show or hide the graphical waveform chart you created at the beginning in Access.



VARIABLES:














And finally, we have the variables. Note the constant that is down to the left, it is the constant that makes creating table, the column reference is created. And others are simply initialized to 0, so that when you launch the program nothing written on them.


And now is the time to show the Front panel, where we execute the program.

















But this is not all the exercise. To finish, I’m going to show how to make an executable file (.exe) with LabView, which is what the customer really needs.

First, you have to include the VI file in a LabView Project and then you must click with the right button of the mouse on “Build Specifications”.
















When we have done this a window will be opened where u have to configure.


















And now we only have to open the .exe archive and work with our new database program.




lunes, 12 de mayo de 2014

(labVIEW) Charge and discharge of capacitor

In this practice I am going to explain how to show in a Labview VI the waveform of the charge and discharge of a capacitor using the data acquisition provided by NI-myDAQ. The NI-myDAQ is a device which allows us the digital-to-analog and analog-to-digital conversion.














I used a 4K8 resistor to despise myDAQ internal resistance and voltage so that everything is in the 4K8 resistor.



















I chosen a 100uF capacitor, so I have to calculate the time of charge: Tc=5RC -> Tc=5*4800*0,0001=2’4secs.

Now i show the first part of the program, when we will write to myDAQ:















NImyDAQ typing mode makes RSE and reading it does because the differential mode analog outputs are all referenced to GND and analog inputs are referenced each individually for GND.

In the left we have the myDAQ configuration (output terminal configuration, units, phisical channels...) and we decide if is input or output.

The first frame have the configuration of output signal (ANALOG, SINGLE CHANNEL, SINGLE SAMPLE, DBL) and the output voltage (5V).

The second frame is a delay with the time necessary to capacitor can charge.

And the third frame is the same at first. This configure the output signal, but now with 0V.

Summarizing, the first part of the program gives us 5V for a certain time and stop the write part.

Second part:












In differential mode, each analog input signal has its own reference signal or return conductor.

In the left we have again the configuration, now we have to read the capacitor so we have to choose input mode, the units, sample mode, number of samples and the input speed.

Now we have a while loop where we will wait the time capacitor need to charge before start to read.

When we configure the read we have to choose the number of samples we want, in this case i chosen 60000.

We show the data read through a waveform graph and stop the read part.

And finally, i will show the last part of the program with the calculations, so we want to know the voltage of the capacitor at a particular time.

The formula to calculate the voltage is: Vins=Vf+(Vi-Vf)e^t/Rc













And this is the Fron panel where we can see the finished program:











jueves, 8 de mayo de 2014

I2C Exercise with Arduino UNO

In this exercise we will write and read in an EEPROM memory by I2C interface with an Arduino UNO and we will simulate in Proteus.


In Proteus I’ve built the next scheme with the 24LC256 EEPROM memory of Microchip, the Arduino Uno and a LCD display to see the data stored in the memory:














The next step is build the program in Arduino software:

///////////////////////////////////////////////

#include <LiquidCrystal.h>
#include <Wire.h>

LiquidCrystal lcd(6, 7, 8, 9, 10, 11); //Declaro el nombre del objeto LCD, y configuro los pines

void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte *data, byte length )//Escribo una página (64 bytes) y declaro la dirección del dispoitivo i2c, la dirección de la página en la eeprom, así como el puntero "data" y el byte "lenght"
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddresspage >> 8)); // MSB
  Wire.write((int)(eeaddresspage & 0xFF)); // LSB
  byte c;//Declara "c" como un byte
  for ( c = 0; c < length; c++) // incrementa "c" siempre que esté entre 0 y "lenght"
  Wire.write(data[c]);
  Wire.endTransmission();
}

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) // Leo un byte y declaro la dirección del dispositivo i2c, así como la dirección de la eeprom donde voy a leer
{
  byte rdata = 0xFF; // Declaro el byte "rdata" como el primer byte del LSB
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8)); // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
  Wire.requestFrom(deviceaddress,1);
  if (Wire.available()) rdata = Wire.read();
  return rdata;
}
void setup() 
{
  char somedata[] = "Hola CIFPN1"; //cadena a escribir
  Wire.begin(); //es obligatorio inicializar la conexion
  Serial.begin(9600);
  i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); //escribir la cadena al principio de la EEPROM; comentar esta linea para probar que la memoria es no volatil
  delay(10); //pequeña pausa despues de escribir en la memoria
  lcd.begin(16, 2);
  lcd.print(somedata);
}
void loop() 
{
  int addr=0; //direccion a leer
  byte b = i2c_eeprom_read_byte(0x50, 0); //acceso a la primera posicion de memoria
  while (b!=0) 
  {
    
    Serial.print((char)b); //enviar al ordenador
    addr++; //siguiente direccion
    b = i2c_eeprom_read_byte(0x50, addr); //acceso a posicion de memoria
  } 
  Serial.println();
  delay(500);
}

///////////////////////////////////////////////

And now is time to run the simulation and check the results:













We can see the memory and virtual terminal is empty














And now we can see we write in the memory and LCD screen at the same time we read as we can see in the virtual terminal.

viernes, 2 de mayo de 2014

SPI Exercise with Arduino UNO

In this exercise I am going to explain how use the protocol SPI to communicate two Arduinos.

This exercise consist in write an EEPROM memory with the first Arduino, and then read the same memory with the other Arduino and finally we can see in one LCD screen that is written into memory.

This communication between two Arduinos will be done with the SPI interface.

The EEPROM memory chosen is the 25AA020A of Microchip,  with 2Kbit  and SPI Bus Serial Interface.

At first, we have to design the scheme in Proteus:












Once we have the scheme, is time to program:

We have to program first the master Arduino which write in the memory:

///////////////////////////////////////////////////

#include <SPI.h>

#define MOSI 11
#define MISO 12
#define SCK 13
#define SS 10
#define PULSADOR 8
#define INT 9


char DATO[] = "JOSEMA";
int DIR_H = 0x00;
int DIR_L = 0x00;
int letra;
int estado_pulsador = LOW;

void escribir_eeprom()
{
  digitalWrite(SS, HIGH); //disable device
  delay(50);
  digitalWrite(SS, LOW);
  SPI.transfer(0x06); //write enable
  digitalWrite(SS, HIGH);
  delay(50);
  digitalWrite(SS, LOW);
  SPI.transfer(0x02); //write instruction

  SPI.transfer(DIR_H);   //send MSByte address first
  SPI.transfer(DIR_L);   //send LSByte address
   
  for(letra>=0; letra<=6;letra++)
   {
     SPI.transfer(DATO[letra]); //write data byte
   }
  digitalWrite(SS, HIGH); //release chip
  //wait for eeprom to finish writing
  delay(500);
}
void setup()
{
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);

  pinMode(MISO, OUTPUT);
  pinMode(MOSI, INPUT);
  pinMode(SCK, OUTPUT);
  pinMode(SS, OUTPUT);
  pinMode(PULSADOR, INPUT);
  pinMode(INT, OUTPUT);

  digitalWrite(SS,HIGH);
}


void loop()
{
  do
  {
    estado_pulsador = digitalRead(PULSADOR);
  }
  while(estado_pulsador == LOW);

  escribir_eeprom();

  digitalWrite(INT, LOW);
  delay(50);
  digitalWrite(INT, HIGH);
  for(;;){}
}

///////////////////////////////////////////////////

And now we have to program the second Arduino that will read the memory and write the data into the LCD:

///////////////////////////////////////////////////

#include <SPI.h>
#include <LiquidCrystal.h>

#define DATAOUT 11//MOSI
#define DATAIN  12//MISO
#define SPICLOCK  13//sck
#define SS 10//slave select
#define RESET 9//RESET del ARD1

LiquidCrystal lcd(8, 7, 6, 5, 4, 3);

char DATO;
int letra = 0;
byte DIR_H = 0x00;
byte DIR_L = 0x01;
volatile byte READ = 0x03;

void read_eeprom()
{
  digitalWrite(SS,LOW);           //slave selection
  SPI.transfer(READ);             //transmit read opcode
}

void setup()
{
  pinMode(RESET, OUTPUT);
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SS,OUTPUT);

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV4);

  lcd.begin(16, 2);
  lcd.print("  LECTURA:");

  digitalWrite(RESET,HIGH);
  digitalWrite(RESET,LOW);  //resetea el ARD1

  digitalWrite(SS,HIGH);          //slave deselection

  read_eeprom();
  for(letra>0; letra<8; letra++)
  {
    DATO = SPI.transfer((DIR_L)&&(DIR_H));
    lcd.setCursor(letra, 1);
    lcd.print(DATO);
    DIR_L++;
    if(DIR_L = 0xFF)
    {
      DIR_H++;
      DIR_L = 0x00;
    }
   if (letra<2)
   {
    lcd.scrollDisplayLeft();
   }
  }

  digitalWrite(SS,HIGH);  //slave deselection
  SPI.end(); //disable SPI communication
}

void loop()
{

}

///////////////////////////////////////////////////

When we have all of this, is time to verify the programs and take the .elf code which we will use to simulate
in Proteus.













We have the .elf code and and now we only have to double click in the Arduino and copy.















When we loaded the two programs, now we have to run the simulation and see the results:

First run the simulation and see the LCD is ON but nothing happened...















When we push the button, the first Arduino write in the EEPROM memory.















And next, the second Arduino read it and write the data in the LCD screen.












jueves, 1 de mayo de 2014

Network diagram SDIG

Below I show how it is organized the network that is installed in the SDIG classroom. I have designed the schemes with Visio Microsoft 2007.