Timers

There are two timers in 8051 microcontroller. Timers are used for the following purposes

  1. For events counting.
  2. To calculate event duration time.
  3. For delay time calculation.

How Timers of 8051 Count?

Each timer has it’s own two 8 bit registers for counting that make 16 bits for count as a whole. These registers are TH0, TL0 for timer 0 and TH1, TL1 for timer 1. Each timer counts one on each machine cycle. We know that 1 machine cycle is of 12 oscillator cycles. It means clock given to timer is

Timer Clock = Oscillator clock / 12

If oscillator

Modes of Operation of 8051 Timers

In 8051 each timer has following modes of operation

  1. 16 Bit Mode
  2. 13 Bit Mode
  3. 8 Bit Auto Reload Mode
  4. Split Timer Mode

1. 16 Bit Mode

In this mode timer uses all 16 bits for counting and maximum counting figure is 65535 (0xffff in hex). When timer try to count next to 65535 (0xffff) it is reset to 0 and timer overflow flag is set and if corresponding timer interrupt is enabled then interrupt service routine for that timer is called and executed. We can adjust timer start value other than default 0 value between 0 to 65535 in the interrupt service routine or when we recognize that overflow has occurred. But in this way there may be some error in calculation as instructions to load interrupt service routine will also take some timer counts during their calling and loading.

Electronic Dice Using Arduino

Description

It is Electronic Dice Game Using Arduino. It is basic arduino learning project that shows how we access arduino pins for writing. Like in basic arduino LED flasher

Circuit Diagram

In circuit diagram 7 LEDs are connected each with 220 Ohm resistor in series to arduino.

/2017/06/Electronic-Dice-Using-Arduino-00.png

Detail

It is a game in which we press button connected to pin 6 of arduino. When button is pressed different patterns of dice game are produces in fast speed. And when we release this button a random pattern is selected and shown on LEDs. This is simple example in which we generate random number from 1 to 6 range and display this number on LEDs.

Software

Arduino program is simple but lengthy. It first set pin mode for button/key as input with internal pullup resistor enabled and for LEDs as outputs. Initially displays 1 on LEDs. Calls srand() function for random number generation. This function is called once. Then in loop() function when key is pressed it generates random numbers from 1 to 6 range and display on LEDs. When key is released random number generation is stopped and final number is displayed on LEDs. Here is program


#include <stdlib.h>

// Define macro or formulae for random number
// generation from 1 to 6.
#define GetRandomNumber() ((rand() % 6) + 1)

void Display(char Value);
void turnOffAllLeds();

const int Switch = 6;

const int Led1 = 7;
const int Led2 = 8;
const int Led3 = 9;
const int Led4 = 10;
const int Led5 = 11;
const int Led6 = 12;
const int Led7 = 13;

void setup() {
  // put your setup code here, to run once:
  pinMode(Switch, INPUT_PULLUP);
  pinMode(Led1, OUTPUT);
  pinMode(Led2, OUTPUT);
  pinMode(Led3, OUTPUT);
  pinMode(Led4, OUTPUT);
  pinMode(Led5, OUTPUT);
  pinMode(Led6, OUTPUT);
  pinMode(Led7, OUTPUT);

  // Turn off all Leds.
  //turnOffAllLeds();
  Display(1);
  srand(50);
}

void loop() {
  char randomNumber;
  // put your main code here, to run repeatedly:
  while(digitalRead(Switch));
  while(!digitalRead(Switch))
  {
    // Generate random number.
    randomNumber = GetRandomNumber();

    // Display this random number
    // on Leds.
    Display(randomNumber);
    // Give some delay.
    delay(10);
  }
    // Generate random number last time.
    randomNumber = GetRandomNumber();
    // Finally display this number on LEDs.
    Display(randomNumber);
}

void turnOffAllLeds()
{
  digitalWrite(Led1, HIGH);
  digitalWrite(Led2, HIGH);
  digitalWrite(Led3, HIGH);
  digitalWrite(Led4, HIGH);
  digitalWrite(Led5, HIGH);
  digitalWrite(Led6, HIGH);
  digitalWrite(Led7, HIGH);
}

// This function displays an integer value from
// 0 to 6 on LEDs.
void Display(char Value)
{
  // Switch off all LEDs.
  //Led1 = Led2 = Led3 = Led4 = Led5 = Led6 = Led7 = 1;
  turnOffAllLeds();
  switch(Value)
  {
  case 1:
    digitalWrite(Led4, LOW);
    break;
  case 2:
    digitalWrite(Led1, LOW);
    digitalWrite(Led7, LOW);
    break;
  case 3:
    digitalWrite(Led1, LOW);
    digitalWrite(Led4, LOW);
    digitalWrite(Led7, LOW);
    break;
  case 4:
    digitalWrite(Led1, LOW);
    digitalWrite(Led3, LOW);
    digitalWrite(Led5, LOW);
    digitalWrite(Led7, LOW);
    break;
  case 5:
    digitalWrite(Led1, LOW);
    digitalWrite(Led3, LOW);
    digitalWrite(Led4, LOW);
    digitalWrite(Led5, LOW);
    digitalWrite(Led7, LOW);
    break;
  case 6:
    digitalWrite(Led1, LOW);
    digitalWrite(Led2, LOW);
    digitalWrite(Led3, LOW);
    digitalWrite(Led5, LOW);
    digitalWrite(Led6, LOW);
    digitalWrite(Led7, LOW);
    break;
  }
}


Thermometer Using LM35D Arduino And LCD

Description

It is a LCD Thermometer Using Arduino and LM35D temperature sensor. It shows temperature on 16×2 LCD in degree centigrade.

Circuit Diagram

In circuit diagram 16×2 LCD is connected to arduino. LM35D is connected to analog channel input of arduino.

/2017/06/Thermometer-Using-Arduino-LM35D-00.png

Detail

LCD is connected in conventional 4 bit mode and LM35D temperature sensor is connected to first analog input channel of arduino. LM35D gives analog output corresponding to temperature. When temperature of environment changes it’s output voltages also changes. It gives 10mv per degree centigrade, means if output of LM35D is 10mv then surrounding temperature will be 1 degree centigrade. If output changes to 100mv then surrounding temperature will be 10 degree centigrade. Our arduino program reads this voltage level and converts it into corresponding temperature value. And then displays this value on 16×2 LCD in centigrade.

Software

#include <LiquidCrystal.h>

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

// Define analog pin where
// LM35D is connected.
const int LM35DPin = A0;

void setup() {
  // put your setup code here, to run once:

  // Setup LCD
  lcd.begin(16, 2);

  lcd.print("Temperature");

}

void loop() {
  // put your main code here, to run repeatedly:
  float temperature = analogRead(LM35DPin);
  temperature = temperature * 5000;
  temperature /= 10240;
  lcd.setCursor(0,1);
  lcd.print(temperature);
  lcd.print((char) 223);
  lcd.print('C');
  delay(300);
}

PC Serial RS232 Interface With Arduino

Description

It is serial RS232 Port interface example with Arduino. Serial Port is a channel for communication with microcontroller/arduino.

Circuit Diagram

Circuit diagram is simple and there is no need of extra component. All hardware interface between arduino microcontroller and PC is already provided in arduino board. Here is simple diagram in proteus to use with serial terminal in proteus.

/2017/06/PC-Serial-RS232-Port-Interface-With-Arduino-00.png

Detail

Serial port is used to communicate with other devices like microcontrollers and PCs. It is most commonly used method for communication between arduino and computer. In serial RS232 interface all data bits are transmitted and received one bit at a time in a stream. So there is series of bits on single wire/pin. In arduino serial port is implemented over USB. There is USB to serial converter device required between arduino microcontroller and PC that is already implemented in arduino board. So, there is no need to add it additionally. This project is the base for so many other projects.

Software


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.write("Started...");

}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available())
  {
    Serial.write(Serial.read() + 2);
  }

}

In software setup() function we first initialize serial channel at 9600 bits/sec. Then we send “Started…” string towards PC. You can see how this “Started…” string is received in terminal in proteus shown in above diagram. You will also see next in video that how this string “Started…” is received in PC. In loop() function we check that if any received character is available? then read this character add 2 to it and send back towards PC.
Here is video for further clarification.

16×2 LCD Interface With Arduino

Today I am going to tell you how to interface 16×2 LCD with Arduino.

Circuit Diagram

/2017/05/16x2-LCD-Interface-To-Arduino-00.png

LCD

Display has very importance in embedded systems. It is used to interact humans with system. Instructions and device function results are shown on displays. Without display we cannot see what operation is being performed inside the arduino/microcontroller. LCDs are most widely used in embedded systems to provide user interface. In this example I am using HD44780 based 16×2 LCD. This LCD can be interfaced using 8 bit or 4 bit mode. In 8 bit mode all 8 data pins are used while in 4 bit mode only 4 pins of LCD are used. In this project I have used 4 bit mode of operation. 16×2 means it has 16 columns and 2 rows. HD44780 controller is installed on other sizes of LCDs like 16×1, 16×4, 20×2, 20×4 etc.

/2012/08/LCD.jpg

Pin-Out

Pin Symbol Function
1 Vss ground (0 V)
2 Vdd power (4.5 – 5.5 V)
3 Vo contrast adjustment
4 RS H/L register select signal
5 R/W H/L read/write signal
6 E H/L enable signal
7-14 DB0 – DB7 H/L data bus for 4- or 8-bit mode
15 A (LED+) backlight anode
16 K (LED-) backlight cathode

We can read & write data to LCD but to keep things simple we have hardwired R/W line to ground for only writing. It means we can only print on LCD but cannot read back content written in LCD RAM.

Software

In arduino we use builtin library for LCD interfacing “LiquidCrystal.h”. And this makes LCD interfacing with arduino simple and easy.

#include <LiquidCrystal.h>

// Define object of LiquidCrystal class.
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);

  // Print welcome message
  // to LCD.
  lcd.print("Welcome!");
  
  // Set cursor to next line and 
  // first column.
  lcd.setCursor(0,1);
  
  lcd.print("micro-digital.net");

}

void loop() {
  // put your main code here, to run repeatedly:

}

Led Flasher With Arduino

It is simple and basic arduino project. You can say it welcome/hello world project in arduino programming. In this project I will first blink on board LED of arduino and then will use off board LED.

Blinking On Board Arduino LED

Arduino is a prototyping board for embedded systems development. In this example I am using Arduino UNO board. In this board ATMega328 microcontroller is installed. On board arduino LED is connected to pin number 13. Here is the circuit with off board LED.

/2017/05/Arduino-LED-Flasher-00.png

What Will You Need

For on board LED you need only

  1. 1 x Arduino Board
  2. 1 x USB Cable
  3. 1 x Computer with Arduino IDE installed

For off board LED you need some more parts

  1. 1 x Bread Board
  2. 1 x LED
  3. 1 x 150 Ω Resistor
  4. 3 x Jumper Wires

Software


// Define pin 13 as LED pin
const int LED = 13;

void setup() {
  // put your setup code here, to run once:

  // Set LED pin as output.
  pinMode(LED, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  // Set LED pin at high/5V level.
  digitalWrite(LED, HIGH);
  // Delay for 500 ms.
  delay(500);
  // Set LED pin at low/0V level.
  digitalWrite(LED, LOW);
  // Delay for 500 ms.
  delay(500);
}

Transformer Designer

/2017/05/transformer-designer-01.png
This app is for transformer designing calculations. Transformers are widely used in our electrical applications to step down or step up AC voltage. These are used in power supplies, stabilizers, inverters, converters, UPS and so many other applications. This app is complete solution especially for 2 winding transformer. This app helps transformer designers to find out different transformer parameters. These parameters are

  1. Turn/Volt
  2. Turns for each coil
  3. SWG/AWG Wire for each coil with actual rate (cmils/A)
  4. Core Area for bobbin selection

During transformer design we need to know core area of transformer for the selection of bobbin. We want to calculate turns/volt so that we can calculate total turns for each coil. For each different coil different SWG/AWG wire is needed. We have to decide how much thick wire will be able to carry required amount of charge through it. Wires are divided according to their thickness/area of cross section. Each wire is assigned a number according to Standard Wire Gauge (SWG) or American Wire Gauge (AWG). This number is called SWG or AWG number of that wire. We know, a thick wire will be able to carry more charge than a thin wire. Here, I have considered circular mils (cmils) as unit of cross sectional area measurement.

This app is helpful in transformer winding, power supplies, inverters, converter and UPS development and sales business. Now, if you are a transformer designer/winder this app is for you.
You can install it from here.

Transformer-Designer

How It Works?

Let us consider we want a transformer for our LED sign board supply. LED sign board needs almost 12V and 4A supply. Considering other factors like temperature, we decide to design a transformer for 12V and 5A. Now, run this app and first enter 1 number of output coils like shown in the following figure and press “Next”.

/2017/05/transformer-designer-0.png

Now, enter VA, Voltage and/or Current values as shown in the following figure. Here you have to enter first and the only output coil’s power requirement. Enter any two of the values and leave single value empty. If you entered all three values then app will calculate third according to left to right order means it will calculate “Current” value by dividing “VA” by “Voltage”. After this press “Next”.

/2017/05/transformer-designer-1.png

Now, enter number of input coils. Here, in our example this is 1.

/2017/05/transformer-designer-2.png

Here, enter “Voltage” or “Current” value of input coil but not both as total VA of transformer are calculated according to output coils and is shown in the following figure.

/2017/05/transformer-designer-3.png

Now, enter value of Rate. In open air wires remain cool and can pass charge at more rate means with less cross sectional area a wire can pass more charge and so more current. But, when we use same wire in transformer/coil winding where wires are wound in layers, one layer over other and there is no air present between these layers but there is paper between them, so wires fail to get cool due to air, their charge passing capability is reduced and so, can pass charge at lower rates. Usually, we double rate (area) in transformers than in open air. We use 500/530 cmils/Amp value or more for transformers. There are so many other factors that affect this value, some of which are temperature, peak load time, working duration of machine per day etc. So, you have to choose better value of Rate considering all these factors. Here, we enter 530 cmils/A. Enter flux density of core used in weber per square inch. Default value for silicon core is 0.0006 weber per square inch. This app is optimized for silicon core. You can use other cores and do experiment. Finally, enter frequency of input voltage. In my country it is 50 Hz. Press “Next” to continue

/2017/05/transformer-designer-4.png

Now, here results are calculated.

/2017/05/transformer-designer-5.png

Here for each output and input coil following parameters are calculated

  1. VA and/or Voltage and/or Current
  2. Turns for coil
  3. 2 SWG numbers with actual rate (in cmils/A)
  4. 2 AWG numbers with actual rate (in cmils/A)

First SWG is safe SWG and second is calculated for your ease if it is with acceptable rate for you. Because this value also depend some other factors like how long transformer will be operated without resting and surrounding temperature etc. Usually we choose between 500 cmils/A and 530 cmils/A. Similarly, 2 AWG numbers are calculated. First is safe and second may or may not be safe for you. Now, scroll and see other parameters

/2017/05/transformer-designer-6.png

At the end there are some other parameters of transformer like

  1. Total VA of transformer
  2. Turn/Volt
  3. Core Area
  4. Selected Rate value
  5. Frequency and
  6. Flux Density of core
/2017/05/transformer-designer-7.png

Install this app from Google Play. Enjoy! this app.

Transformer-Designer

Disclaimer

We have designed this app at our best. We have tested it so many times but use it at your own risk. We will not responsible for any kind of loss in any form due to this app. If you find any bug or defect then please inform us at udigital.solutions@gmail.com. If you have idea of an app you can also share with us at this email.

Transformer Winding Calculator

/2017/05/Transformer-Winding-Calculator-00.jpg

This app can calculate SWG/AWG wire number for your transformer coil and turns per volt to calculate total turns of coil.

During transformer/ciol design we have to decide how much thick wire will be able to carry required amount of charge through it. Wires are divided according to their thickness/area of cross section. Each wire is assigned a number according to Standard Wire Gauge (SWG) or American Wire Gauge (AWG). This number is called SWG or AWG number of that wire. We know, a thick wire will be able to carry more charge than a thin wire. Here, I have considered circular mils (cmils) as unit of cross sectional area measurement.

Now, there is no need to look up a table/chart against your required value of current for wire selection. This smart app will do this work for you.

How It Works?

SWG/AWG Calculation

It takes two values as input. First is Current that has to be passed through wire, so wire should be able to carry this value of current. Second value is Rate circular mils per ampere.
It generates two output values as well. First and third are SWG and AWG number of wires that are safe for given value of current and it’s actual rate. Second and forth values are the SWG and AWG numbers of next wires that may be or may be not near the required wire with it’s actual rate. You can decide yourself which SWG/AWG wire will be better for your current requirement.

/2017/05/transformer-winding-calculator-0.png

First enter value of Current.

/2017/05/transformer-winding-calculator-1.png

Now, enter value of Rate. In open air wires remain cool and can pass charge at more rate means with less cross sectional area a wire can pass more charge and so more current. But, when we use same wire in transformer/coil winding where wires are wound in layers, one layer over other and there is no air present between these layers but there is paper between them, so wires fail to get cool due to no air, their charge passing capability is reduced and so, can pass charge at lower rates. Usually, we double rate (area) in transformers than in open air. We use 500/530 cmils/Amp value or more for transformers. There are so many other factors that affect this value, some of which are temperature, peak load time, working duration of machine per day etc. So, you have to choose better value of Rate considering all these factors.

/2017/05/transformer-winding-calculator-2.png

Now, you press “CALCULATE” button and results will be shown to you as in the following figure.

/2017/05/transformer-winding-calculator-3.png

Turn Per Volt Calculation

First enter area of core in square inches.

/2017/05/transformer-winding-calculator-4.png

Now, enter flux density of core used in weber per square inch. Default value for silicon core is 0.0006 weber per square inch. This app is optimized for silicon core. You can use other cores and do experiment.

/2017/05/transformer-winding-calculator-5.png

Enter value of frequency in hertz. Default value is 50 Hz.

/2017/05/transformer-winding-calculator-6.png

Now, press calculate button below frequency field and app will show result as shown in the following figure.

/2017/05/transformer-winding-calculator-8.png

Download this app from Google Play. Enjoy! this app.

Disclaimer

We have designed this app at our best. We have tested it so many times but use it at your own risk. We will not responsible for any kind of loss in any form due to this app. If you find any bug or defect then please inform us at udigital.solutions@gmail.com. If you have idea of an app you can also share with us at this email.

Wire Gauge Calculator Pro

/2017/05/Wire-Gauge-Calculator-Pro.jpg

During transformer/ciol design we have to decide how much thick wire will be able to carry required amount of charge through it. Wires are divided according to their thickness/area of cross section. Each wire is assigned a number according to Standard Wire Gauge (SWG) or American Wire Gauge (AWG). This number is called SWG or AWG number of that wire. We know, a thick wire will be able to carry more charge than a thin wire. Here, I have considered circular mils (cmils) as unit of cross sectional area measurement.

Now, there is no need to look up a table/chart against your required value of current for wire selection. This smart app will do this work for you.

How It Works?

It takes two values as input. First is Current that has to be passed through wire, so wire should be able to carry this value of current. Second value is Rate circular mils per ampere.
It generates two output values as well. First and third are SWG and AWG number of wires that are safe for given value of current and it’s actual rate. Second and forth values are the SWG and AWG numbers of next wires that may be or may be not near the required wire with it’s actual rate. You can decide yourself which SWG/AWG wire will be better for your current requirement.

/2017/05/wire-gauge-calculator-pro-1.png

First enter value of Current.

/2017/05/wire-gauge-calculator-pro-2.png

Now, enter value of Rate. In open air wires remain cool and can pass charge at more rate means with less cross sectional area a wire can pass more charge and so more current. But, when we use same wire in transformer/coil winding where wires are wound in layers, one layer over other and there is no air present between these layers but there is paper between them, so wires fail to get cool due to no air, their charge passing capability is reduced and so, can pass charge at lower rates. Usually, we double rate (area) in transformers than in open air. We use 500/530 cmils/Amp value or more for transformers. There are so many other factors that affect this value, some of which are temperature, peak load time, working duration of machine per day etc. So, you have to choose better value of Rate considering all these factors.

/2017/05/wire-gauge-calculator-pro-3.png

Now, you press “CALCULATE” button and results will be shown to you as in the following figure.

/2017/05/wire-gauge-calculator-pro-4.png

Download this app from Google Play. Enjoy! this app.

Disclaimer

We have designed this app at our best. We have tested it so many times but use it at your own risk. We will not responsible for any kind of loss in any form due to this app. If you find any bug or defect then please inform us at udigital.solutions@gmail.com. If you have idea of an app you can also share with us at this email.

Some of Our Efforts in Traffic Signals and Displays

GSM Based Scrolling Message Display

Following is the video of GSM Based Scrolling Message Display developed by Micro Digital. It was installed in Islamabad at 10 different locations including Zero Point, Shakar Parian and Way To Daman-e-Koh in 2008. This display was operated remotely through SMS and public informational messages/news were played on them.

Some more scrolling message display products with new exiting features are in development process that will be posted on our site in near future.

First Traffic Signal Controller By Micro Digital

Here are the videos of our first traffic signal controller. It’s copies were installed at Jehlum Main Chowk on GT-Road, Kohat and some in Peshawar.

Pedestrian Road Crossing Signal

Following is an imported Pedestrian Road Crossing Signal.

Large Size Digital Clock For Stadium

Following is the video of large size digital clock to be installed in stadiums/university gates etc. 7 Segment used in this clock is same as we use in traffic signal count down meter.