Showing posts with label in. Show all posts
Showing posts with label in. Show all posts

Sunday, 19 March 2017

PIC16F887 877 programming in C Tutorial 3 3 Timer 2


Timer 2:
Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be used as the PWM time base for the PWM mode of the CCP module(s). The TMR2 register is readable and writable and is cleared on any device Reset.

The input clock (FOSC/4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits T2CKPS1:T2CKPS0 (T2CON<1:0>). 

The Timer2 module has an 8-bit period register, PR2.
Timer2 increments from 00h until it matches PR2 and then resets to 00h on the next increment cycle. PR2 is a readable and writable register. The PR2 register is initialized to FFh upon Reset. 

The match output of TMR2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a TMR2 interrupt (latched in flag bit, TMR2IF (PIR1<1>)).
Timer2 can be shut-off by clearing control bit, TMR2ON (T2CON<2>), to minimize power consumption.

Prescaler and Postscaler - Timer2 is an 8-bit timer with a prescaler and a postscaler. Each allows to make additional division of the frequency clock source.
Prescaler divides the frequency clock source BEFORE the counting take place at the register TMR2, thus the counting inside the TMR2 register is performed based on the divided frequency clock source by the Prescaler.
Postscaler divides the frequency that comes out of the Comparator.
T2CON Register:

How to calculate the required values of the TIMER2: TIMER2 FORMULA
Fout – The output frequency after the division.
Tout – The Cycle Time after the division.
4 - The division of the original clock by 4, when using internal crystal as clock (and not external oscillator).
Count - A numeric value to be placed to obtain the desired output frequency - fout.
(PR2 – TMR2) - The number of times the counter will count.

Code
Lets write the code to toggle the bits of portc after 2 sec;

void main() {
     // using 4MHz ext xtal
     int count=0;
     trisc=0;
     portc=255;
/////////////////// comment this block if you are using 877///////////
     ansel=0;
     anselh=0;
     c1on_bit=0;
     c2on_bit=0;
////////////////////////////////////////////
    
     t2con=124;         //prescaler is 16
     pr2=255;            //final value to count
     tmr2=0;              //initial value

     while(1){
        while(!tmr2if_bit);        //tmr2 flag bit
        tmr2if_bit=0;
        cnt++;


     if(cnt==488){                //for 2 sec(16*256u*488=2sec)
         portc=~portc;
         cnt=0;
         }

  }   
}


Schematic:
Timer 0 schematic can be used (tutorial 3 part 1). 


Readmore → PIC16F887 877 programming in C Tutorial 3 3 Timer 2

Wednesday, 8 March 2017

LCD Module in 4 bit Mode Circuit Diagram


In many projects use is made of alphanumeric LCDs that are driven internally by Hitachi’s industry-standard HD44780 controller. These displays can be driven either in 4-bit or 8-bit mode. In the first case only the high nibble (D4 to D7) of the display’s data bus is used. The four unused connections still deserve some closer attention. The data lines can be used as either inputs or outputs for the display. It is well known that an unloaded output is fine, but that a floating high-impedance input can cause problems. So what should you do with the four unused data lines when the display is used in 4-bit mode? This question arose when a circuit was submitted to us where D0-D3 where tied directly to GND (the same applies if it was to +5 V) to stop the problem of floating inputs.

The LCD module was driven directly by a microcontroller, which was on a development board for testing various programs and I/O functions. There was a switch present for turning off the enable of the display when it wasn’t being used, but this could be forgotten during some experiments. When the R/Wline of the display is permanently tied to GND (data only goes from the microcontroller to the display) then the remaining lines can safely be connected to the supply (+ve or GND). In this application however, the R/Wline was also controlled by the microcontroller. When the display is initialised correctly then nothing much should go wrong. The data sheet for the HD44780 is not very clear as to what happens with the low nibble during initialisation.

Circuit diagram :
LCD module_in_4-bit_Mode_Circuit_Diagramw
LCD Module in 4-bit Mode Circuit Diagram

After the power-on reset the display will always be in 8-bit mode. A simple experiment (see the accompanying circuit) reveals that it is safer to use pull-down resistors to GND for the four low data lines. The data lines of the display are configured as outputs in this circuit (R/Wis high) and the ‘enable’ is toggled (which can still happen, even though it is not the intention to communicate with the display). Note that in practice the RS line will also be driven by an I/O pin, and in our circuit the R/W line as well. All data lines become high and it’s not certain if (and if so, for how long) the display can survive with four shorted data lines. The moral of the story is: in 4-bit mode you should always tie D0-D3 via resistors to ground or positive.




Streampowers

Readmore → LCD Module in 4 bit Mode Circuit Diagram

Tuesday, 7 March 2017

In Circuit Transistor Checker


This simple circuit has helped me out on many occasions. It is able to check transistors, in the circuit, down to 40 ohms across the collector-base or base-emitter junctions. It can also check the output power transistors on amplifier circuits. Circuit operation is as follows. The 555 timer ( IC1 ) is set up as a 12hz multi vibrator. The output on pin 3 drives the 4027 flip-flop ( IC2). This flip-flop divides the input frequency by two and delivers complementary voltage outputs to pin 15 and 14. The outputs are connected to LED1 and LED2 through the current limiting resistor R3.

Circuit Diagram

In Circuit Transistor Checker Circuit DiagramThe LED's are arranged so that when the polarity across the circuit is one way only one LED will light and when the polarity reverses the other LED will light, therefore when no transistor is connected to the tester the LED's will alternately flash. The IC2 outputs are also connected to resistors R4 and R5 with the junction of these two resistors connected to the base of the transistor being tested. With a good transistor connected to the tester, the transistor will turn on and produce a short across the LED pair. If a good NPN transistor is connected then LED1 will flash by itself and if a good PNP transistor is connected then LED2 will flash by itself. If the transistor is open both LED's will flash and if the transistor is shorted then neither LED will flash.

Readmore → In Circuit Transistor Checker

Sunday, 5 March 2017

Types of Actuators used for Motion in Automation with Advantages Disadvantages




Types of Actuators used for Motion in Automation with Advantages & Disadvantages


The actuators used for performing motion (which includes control of speed, positional accuracy or torque) are

• Air Motors

• AC Induction Motors

• Clutch/Brake

• Stepper Motors

• Hydraulic Motors

• Servomotors

 1) Air Motors
This uses “compressed air” to create motion. Pressure and flow determine speed and torque. Positional accuracy is not a required.

Advantages:
1. Low cost
2. Available components
3. Maintenance easy
4. Simple
5 .Centralized power source

Disadvantages:
1. Audible compressor noise
2. Difficult to regulate speed
3 Prone to contamination
4. Energy inefficient

 2) Hydraulic motors
This uses “pressurized oil” to move a piston. Higher pressure results in higher torque (i.e. brute force).

Advantages:

1 .Easy to apply
2. High torques
3. Centralized power source
4. Simple

Disadvantages:
1. Audible noise
2. Difficult to control speed
3. Slow positioning
4. Prone to leaks
5. Energy inefficient
6. High maintenance required

 3) Clutch/Brake

A device couples a continuously rotating shaft and a load. Uncoupling the load results in stopping of shaft. Varying on/off time results in varying distances

Advantages:
1. Easy to apply
2. Low cost
3. Good for start/stop (not used with high loads)
4. Easy to provide speed matching

Disadvantages:
1. Uncontrolled acceleration
2. Inaccurate
3. Prone to wear
4. Non-repeatable performance

4) Stepping Motors

Electromechanical device which converts one digital pulse into a specific rotational movement/Step or displacement. A "train of pulses" results in rotational speed.

Advantages:
1. Simple control
2. Moderate cost
3. Good for constant loads
4. Good positional accuracy

Disadvantages:
1. Prone to losing steps
2. Not good for varying loads
3. Energy inefficient
4. Large motor size
5. Resonance problems

 5) AC Induction Motors –
Widely used for constant speed requirements. Electric "starters" provide connections/start-up/overload protection. Newer technology provides variable speed Drive capability.

                        Advantages:
         1. Simple motor
         2. Low cost
         3. Mature technology
         4. Straightforward on/off control
         5. Affordable coarse speed control
         6 .Simple wiring
         7. Wide product variety
         8. Many vendors available

                        Disadvantages:
         1. Limited position control
         2. Relatively larger size

 6) Servomotors
A motor with a "feedback" device called as encoder. High speed and position accuracy

Advantages:
1. High performance
2. Small size
3. Wide variety of components
4. High speeds available with specialized controls

Disadvantages:
1. High cost
2. High performance limited by controls
3. High speed, torque is limited.

Readmore → Types of Actuators used for Motion in Automation with Advantages Disadvantages

Tuesday, 6 December 2016

PIC16F887 877 programming in C Tutorial 6 Keypad Interfacing


Keypad Interfacing:
This tutorial is about the interfacing of 4x3(4 rows & 3 columns) keypad with micro-controller using library routine of mikroc. Using these functions it is much easy to program. The basic technique is,  make the coloums as i/p and drive the rows making them o/p, this whole procedure of reading the keyboard is called scanning.

In order to detect which key is pressed from the matrix, we make row lines low one by one and read the coloums. Lets say we first make Row1 low, then read the columns. If any of the key in row1 is pressed will make the corrosponding column as low i.e if second key is pressed in Row1, then column2 will give low. So we come to know that key 2 of Row1 is pressed. This is how scanning is done.

So to scan the keypad completely, we need to make rows low one by one and read the columns. If any of the button is pressed in a row, it will take the corrosponding column to a low state which tells us that a key is pressed in that row. If button 1 of a row is pressed then Column 1 will become low, if button 2 then column2 and so on...

The above whole algorithm is in Keypad_Key_Click() function, we are going to use, ones we have key just compare it the ASCII value to get the right key.  

Code:
Lets write a program that display the pressed key and quantity (how many times the key is pressed), on LCD using mickroc routines.  

unsigned short kp, cnt, oldstate = 0;
char txt[4];

// Keypad module connections
char  keypadPort at PORTD;
// End Keypad module connections

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections

void main() {
  cnt = 0;                                 // Reset counter
  Keypad_Init();                           // Initialize Keypad
 ///////////// comment for 877/////////////////////////////////////
  ANSEL  = 0;                              // Configure AN pins as digital I/O
  ANSELH = 0;
  c1on_bit=0;
  c2on_bit=0;
/////////////////////////////////////////////////////////////////
  Lcd_Init();                              // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off

  Lcd_Out(1, 1, "Key Pressed :");                 // Write message text on LCD
  Lcd_Out(2, 1, "Times: ");

  do {
    kp = 0;                                // Reset key code variable

    // Wait for key to be pressed and released
    do
            kp = Keypad_Key_Click();             // Store key code in kp variable
    while (!kp);
   // Prepare value for output, transform key to it's ASCII value
    switch (kp) {

      case  1: kp = 49; break; // 1
      case  2: kp = 50; break; // 2
      case  3: kp = 51; break; // 3
      case  4:                              //  kp = 65; break; // A for 4x4 pad
      case  5: kp = 52; break; // 4
      case  6: kp = 53; break; // 5
      case  7: kp = 54; break; // 6
      case  8:                              //kp = 66; break; // B for 4x4 pad
      case  9: kp = 55; break; // 7
      case 10: kp = 56; break; // 8
      case 11: kp = 57; break; // 9
      case 12:                             //kp = 67; break; // C for 4x4 pad
      case 13: kp = 42; break; // *
      case 14: kp = 48; break; // 0
      case 15: kp = 35; break; // #
      //case 16: kp = 67; break; // D for 4x4 pad
    }

    if (kp != oldstate) {                  // Pressed key differs from previous
      cnt = 1;
      oldstate = kp;
      }
    else {                                 // Pressed key is same as previous
      cnt++;
      }

    Lcd_Chr(1, 15, kp);                    // Print key ASCII value on LCD


    byteToStr(cnt, txt);                   // Transform counter value to string
    Lcd_Out(2, 12, txt);                   // Display counter value on LCD
  } while (1);
}

First specify the keypad connections; same thing we did in last tutorial, and LCD connections. Then initialize the keypad routine by using Keypad_Init() function, initialize the lcd and display the appropriate messages. Now once the key is pressed and the value is store in kp, by using Keypad_Key_Click() function, we have to compare the key number to its ASCII code to get the right key. Switch(kp) is used for this purpose.

Once we get the right key we compare it with oldstate; if Pressed key differs from previous, assign the cnt with one and update the oldstate. And if the Pressed key is same as previous, cnt is incremented (to count the number of times this key is pressed).

After this we want to display the pressed key and number of times on LCD. To display ASCII value, kp, we use 'Lcd_Chr' function. On the other hand cnt is a short to display it we have to convert it into a string; 'byteToStr' function is do the job. It converts input byte to a string. The output string has fixed width of 4 characters including null character at the end. txt[4] is declared for this purpose. For the next key the whole steps are repeated. 

Schematic:
keypad connection diagram


Readmore → PIC16F887 877 programming in C Tutorial 6 Keypad Interfacing

Monday, 31 October 2016

The Chinas ZTE launches Firefox phones in US Britain


China's ZTE launches Firefox phones in US, Britain

WASHINGTON — Chinese telecom giant ZTE announced plans Monday to sell a low-cost smartphone using the open source Firefox operating system in the United States and Britain.

ZTE said its Open Firefox OS phone will be sold through eBay in the US for $79.99 and 59.99 pounds in Britain.

The phone, unlocked to allow use on a variety of mobile networks, uses the open source Firefox operating platform from the nonprofit Mozilla Foundation, which is aiming to break the dominance of Google's Android and Apple's iOS.

"The global availability of the ZTE Open through eBay means that more consumers worldwide are now able, for the first time, to buy an affordable smartphone based entirely on open Web standards," the Chinese firm said in a statement.

"The ZTE Open is powered by Firefox OS, which frees developers, operators and consumers from the constraints of existing closed ecosystems by using the Web as the platform for all functionality and applications."

The statement said sales would begin "soon," without elaborating.
ZTE vice president Dai Wenhong said the company "is devoted to providing more options for customers globally and enabling them to live better lives via advanced technology.

The ZTE Open offers customers a smartphone experience at an incredible price point, making it ideal for cost conscious consumers or those looking to upgrade to a smartphone for the first time."

The phone offered for US and British consumers is orange in color, while a blue version has been on sale in Spain and Venezuela and a black version in Colombia.

In June, Taiwan's Hon Hai Precision said it aims to hire up to 3,000 new employees to develop devices and software for Mozilla's Firefox operating system.

Hon Hai, better known by its trade name Foxconn and a major supplier to Apple, plans to produce five devices running on Firefox.

The Firefox operating system uses applications on HTML5, a Web standard which operates across platforms, unlike those developed for specific systems such a Apple's iOS or Google Android.
Copyright © 2013 AFP. All rights reserved.

Readmore → The Chinas ZTE launches Firefox phones in US Britain