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

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/15/2015

    Communication Between Microcontroller

    The main purpose of communication is to transfer information from source to destination. Communication between Microcontroller have two ways to transmit data on line.

    1-Serial Transmission
    2-Parallel Transmission
      
    Serial Transmission 

    When using the Serial Transmission, we transmit only one bit at a time. It simply means there is only one transmission line through which the bit is transmitted.
    Serial communication
      
    Parallel Transmission 
     
    When using the Parallel Transmission, we transmit an entire byte of data at a time. Hence we need 8 lines for transfer 8-bit data.
    Parallel communication

    In order to understand the Serial communication and the difference between these two. Let's take a look at the following Proteus example.

     >> First Open Proteus ISIS
    >> Press on P for choosing component.
    >> Search COMPIM
    >> In virtual instrument mode select virtual terminal as show below.


    >> Make connection as shown below.

     
     >>  Now double click on the COMPIM and set the properties as shown below.

     >> Here , i have selected COM1 and my baud rate is 9600.
    >> Similarly open the property of the virtual terminal and set the baud rate is 9600.
    >> Now run the simulation.

    >> By pressing any key from your keyboard, you will see the TXD pin will be high, which indicate that one bit is transfor as shown below.

    In the next tutorial we will see parallel transmission.

      

                                 Previous <<             >>Next

    12/13/2015

    Interfacing LCD with PIC 16F877A Microcontroller

    In this tutorial we will see how to interface LCD 16x2 with PIC 16F877A. It is an inevitable part used in all embedded  project. If you will learn it properly then you can easily design embedded project. LCD 16x2 display 2 lines with 16 characters. It can display all the letters, alphabet, mathematical symbols, Greek alphabet etc.  

    Related post >> Blinking LED using PIC Microcontroller


    Circuit Diagram 

    VSS   --> This pin must be connected to the ground.
    VDD --> This is positive supply (5v) voltage pin.
    VEE --> Contrast adjustment pin
    RS   --> Register selection
    E     --> Enable
    R/W -->  Read/write
    D7,D6,D5,D4 --> Data pin




    LCD may be connected to the PIC using either 4-bit or 8-bit. Here we are using 4-bit configuration. If an 8-bit bus is used then the remaining pin D1,D2,D3,D4 will be connect with the PIC PORD.D pin

    Program:

    Device 16F877A
    XTAL 20  
    ALL_DIGITAL TRUE
    Declare LCD_DTPIN PORTD.4
    Declare LCD_RSPIN PORTD.2
    Declare LCD_ENPIN PORTD.3
    Declare LCD_INTERFACE 4
    Declare lcd_line 2
    Declare LCD_TYPE 0 
    Output PORTD
    initial:
    Cls
    Print At 1, 1," Hello World " '
    DelayMS 100
    GoTo initial
    ----------------------------------------------------------------------------
     Declare LCD_DTPIN PORTD.4 --> It is uesd for 4 line interface. If we used 8 line interface then we will write 'Declare LCD_DTPIN PORTD.0' 

    Declare LCD_RSPIN PORTD.2 --> It tells the compiler that the LCD's RS line will attach to PORTD.2 

    Declare LCD_ENPIN PORTD.3--> It tells the compiler that LCD's enable pin will attach to PORTD.3 

    Declare LCD_INTERFACE 4  -->Inform the compiler that it is 4 line interface. For 8-line we will write 'Declare LCD_INTERFACE 8. 

    Declare lcd_line 2 --> Inform the compiler that the LCD's have 2 line.

    Declare LCD_TYPE 0 --> Imform the compiler that it is alpha type LCD.
    The remaining command we have discussed in our previous tutorial.

    Diagram Of Final Output

                        Previous<<       >>Next

                                                       

    12/07/2015

    Blinking LED using PIC Microcontroller

    In this tutorial, we will learn, how to burn program in PIC Microcontroller. and we will also see how to use Proton IDE. If you still did not install Proton IDE and Proteus then click the following link and install it.

    How to install Proton IDE and Proteus.

    If anyone having any problem at any point, ask me in comment. I will try my best to resolve it. 
    First of all, open the Proteus ISIS and Proton IDE software. It will look the same as below image.


    At this point, i supposed you have learnt my previous tutorial, getting stard with Proteus ISIS.

    >> Open the Proton IDE.
    >> write program for blinking LED.
    >> Copy the below code and past it in Proton IDE.



    - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  - - -

     ' LED BLINKING CODE

     Device 18F452  ' Tell the compiler about device

     XTAL 20            ' Crystal Frequency

     ALL_DIGITAL TRUE   ' For digital input

     Input PORTB.0      ' Initialize portb.0 as input

     Output PORTD.0     ' Initialize portd.0 as output

     PORTB.0=0          ' set portb.0 as low

     PORTD.0=0          ' Set portd.0 As Low

     initial:             ' for looping

     If PORTB.0==1 Then    'condition

     High PORTD.0

     Else

     Low PORTD.0

     EndIf                  ' for ending if

     GoTo initial           ' For continue loop

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - 



    After pasting, compile the program by clicking at the compile, showing below.



    Now, it will ask the address, where do you want to save the program. After saving, it will automatically create all related files, including HEX file.



     >> Now, put hex file in the Proteus ISIS.
    >> Design exactly the same circuit as shown below.



    >> Now, double click at the PIC 18F452.
    >> Put HEX file as shown below.



     >> After adding the hex file, now click at the play button.




    Now, simulation will run. You will get result as shown below.



    That is all for today. In the next tutorial, we will learn about different component, which are commenly used like LCD interfarence, serial communication, motor, CCP etc. So stay tuned and subscribe via email and also like us on facebook. If someone having problemn ask me in comment. I will try my best to explain it. 



                                Previous <<             >>Next

     

    12/05/2015

    How to install proton ide

    How To Install Proton IDE


    The sofware, which we will use to program PIC, is proton ide. Proton IDE is a professional and powerful visual Integrated Development Environment (IDE). It is easy to use. You can download this software by click the following link.

                  Click here to download Proton IDE

    After click the above link the following window will appear.


    Then press at the download. After pressing at the download the following window will appear.

     Press at the download anyway. Now one zipfile will appear on your screen press at the ok.

    After installing, extract zip file as shown below.

     
    Now one icon, look like below will appear, double click it



    Now after pressing ok and next, next the proton ide will be install on your PC.




                       Previous  <<         >> Next


    Introduction To PIC Microcontroller

    Introduction

    Welcome to the start of the tutorial. These tutorial will teach you from the beginning of PIC Microcontroller. I will not include any internal architecture diagrams because this may only lead to confusion.

    To start, let's take a look at the data sheet of PIC 18F452 .


    The 18F452 has  1536B of RAM and 16k of program memory. It has four port namely as porta, portb, portc and portd. Each port has eight pins. As shown in figure the pin num RA belongs to porta and same as for RB, RC and RD.

    VSS and VDD

    These are the power supply pins. VSS is ground and VDD is the positive supply pin. The range of supply is 5V to 3V. The maximum supply is 5V and minimum is 3V. (above 5V the IC can damage so be carefull).

    OSC0/CLK0 and OSC1/CLK1

    Since microcontroller has some kind of timing, so we connect an external clock with these pins.

    MCLR

    In normal mode this pin connect to the positive (5V) supply. Specially, this pin is used to erase the memory location.

    (RA0 to RA7) to (RD0 to RD7)

    These are the bidirectional ports. That can be configured as an input and output. The number following RA0, RA1 is the bit number.

    INT1 and INT2

    These is an another clock, which operate an internal timer.

    HOW TO PROGRAM PIC

    There are two ways for programming, the easy and DIY way. The easy way is to buy a PIC burner, which will connect to your PC and you can program it by using software. The DIY is to build your own burner and use free software to program it.

    In these tutorial, first we will learn the programming of PIC and will see the simulation by using Proteus. Then we will proceed to the harware.


                     

                                           Click here to 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...