Tuesday, October 29, 2013

Tutorial 4 PIC Microcontroller

All the questions asked below are related to the Applications of PIC16F877A.

1. What is meant by SWITCH (CONTACT) DEBOUNCE?

 Solution


Button function is simple. When we push a button, two contacts are joined together and connection is made. Still, it isn't all that simple. The problem lies in the nature of voltage as an electrical dimension, and in the imperfection of mechanical contacts. That is to say, before contact is made or cut off, there is a short time period when vibration (oscillation) can occur as a result of unevenness of mechanical contacts, or as a result of the different speed in pushing a button (this depends on person who pushes the button). The term given to this phenomena is called SWITCH (CONTACT) DEBOUNCE.


2. How to overcome SWITCH (CONTACT) DEBOUNCE problem by applying the well-designed program?

Solution
In order to avoid this problem, we can introduce a small delay when we detect the closing of a contact. This will ensure that the push of a button is interpreted as a single pulse. The debounce delay is produced in software and the length of the delay depends on the button, and the purpose of the button.


3. Give four examples of analog sensors and suggest which ports of PIC 16F877A  can be directly used to input the signal from the analog sensor.

Solution
Examples of analog sensors are Microphone, analog infrared distance sensor, analog compass and barometer sensor.
Port A and Port E  (pin 0,1 &2) can be used to input these analog input because it has built in A/D converter. If PortB, C and D are used to input analog signal, and external A/D converter will be needed.

4. List down the steps should be followed for doing and A/D conversion

Solution
1. Configure the A/D module:
• Configure analog pins / voltage reference /and digital I/O (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D conversion clock (ADCON0)
• Turn on A/D module (ADCON0)

2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• Set GIE bit
3. Wait the required acquisition time.

4. Start conversion:
• Set GO/DONE bit (ADCON0)

5. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
OR
• Waiting for the A/D interrupt

6. Read A/D Result register pair (ADRESH:ADRESL), clear bit ADIF if required.

7. For next conversion, go to step 1 or step 2 as required. The A/D conversion time per bit is defined as TAD. A minimum wait of 2TAD is required before next acquisition starts.


5. If the microcontroller can not work, what are the steps to troubleshoot it?

 Solution
For software part, try to simulate with the MPLAB and Virtual breadboard.

When load program to microcontroller, if the source code is in Hex file, make sure “Intel Hex” is selected.     

For 16F877A
Make sure pin 11 and pin 32 are connected to 5V, pin 12 and pin 31 are connected to ground.

Make sure pin 13 and 14 are connected with correct frequency oscillator (20MHz) and check the these pins with oscilloscope, 20MHz sinusoidal wave should be observed.

If still can not function, use the functional new microcontroller to try again, or try the suspected not working microcontroller in other functional board.

6. If you are required to design a temperature sensor using 16F877A, which will trigger an alarm when the temperature is over 400C.Describe how are you going to design it by applying the features available in 16F877A and show all the calculation involved. State all the assumptions make.

Solution
Use port A pin0 to input voltage from the sensor and convert from analogue to binary (or digital value).After that, compare the digital value with equivalent digital value of 40oC, if it is greater than 40oC, trigger set port B pin 1 to high to trigger the driver of alarm connected to it.

Let assume that when temperature sensor sense 40oC, it will give 2.4V to the PIC. After A/D, if the voltage value will be saved as 10-bit number.
;5V = 1023, thus 1023/5= 205/1V
;if 40oC give 2.4V, which is equal to 2.4x205 = 492.

If the input digital value is exceeds 492 (40oC), the alarm will be triggered through port B pin1.

Assumption, VDD = 5V, Vss = 0V.

7. For serial communication between PIC and PC, why Max232 is needed in between?

Solution
In order to connect a microcontroller to a serial port on a PC computer, we need to adjust the level of the signals so communicating can take place. The signal level on a PC is -10V for logic zero, and +10V for logic one. Since the signal level on the microcontroller is +5V for logic one, and 0V for logic zero, we need an intermediary stage that will convert the levels. One chip specially designed for this task is MAX232. This chip receives signals from -10 to +10V and converts them into 0 and 5V.
     8. What are the applications of master synchronous serial port (MSSP) module   available in 16F877?
The Master Synchronous Serial Port (MSSP) module is a serial interface, useful for communicating with other peripheral or microcontroller devices. These peripheral devices may be serial EEPROMs, shift registers, display drivers, A/D converters, etc. The MSSP module
can operate in one of two modes:
• Serial Peripheral Interface (SPI)
• Inter-Integrated Circuit (I2C)

9. What are the applications of the Universal Synchronous Asynchronous Receiver Transmitter (USART)module available in 16F877?
Solution
The Universal Synchronous Asynchronous Receiver Transmitter (USART) module is one of the two serial I/O modules. (USART is also known as a Serial Communications Interface or SCI.) The USART can be configured as a full duplex asynchronous system that can communicate with peripheral devices such as CRT terminals and personal computers, or it can be configured as a half duplex synchronous system that can communicate with peripheral devices such as A/D or D/A integrated circuits, serial EEPROMs etc.

10. What are the four important elements in USART Asynchronous module?
Solution
·         Baud Rate Generator
·         Sampling Circuit
·         Asynchronous Transmitter
·         Asynchronous Receiver

11. List down the steps should be followed when setting up an Asynchronous Reception

Solution
When setting up an Asynchronous Reception, follow these steps:
1. Initialize the SPBRG register for the appropriate baud rate. If a high speed baud rate is desired,set bit BRGH (Section 10.1).
2. Enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
3. If interrupts are desired, then set enable bit RCIE.
4. If 9-bit reception is desired, then set bit RX9.
5. Enable the reception by setting bit CREN.
6. Flag bit RCIF will be set when reception is complete and an interrupt will be generated if enable
bit RCIE is set.
7. Read the RCSTA register to get the ninth bit (if enabled) and determine if any error occurred
during reception.
8. Read the 8-bit received data by reading the RCREG register.
9. If any error occurred, clear the error by clearing enable bit CREN.
10. If using interrupts, ensure that GIE and PEIE (bits 7 and 6) of the INTCON register are set.




No comments:

Post a Comment