Showing posts with label Microcontroller. Show all posts
Showing posts with label Microcontroller. Show all posts

7/21/2017

Interfacing LCD With Arduino Microcontroller

In this tutorial we are going to interface a Liquid Crystal Display (LCD) with Arduino Microcontroller. Liquid Crystal Display are used in many devices.

Liquid Crystal Display LCD


Components Required


Hardware: 

ARDUINO UNO, 
power supply (5v),  
16X2 Liquid Crystal Display  (LCD)

Software: 

Arduino IDE

Pin Configuration

Liquid Crystal Display LCD
Pin 1GND
Pin 2+5V
Pin 3Mid terminal of potentiometer (for brightness control)
Pin 4Register Select (RS)
Pin 5Read/Write (RW)
Pin 6Enable (EN)
Pin 7DB0
Pin 8DB1
Pin 9DB2
Pin10DB3
Pin 11DB4
Pin 12DB5
Pin 13DB6
Pin 14DB7
Pin 15+4.2-5V
Pin 16GND


Description Of Pin

Register Select : RS pin is used to select the register.


RW selects either read or write mode.
Enable: E enables the LCD module.

Data Pins: Pin7 to Pin14 are data Pins.
Logic High (1) – Activates Data register.
Logic Low (0) – Activates  Instruction register.
Logic High (1) – Activates Read mode.
Logic Low (0) – Activates Write mode.
Vss: It is the Ground Pin of the module.
Vdd : It is the supply pin of the module.
VEE : Pin3 is used for controlling the brightness of the LCD. Normal setting of this pin is between 0.4V to 0.9V.A 10 k pot is connected to adjust the brightness of the screen.

Circuit Diagram:

Liquid Crystal Display LCD
Arduino Code:-


 #include
LiquidCrystal lcd (5, 4, 3, 2, 1, 0);  

Void setup ()
{
 lcd.begin(16, 2);  
}

Void loop ()
{
  lcd.setCursor (0, 0);         
  lcd.print ("Hello World"); 
  lcd.setCursor (0,1);       
  lcd.print ("16X2 LCD");     
}




2/03/2017

How to display hidden files and folders

There is a lot of method to do so, but today i am going to share the easiest method to display hidden files and folders in window.

  •  Click on start button 
  • Go to control panel


    • Click on Appearance and Personalization

    • click on Folder Options
    • Under Folder Option, do the same as follow image

    • Now restart your PC and see the magic :) ..
    But do not forget to again the restore default after finish your work.

    12/29/2015

    Line Following Robot

    Line following robots have been around for years, so many people have had chances to attack this sort of problem. Line following robots can be very basic or very sophisticated depending on the hardware used, efficiency wanted, and programming capabilities. In the history of line following robots the differential steering system is the most widely used way of keeping the robot on course. Infrared (IR) sensors are used more frequently in line following robots then any other sensor.

    Hardware

    The four main Hardware items needed to build and control a line following robot are Sensors, Micro-controllers, Drivers, and Motors.

    Sensors

    As mentioned before IR sensors are the most popular sensor used in the line following robot field. IR sensors have two IR LED, one is the Emitter and the other is the Receiver. An electrical property of these LED is that they produce a voltage difference across its leads when it is subjected to light. This voltage can barely be detected. An Op-Amp is normally used to increase this voltage to a reasonably detectable range. By amplifying the voltage, the changes in voltage will be easier to detect.

    There are many other sensors that can be used to detect lines. Photo-cells and Photo-resistors are two other common sensors used.

    The image below is a commercially available single line following IR sensor. It needs only 5 volts to run. The output signal ranges from 0V to 5V. This range is based off of it seeing white or black. This also means there is an Op-Amp already installed. The sensing distance is 0.04 in to 0.5 in. This short range is common for IR sensors.

     The image shown below is also a commercially available line following IR sensor. As you can see there are five IR sensors set up in an array. This board reads from all five sensors and outputs a 0-127 signal, 0 meaning all sensors are seeing white and 127 means all are seeing black. It has the same input voltage and range as the single line following IR sensor. An array of sensors is the most efficient way of sensing and staying on a line. PID Controller

    Common Sensors

    IR

    IR— Infra-red sensors are normally used in range or proximity sensing. Time-of-Flight from the emitter to the receiver is used to calculate the distance to an object.

    Sonar

    Sonar sensors are used in the same manner as the IR sensors. The sonar sensor sends out a sound wave and measures the time it takes to return to the sensor. Sonar sensors are also used widely in range finding.

    Laser

    Lasers have the best range and percision of all the sensors used in robotics. They are very expensive and can be fairly large compared to IR and Sonar sensors. The same basic concept is used in laser sensors as IR and Sonar sensors.

    Micro-Controller

    The type of micro-controller used in your application may vary depending on what other objectives you may need to accomplish. The simplest micro-controller that will be needed to just follow a line will need to have an Analog to Digital (ATD) port (or something equivalent "Comparator") and a couple basic I/O pins. The ATD port is to read from the sensor and the two I/O pins are to control the drivers which in part control the motors. The more ATD ports on the micro-controller used will greatly improve the efficiency of the robot if coded properly.

    Drivers

    There are many types of drivers offered but all of them have the same concept. An H-Bridge configuration is the most common.
    The diagram above shows how simple the concept of an H-Bridge really is. To rotate the motor in one direction the controller would need to close switches S1 and S4. To rotate in the opposite direction, the controller would need to close switches S3 and S2.

    The driver shown below is a Texas Instruments(TI) L293 quadruple high-current half-H driver. The L293 is designed to provide bidirectional drive currents of up to 1 A at voltages from 4.5 V to 36 V. The L293 is designed to drive inductive loads such as relays, solenoids, dc and bipolar stepping motors, as well as other high-current/high-voltage loads in positive-supply applications.

    Most IC drivers like the TI L293 have Enable pins, which will turn on that half of the IC or the IC in general. Pin 1 is the Enable pin for the first two half-H bridges. From the diagram Pin 9 turns on the other two half-H bridges. Pin 8 is the motor supply voltage input pin. This voltage is normally higher then the voltage used by other components on the robot. Pins 2 & 7 are the input pins to turn on or off the motors. Pins 3 & 6 are the outputs to the motor. Everything from here on is mirrored across the IC. This driver offers multiple configurations for motor set-ups. The figure below shows two different configurations. By connecting the two half-H bridges through a motor the controller can rotate the motor in both directions(right side). If Pin 2 is high and Pin 7 is low the motor will rotate in one direction and vise versa for the opposite direction. The drivers can also be configured to run one motor in only one direction using only one of the half-H bridges as seen on the left side of the figure below.

    Motors

    The motors and gearing used will be based off of the objective the robot is trying to complete.
    A concern when choosing motors and gear reduction for a line following robot would be keeping the speed of the motors slow enough the robot is not over shooting the edge of the line. If the robot does over shoot the edge of the line the robot could become lost. Depending on programming the robot may never find the line or could find the line but will be going in the wrong direction and not know.

    Programming

    Zig-Zag Method

    The Zig-Zag method is the simplest and easiest way of programming a line following robot. The concept is the robot moves across the line it is following until it meets an edge. Once it senses it has hit an edge it turns the current motor off and turns the opposite motor on. Once it senses the next edge it swaps the power to the first motor again. As you can see the robot Zig-Zags back and forth across the line.

    One Sensor

    The Zig-Zag method with one sensor is a very basic line following robot. Since there is only one sensor there will only be one reading. This reading will be either "I see Black" or "I see White". As mentioned before the Zig-Zag method crosses back and forth across the line being followed, this causes problems with wide lines. The robot will move across the line untill it senses the edge, by the time it gets to the edge it might not be facing the end point any more. Further thought into programming and powering both motors, one just more then the other will help with this problem.
     
    Basic Zig-Zag Code

    %Zig-Zag Code
    %2/10/10
    %PinA is connected to the enable Pin on the driver for the right side motor
    %PinB is connected to the enable Pin on the driver for the left side motor
    %ATD1 is the port connected to the IR sensor(reads 1 for Black and 0 for
    % White)
    %In this program the robot will be following a White line. If you are
    %following a Black line the inputs for the IF loops will be swapped
    %Start centered on the line
    ATD1 = 0;
    %
    %Start off scanning for edge to the left
    PinA = 1;
    %Right_wheel means the right wheel is spinning,
    Right_wheel = 1;
    %
    %The percentage of your PWM will be based off of the gearing of your motor
    %and the width of the line. I am using a PWM% of 50% just to show the
    %concept
    %Continuous loop
    while(1);
    %
    %Sensor reads Black(Not on the Line)
    if (ATD1 == 1)
    %Figures out which direction it is currently moving
    if(Right_wheel == 1)
    %Changing direction by changing which motor is running
    Right_wheel = 0;
    PinB = 1;
    PinA = 0;
    else
    %Changing direction by changing which motor is running
    Right_wheel = 1;
    PinA = 1;
    PinB = 0;
    end
    end
    end

    Two Sensors

    The Zig-Zag method using two sensors becomes more efficient then using one sensor. There are two ways of setting the sensors on the robot. Depending on the width of the line and personal preference the robots sensors can be set up to straddle the line or can be set up to stay with-in the line's width. Both of these configurations makes the response of the robot faster at detecting the edge then the single sensor robot. The robot will Zig-Zag faster back and forth but will have a more true heading. Using two sensors makes the over shoot problem a little easier to handle. If over shoot happens it is possible one of the sensors is seeing the line and could straighten the robot out based off of the general Zig-Zag coding.

    PID Control Method

    Array of Sensors

    In many applications an array of sensors is used. By using the array of sensors the robot can have a better understanding of where it is on the line and will be able to correct its trajectory a little more accurately. The figure below is a simple diagram of an array of sensors that could be used on a line following robot. It has four sensors on the right (R1-R4) and four on the left (L1-L4). As seen in the above explanations these can be 0's or 1's depending on the color of the line you are following.

    The figure below shows what the controller would see if the robot was centered on the line. When your robot is seeing this you will want your robot to supply both motors with an equal amout of power.

    The Diagram below shows the robot trailing slightly to the right of the line. In this case the controller will want to power the right wheel slightly more then the left wheel to correct the trajectory of the robot back to centered on the line. If you are using a PID type of controller the error signal would be proportional to the magnitude the robot was off of center. In this case the robot is not far from center so the error would small.

    In the following figure you can see the robot is drifting further to the right. In this case the PID error signal would be greater then the above example. There for supplying a greater amount of power to the right wheel.

    When using an array of sensors the most common controller used is a PID controller. Most configurations using arrays will wire the signals into one whole eight pin ATD PORT on a micro-controller. By using the whole port the controller can read an 8 bit number from the sensors. By calibrating the sensors centered on the line to be followed, the controller can take that reading as "I'm on course". The PID control in the programming will try to keep the robot at the "I'm on course" reading by smoothly and constantly adjusting the right and left wheel speed. To learn more about PID Controlling please see PID Controller

    Bibliography

    http://www.ikalogic.com/ir_prox_sensors.php [1]
    http://www.trossenrobotics.com/p/single-line-following-sensor.aspx [2]
    http://www.trossenrobotics.com/p/I2C-Line-Following-Sensor.aspx [3]
    http://focus.ti.com/lit/ds/symlink/l293.pdf [4]
    http://www.kronosrobotics.com/application.shtml [5]

    Three phase latching relay programming for PIC Microcontroller 16f873A

    During on condition i need to check the continuity of relay contacts. For that i gave +5v supply to the relay contacts output of this contact is given to microcontroller 25th pin. If the relay contact is working, I will increase the relay test count and this count should written into the EEPROM.I f relay contact is not working microcontroller should wait until the contact works.


    TEST BSF PORTB,2 ;Set Turn off Relay
    CALL DELAY
    BCF PORTB,2 ;Clear Turn off Rly
    CALL DELAY
    CALL DELAY
    CALL DELAY
    CLRF PORTB
    BSF PORTB,1 ;Set Turn on Rly
    CALL DELAY
    BCF PORTB,1 ;Clear Turn on Rly
    CALL DELAY
    CALL DELAY
    CALL DELAY
    MOVF PORTB,W
    MOVWF CTAT_STATUS
    BTFSS CTAT_STATUS,4
    GOTO $-3
    MOVLW 01H
    MOVWF DATA_EE_ADDR
    CALL READ
    MOVWF DATA_TCNTL
    MOVLW 00H
    MOVWF DATA_EE_ADDR
    CALL READ
    MOVWF DATA_TCNTH
    INCFSZ DATA_TCNTL,1
    GOTO STORE
    INCFSZ DATA_TCNTH,1
    GOTO STORE
    STORE MOVF DATA_TCNTL,W
    MOVWF DATA_EE_DATA
    MOVLW 01H
    MOVWF DATA_EE_ADDR
    CALL WRITE
    MOVF DATA_TCNTH,W
    MOVWF DATA_EE_DATA
    MOVLW 00H
    MOVWF DATA_EE_ADDR
    CALL WRITE
    GOTO TEST


    If the code do not work on the application then follow the instructions connect ground to relay contact and check for 0 in program also have a pull up for Microcontroller pin for current program go for pull down resistor that should solve your problem.

    Extend PIC Microcontroller‘s RAM

    Virtually all PIC microcontrollers have some banking mechanism to extend addressing to additional memory space. But this external data memory is not directly addressable (except in some high versions of PIC18 devices, which include PIC18F8520, PIC18F6620, etc.). In this post we describe easy to implement external memory interface for PIC microcontrollers. Theoretically most of the PIC microcontrollers can use this setup to extend its RAM space. At the prototyping stage we test this system with PIC16F877, PIC16F887, PIC18F4550 and PIC18F4620 microcontrollers.

    Schematic

    Sample Schematic for Extended RAM system
    With this given schematic user may be able to address RAM space up to 192KB. But this can be extended up to 448KB by adding more SRAM modules to the system.
    In this given setup we use 24512 – 64K x 8 CMOS SRAMs as a memory modules. 74HC373 latch is used as 8bit to 16bit address extender and 74HC138 demultiplexer is used as memory bank selector.

    Function to write data to the external memory bank

    //==============================================================================
    // Function to write data to the external memory bank
    // Input parameters:
    //   bank: Memory band number. Valid range is between 1 to 7. 0 for no bank.
    //   address: Memory address to write.
    //   value: Value to write
    // Return:
    //   none
    //==============================================================================
    void WriteExMem(char bank, unsigned int address, char value) {
      asm {
        clrf TRISD
        clrf TRISB
        movlw 0xe0
        andwf TRISC, 1
        movlw 0xc3
        andwf PORTC, 1
        nop
        nop
        movf FARG_WriteExMem_address+1, 0
        movwf PORTD
        movlw 0xfd
        andwf PORTC, 1
        nop
        nop
        bsf PORTC, 1
        movf FARG_WriteExMem_address, 0
        movwf PORTD
        movf FARG_WriteExMem_value, 0
        movwf PORTB
        nop
        nop
        movlw 0xfe
        andwf PORTC, 1
        movf FARG_WriteExMem_bank, 0
        movwf R0
        rlcf R0, 1
        bcf R0, 0
        rlcf R0, 1
        bcf R0, 0
        movf R0, 0
        iorwf PORTC, 1
        nop
        nop
        bsf PORTC, 0
        movlw 0xe3
        andwf PORTC, 1
      }
    }

    Function to read data from external memory bank


    //==============================================================================
    // Function to read data from external memory bank
    // Input parameters:
    //   bank: Memory band number. Valid range is between 1 to 7. 0 for no bank.
    //   address: Memory address to read.
    // Return:
    //   Data value
    //==============================================================================
    char ReadExMem(char bank, unsigned int address) {
      asm {
        clrf TRISD
        movlw 0xff
        movwf TRISB
        movlw 0xe0
        andwf TRISC, 1
        movlw 0xc3
        andwf PORTC, 1
        nop
        nop
        movf FARG_ReadExMem_address+1, 0
        movwf PORTD
        movlw 0xfd
        andwf PORTC, 1
        nop
        nop
        bsf PORTC, 1
        movf FARG_ReadExMem_address, 0
        movwf PORTD
        movf FARG_ReadExMem_bank, 0
        movwf R0
        rlcf R0, 1
        bcf R0, 0
        rlcf R0, 1
        bcf R0, 0
        movf R0, 0
        iorwf PORTC, 1
        nop
        nop
        movf PORTB, 0
        movwf R1
        movlw 0xe3
        andwf PORTC, 1
        movf R1, 0
        movwf R0
      }
    }

    Sample Code to test SRAM system


    void main() {
      unsigned int address_;
      char bank = 1;
      char txt_buffer[20];
     
      ADCON1 = 15;
      ADCON0 = 0;
      SSPCON1 = 0;
      CCP1CON = 0;
     
      UART1_Init(4800);
      Delay_ms(100);
      UART_Write_Text("Start Testing...\n");
     
      while(bank < 4)
      {
        sprintf(txt_buffer, "Testing bank %c\n", (bank+48));
        UART_Write_Text(txt_buffer);
        for(address_ = 0; address_ < 65535; address_++)
          WriteExMem(bank, address_, 170);           //170 is a magic number to test
        for(address_ = 0; address_ < 65535; address_++)
          if(ReadExMem(bank, address_)!=170)
          {
            UART_Write_Text(" Test FAIL ");
            sprintf(txt_buffer, "address: %u\n", address_);
            UART_Write_Text(txt_buffer);
            bank = 5;
            break;
          }
        if(bank < 5)
          UART_Write_Text(" Test PASS \n");
        bank++;
      }
      UART_Write_Text("SRAM test completed\n");
      while(1);
     
    }

    The above listed source code is compatible with MikroC Pro for PIC compiler and it can use with other compilers with some slight modifications.

    12/06/2015

    Getting Started With Proteus ISIS

    In this tutorial, we will learn how to use Proteus isis. In this tutorial we will not design circuit.  Instead, we will see the different funtions of Proteus ISIS.

    When you make code such as writing on the LCD then its quite difficult to burn it out again and again. Instead, we design circuit on Proteus and check code. Protus is quite handy and easy.

    At this time, i suppose you have installed Proteus ISIS on your PC. If you did not do it then click on the following link and install it.

    http://microcontrollr.blogspot.com/2015/12/pic-microcontroller-1.html

     Click on Proteus ISIS icon and it will be appear as shown below.



    I have divided The Proteus in different section. Section 1 is for toolbar. The first icon is for create layout, 2nd is to open existing layout, 3rd for zooming. Area icon is for design PCB layout.

    Sec 2 has two button, one is P and other is E. P is use for operating the part list and E is used for editing the component property.

    Sec 3 has alot of functions, its mostly used section of Proteus. we will look easc in our next tutorial.

    Sec 4 is used to play, pause and stop the Proteus simulation.

    Now, we will see the use of each option. First discuss about sec 2. After pressing at P the following window will appear.


    This is the window of component searching. I have searched 18F452 and Proteus automatically show me that component as shown in figure. It is also show its preview and PCB preview. If you are sure that you have chose right component then double click on it or press on OK.

    AS shown below, i have searched the component and made a simple circuit.


     In this circuit, i used DC supply and ground, which i chose from sec 3 as shown below.



                                  Previous <<         >> Next




    Interfacing LCD With Arduino Microcontroller

    In this tutorial we are going to  interface a  Liquid Crystal Display (LCD)  with Arduino Microcontroller .  Liquid Crystal Display are us...