KPIT Walkin interview | Chennai 22nd April 2017 | 3 - 9 Work Experience

Share it as Fast

Company Name
KPIT
Interview Type
Walk In
Job Title
 Embedded C Developer.
 Model Based Development,
 Project Lead and Project Manager,
 Verification and validation Testing
 Autosar
Work Experience
3 – 9 Years
Date
22nd April 2017
Job Location
Banglore/Pune
Interview Venue
KPIT Technologies Ltd.,
SKCL Trition Square,
6th Floor, C3 to C7,
Thiru-Vi-Ka Industrial Estate,
Guindy, Chennai 600032
Interview Time
9AM – 4PM
Salary
Not Disclosed

UART in PIC16F877A pic microcontroller with Proteus simulation

Before going to this tutorial you are recommended to see
1) GPIO Configuration in PIC16F877A
2) PIC16F877A Interrupt configuration

UART in PIC16F877A PIC microcontroller

Asynchronous communication can be configured in PIC16F877A with TXSTA(TRANSMIT STATUS AND CONTROL REGISTER) and RECEIVE STATUS AND CONTROL REGISTER(RCSTA). RC6 is a transmission pin and RC7 is a receive pin. in PIC16F877A. This RX needs to be connected to the receiver TX and viceversa for receiver.

TXSTA

We are going to configure Transmission as 8bit transmission(also no parity) (TX9 = 0). Enable transmission (TXEN = 0). Asynchronous transmission (SYNC = 0). Low speed mode (BRGH = 0).


RCSTA

Configure the receive control register as Enable Serial port (SPEN = 1). Enable continuous receive ( CREN = 1). 


UART Baudrate generation
Microcontroller is going to operate on 20MHz oscillator frequency, UART is configured in Low frequency mode. So that to achieve a common Baudrate of 9600 SPBRG value is given as 31.
Below is the other baudrate values.

UART Transmission working in PIC16F877A


UART Receiving Opearation in PIC16F877A
More detailed explanation for this block diagram is given in the datasheet

UART Transmit Diagram


UART Receive Diagram


Embedded C Program

#include <xc.h>
#include <pic16f877a.h>

void interrupt ISR()
{
    //If the received interrupt is because of
    //data received in UART
    if(PIR1bits.RCIF == 1)
    {
        //Clear the interrupt
        PIR1bits.RCIF = 0;
        TXREG = (RCREG + 1);
        while(TXSTAbits.TRMT == 0);
    }
}

void UART_Init()
{
    //Select 8bit transmission
    TXSTAbits.TX9 = 0;
    //Enable Transmit
    TXSTAbits.TXEN = 1;
    //Async mode select
    TXSTAbits.SYNC = 0;
    //Operate in Low Speed
    TXSTAbits.BRGH = 0;
 
    //Enable Serial Port
    RCSTAbits.SPEN = 1;
    //Enable continuous receive
    RCSTAbits.CREN = 1;
 
    //Baudrate 9600
    SPBRG = 31;
 
    //Enable global interrupt
    INTCONbits.GIE = 1;
    //Enable Peripheral interrupt
    INTCONbits.PEIE = 1;
 
    //Enable receive interrupt
    PIE1bits.RCIE = 1;
    //Clear the receive interrupt flag
    PIR1bits.RCIF = 0;
}

void main(void) {
    //Initialize UART
    UART_Init();
    //Loop forever
    while(1);
    return;
}

Here the UART is initialized first as a 8bit transmission with 9600(approx) baudrate, both transmit and receive is enabled. To receive the interrupt on every data received through RC7 receive pin, global interrupt, peripheral interrupt needs to be enabled. RCIE bit enables the actual uart rx(receive) interrupt.

In the Interrupt service routine RCIF flag bit is used to check, the interrupt is occured by receive interrupt. If so, clear the flag RCIF. RCREG register holds the received 8bit data.

For example, We are going to transmit the next ASCII value of the received value. TRMT bit is used to stop until the transmit completion. So that If the received data is 'A' Transmit data will be 'B' and so on.

Proteus Hardware Simulation Circuit


Virtual Terminal in Proteus is as below
Virtual Terminal Configuration

Proteus Simulation Output


What if Baudrate mismatch ?

When baudrate mismatch communication will not be proper as shown below.

TO DOWNLOAD THIS PROJECT

Video tutorial



Addon - What is loopback Test ?

Interrupts in PIC16F877A Pic microcontroller with Push button Example using Proteus

Before going to this tutorial, you are recommended to see

1) PIC16F877A GPIO configuration
2) Blinking LED
3) Multiple Blinking LED

What is Interrupt ?

Interrupts are used to interrupt the processor, to perform some other task. After completing the task, processor will continue it's previous task.

Interrupts in PIC16F877A Pic microcontroller

PIC16F877A has 15 interrupts which has one GPIO interrupt i.e., RB0/INT.

How to configure this GPIO as a interrupt ?

1) Configure the RB0 pin as a input
2) Enable the Global interrupt.(GIE)
3) Enable Peripheral interrupt.(PEIE)
4) Enable RB0 interrupt.(INTE)
5) Write the interrupt service routine using interrupt keyword before the function.

Hardware Proteus Circuit


Embedded C Program

#include <xc.h>
//interrupt service routine
void interrupt ISR() {
    //Check if the interrupt is because of
    //RBO GPIO pin
    if(INTCONbits.INTF == 1) {
        //Clear the interrupt
        INTCONbits.INTF = 0;
        //If the LED is on
        if(PORTBbits.RB1 == 1) {
            //turn off the LED
            PORTBbits.RB1 = 0;
        }
        //If the LED is off
        else {
            //turn on the LED
            PORTBbits.RB1 = 1;
        }
    }
}
void main() {
    //RB0 as a input
    TRISBbits.TRISB0 = 1;
    //RB1 as a output
    TRISBbits.TRISB1 = 0;
    //RB1 high so LED On
    PORTBbits.RB1 = 1;
    //Enable the Global interrupt
    INTCONbits.GIE = 1;
    //Peripheral Interrupt Enable
    INTCONbits.PEIE =1;
    //enable RB0 interrupt
    INTCONbits.INTE = 1;
    //Loop forever
    while(1);
    return;
}

Proteus Push button Output




Video Tutorial


TO DOWNLOAD THIS PROJECT CLICK HERE

Also See 

Push button Example using 8051

What is Background Debug Mode, and why do I want it?

BDM stands for `Background Debug Mode', and it is a special debug interface on some of Motorola's embedded 68K and Power PC processors. BDM allows an external debug system to control and monitor the operation of the embedded processor through a 10-pin proprietary serial interface, without any software support in the target system and without the use of an In-Circuit Emulator (ICE). 

Using a low-cost interface cable to your PC's printer port, and the right software on your PC, you can perform most of your debugging directly on your target hardware at very low cost.

Multiple Blinking LED using PIC16F877A with Proteus Simulation

Recommended To Know before you go to this tutorial

1. How to configure PIC16F77A as a GPIO
2. Simple Blinking LED tutorial with PIC16F77A

Multiple Blinking LED Tutorial

In this tutorial Blue, Green, Red, Yellow these 4 LEDs are turned on and off with some delay. It is one of the application of GPIO configuration.

Embedded C Program

#include <xc.h>
void main(void) {
    //PORTA pin 0 as output
    //Direction register configuration
    TRISA = 0;
    //Initialize the variable
    //used for the delay
    int i = 0;
    //loop for ever
    while(1)
    {
       //LED 4 OFF
       RA3 = 0;      
       //LED 1 ON
       RA0 = 1;
       //Delay function
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       //LED 1 OFF
       RA0 = 0;
       //LED 2 ON
       RA1 = 1;
       //Delay
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       //LED 2 OFF
       RA1 = 0;      
       //LED 3 ON
       RA2 = 1;
       //Delay function
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);

       //LED 3 OFF
       RA2 = 0;
       //LED 4 ON
       RA3 = 1;
       //Delay
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);
       for(i = 1; i< 6000; i++);

    }
    return;
}

Proteus Hardware simulation Circuit


Proteus Simulation Output





Here, All the LED's are turned on and off one by one with some delay.

Video Tutorial


Also See Multiple Bliking LED for 8051

What is the processor support provided for debugging ? Explain JTAG/BDM ?

A standard specifying how to control and monitor the pins of compliant devices on a printed circuit board. Each device has four JTAG control lines. There is a common reset (TRST) and clock (TCLK). The data line daisy chains one device's TDO pin to the TDI pins on the next device.  The protocol contains commands to read and set the values of the pins (and, optionally internal registers) of devices. 

This is called "boundary scanning". The protocol makes board testing easier as signals that are not visible at the board connector may be read and set. The protocol also allows the testing of equipment, connected to the JTAG port, to identify components on the board (by reading the device identification register) and to control and monitor the device's outputs. JTAG is not used during normal operation of a board.

What is meant by downloading the build to target ?

Refers to the transfer of executable code from a host to a target, typically using an RS-232 serial line. The target must have resident software (e.g., EPROM) that can read the incoming data, translate it if necessary (the file format may be ASCII hex for example) and load and run the code. 

If the target board has no resident software, then an ICE is required. The ICE connects to the host via RS-232 typically and accepts the download and loads the code into memory.

Blinking LED using PIC microcontroller PIC16F877A and Proteus simulation

Before Going to this PIC16F877A LED blinking tutorial, we are recommending you to see how to configure a pin in PIC microcontroller PIC16F877A as input or outtput. From the link below

Click Here

If you have learned how to configure the PIN as a output using TRIS directio register. You can go forward to use it in a application. i.e., Blinking LED using PIC16F877A pic microcontroller.

PICF16F877A Blinking LED Circuit (Proteus)


In this circuit Oscillator frequency is used as 8MHz. and a RA0 is connected to the LED through a 400 ohm resistor.

Embedded C Program

#include <xc.h>
void main(void) {
    //PORTA pin 0 as output
    TRISA0 = 0;
    //Initialize the variable
    int i = 0;
    //loop for ever
    while(1)
    {
       //LED ON
       RA0 = 1;
       //Delay
       for(i = 1; i< 6000; i++);
       //LED OFF
       RA0 = 0;
       //Delay
       for(i = 1; i< 6000; i++);    
    }
    return;
}

PIC16F877A blinking LED Proteus Output



Whenever the RA0 is high LED will blink, and when it is low it will not blink. A small delay is given to visually see the led blink in a real world.

Blinking LED using PIC16F877A PIC microcontroller video tutorial


To Download this Project Click here

Blinking LED for 8051

Configure GPIO in PIC16F877A example with PROTEUS simulation

Before going to the GPIO configuration we strongly recommend to see how to create a project in MPLAB X ide from the link below

GPIO in PIC16F87XA

GPIO in PIC16F877A is divided into 5 ports that is PORTA, PORTB, PORTC, PORTD, PORTE. We can configure a GPIO pin as a input or output. In all the microcontroller that can be set with the direction register.
Incase of PIC16F877A we can use a direction register TRIS. For every port there will be one TRIS direction register port. Consider the PORTA, which has TRISA. The address is given below.

What is the use of TRIS ❓

As given above TRISA, TRISB, TRISC, TRISC, TRISD, TRISE is used as direction register. So that writing into this register will configure the particular GPIO port as a input or output.

How to configure input and output with TRIS ❓

For this we need to refer the datasheet of the PIC16F877A. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input (i.e., put the corresponding output driver in a High-Impedance mode). Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the selected pin). This is common for other ports also.

Reading the PORTA register reads the status of the pins, whereas writing to it will write to the port latch. All write operations are read-modify-write operations. Therefore, a write to a port implies that the port pins are read, the value is modified and then written to the port data latch.

Example program to  cofigure the RA0 in PORTA bit 0 pin as output

#include <xc.h>
void main(void) {
    TRISA0 = 0;
    int i = 0;
    while(1)
    {
       RA0 = 1;
       for(i = 1; i< 6000; i++);
       RA0 = 0;
       for(i = 1; i< 6000; i++);      
    }
    return;
}

Proteus circuit for the above program


Proteus Simulation output


Find the video tutorial which explains how to configure the GPIOs in PIC16F877A with Proteus simulation


Recommended to see the usage of GPIO configuration blinking LED


How to create a project using MPLAB IDE

Before going to this tutorial, Have you installed the MPLAB X ide and XC8 compile. Then click the link below to download and install it 😊.


How to create a project using MPLAB IDE

1. File -> New Project
2. Select Standalone project. (If you wish to select others click that option also you can see the description below)
3. Select the family or directly enter the name of the device.
4. Select the debugger you want to use. (Mostly preferred is ICD3)
5. Select the compiler
6. Give the name of the project
7. Finish to create the project


Create a .c file for the project

1. Select source files
2. Right click and select New -> main.c
3. Give a name for the .c file
4. Save it.

Generate Hex file

1. Modify the code as required
2. Click Build or clean and build.
3. In Output window build successful will come if the compilation is passed.
4. Also it will give the path of the generated hex file.

See the video tutorial below




PIC Microcontroller PIC16F877A Datasheet PDF free download

PIC Microcontroller PIC16F877A Datasheet free download


Click the link to download the PIC microcontroller 

Download Install Setup MPLAB IDE and Compiler for FREE

1. Download the MPLab IDE and Compiler by clicking the link below for free

Click here to download the MPLAB

2. Extract the downloaded file in one folder

3. First install the MPLAB IDE (MPLABX-v3.55-windows-installer)

4. Then install the 8 bit compiler (xc8-v1.41-full-install-windows-installer)

5. After installation open the MPLAB ide from the path
"C:\Program Files (x86)\Microchip\MPLABX\v3.55\mplab_ide\bin\mplab_ide.exe"



That's it, you are set up to program and compile for PIC controller.

Watch the video tutorial below



What is an In Circuit Debugger ?

ICE is an electronic tool that allows for debugging beyond the capabilities of a standard software debugger. An ICE is essentially a hardware box with a 2 to 3 foot cable attached to it. At the end of the cable is a multi-pin connector connected to a CPU processor chip, which is identical to the processor on the target board. The target processor is removed from your target board, and the connector plugged in. 

The ICE allows for trapping the following types of activities: read/write to an address range, read/write a specific value from an address range, setting a breakpoint in EPROM, mapping emulator memory to target board memory, and other similar features. It also turns the host (a PC for example) into a debug station with supplied software. This allows for debugging of the target board even though the target does not have a keyboard, screen, or disk.

What is a break point ?

A point in a program that, when reached, triggers some special behavior useful to the process of debugging; generally, breakpoints are used to either pause program execution, and/or dump the values of some or all of the program variables. 

Breakpoints may be part of the program itself; or the programmer as part of an interactive session may set them with a debugging tool for scrutinizing the program's execution.

Difference between memory mapped IO and mapped IO

Use of the same instructions and bus to communicate with both main memory and input/output devices. This is in contrast to processors that have a separate I/O bus and special instructions to access it. 

The I/O devices are addressed at certain reserved address ranges on the main memory bus. These addresses cannot therefore be used for RAM. Motorola and Mostec architectures, among others, use memory mapped I/O.

What is a monitor program ?

A monitor is a program installed in the micro controller, which provides basic development and debug capabilities. Typical capabilities of a micro controller monitor include: loading object files into system RAM, executing programs, examining and modifying memory and registers, code disassembly, setting breakpoints, and single-stepping through code. 

Some simple monitors only allow basic functions such as memory inspection, and the more sophisticated monitors are capable of a full range of debug functions. Monitors can either communicate with a dumb terminal or with a host computer such as a PC. Much of the work of the monitor (such as user interface) can be offloaded to the host PC running a program designed to work with the monitor. This makes it possible to reduce the size and complexity of the code that must be installed in the target system.

How would you download a code to the target ?

The code is normally downloaded by either of two ways, flashing, or auto down loading. In the flashing mode, Hex file is used as input, and the 3rd party software tool is normally used to Download the hex file. There will be provision to select the start address and end address, where the load has to put. Once this is all done, there will be provision to flash this load to the EEPROM using a BDM connector. All the software does, is read the address and data and starts storing that in the EEPROM.

Some time Bootloader if present the application software can be loaded using the bootloader, there the Bootloader expects the application software in a specific format, such as header, checksum, CRC, placed in appropriate place. Then when the loading starts the bootloader will takes the load from floppy and dump in the EEPROM. Here compatibility test will be performed, if the CRC is not matching, the loading will be discarded, by the bootloader.

What is a Compiler and Linker ?

Compiler is a program that converts another program from some source language (or programming language) to machine language (object code). Some compilers output assembly language, which is then converted to machine language by a separate assembler. 

A compiler is distinguished from an assembler by the fact that each input statement does not, in general, correspond to a single machine instruction or fixed sequence of instructions. A compiler may support such features as automatic allocation of variables, arbitrary arithmetic expressions, control structures such as FOR and WHILE loops, variable scope, input/output operations, higher-order functions and portability of source code. 

Linker is a program that combines one or more files containing object code from separately compiled program modules into a single file containing loadable or executable code This process involves resolving references between the modules and fixing the relocation information used by the operating system kernel when loading the file into memory to run it.

What is Just In Time (JIT) Compiler ?

What is Just In Time (JIT) Compiler ?

JIT means Just in Time compiler this technique was pioneered by the commercial Smalltalk implementation currently known as Visual Works, in the early 1980s. Currently it is also used by some implementations of the Java Virtual Machine under the name JIT (Just In Time compilation). A virtual machine implementation approach, used to speed up execution of byte-code programs. To execute a program unit such as a method or a function, the virtual machine compiles its byte codes into (hardware) machine code. The translated code is also placed in a cache, so that next time that unit's machine code can be executed immediately, without repeating the translation.

Line Following | Obstacle avoiding | Light Following | Anti Falling Robot using Arduino

The following video contains the output of line following, obstacle avoiding, light following and anti falling robot. All of these robots are made up of arduino uno. The code for all of the robots will be available soon. Click below for the program for all the robots.

See the fastest line following robot here

Video


How are Logic Analyzers used for troubleshooting ?

Logic analyzers (LAS) are normally used for trouble shooting the hardware under development. It is also used to validate the timing performance of the system. A logic analyzer has a set of pod to which a flat cable is connected. These pods are address, data and control pods. There hardware under test shall have provision to insert the other end of the logic analyzer probe; under respective pods namely data, address, and control.

Usually LAS is an intelligent system where in you can select set the triggers using the scripts that is available within the LAS. Once the trigger occur the data is captured in the buffer in the LAS, which can be latter printed, or stored or analyzed.

What is BIT (Built-in-Test) ?

BIT (Built-in-Test) is a periodic diagnostic software is built in your software which helps to detects failure on the ` hardware interfaces that with the system.