Sie sind auf Seite 1von 5

PIC 18F4520 Microprocessor

Application Note Kyle Proctor ECE 480 Design Team 10 Executive Summary Microprocessors are used to receive perform a wide variety of tasks such as receive, analyze and output data and perform calculations. In short they are an entire computer in one chip. They allow for wide range of applications at a fairly low cost. This application note examines one microprocessor for use in analyzing multiple inputted signals and outputting the signal to a serial line. Keywords Programmable Intelligent Computer (PIC) Universal Asynchronous Receiver/Transmitter (USART) Port Interrupt Watchdog Timer (WDT) Low Voltage Programming (LVP) Oscillator Serial Analog Digital Introduction When a problem occurs in the power grid, a protective relay will detect it, or trip, and disconnect the problem source from the grid. A challenge comes up in determining when and where the problem occurred. A sensor has been designed to detect the relay trip so that an operator can be notified immediately of the problem. A microprocessor is used to analyze the signal and then send the signal to the operator. Objective The design objectives are to receive a signal that an event has occurred from a latch, determine where the event occurred, transmit a warning to an operator or computer and then reset the latch. To do this, a PIC18F4520 microprocessor was used in conjunction with a universal asynchronous receiver/transmitter or USART. To determine where an event has occurred, each individual location has its own pin on the microprocessor. The microprocessor will then determine which pin has been set high to determine where the event occurred. Before any of the code for this program can be written, certain features of the microprocessor will need to be determined. The features being what inputs and outputs are available, how the microprocessor is programmed, how

the microprocessor communicates with external devices and how the microprocessor needs to be configured. Programming MPLAB IDE was used to program the 18F4520 microprocessor. This is a free toolset used to program and debug any of Microchips PICs and DsPIC microcontrollers. Programming was done in C code. MPLABs ICD 2 was used to connect the microcontroller to MPLAB. Configuration Configuration of a microprocessor is a crucial step when programming. Without the proper configurations, code will execute in unexpected and often problematic ways. The three main items that needed to be configured for this project were the OSC or oscillator, WDT or watch dog timer and LVP or low voltage programming. The OSC is used to determine the clock source. It is set to XT for external crystals under 4 MHz, HS for external crystals over 4 MHz, EC for a TTL/CMOS clock, RC for an external RC resonator and INT for an internal oscillator. Since a 40 MHz external clock is being used, the OSC configuration must be set to HS. The WDT is a timer that will periodically reset the PIC. When enabled, WDT set to ON, the microprocessor will run for a certain length of time then reset. This is an undesired feature that could cause a loss of data. To prevent this, the WDT should be set to OFF. When enabled, the LVP allows for more sensitive programming. This is only set to ON to prevent possible PIC resets. For this designs purpose, LVP is not needed and therefore was set to OFF. The code used to configure the PIC is shown below. #pragma config OSC=HS #pragma config WDT=OFF #pragma config LVP=OFF Ports The PIC 18F4520 has 5 usable ports or I/O registers. These ports are labeled A-E with Ports A-D having 8 bits each and Port E having 4 bits. Port A can be used as either analog or digital I/Os. Since the incoming signals will all be a latched bit, set either high or low, Port A can be set as a Digital I/O. One thing to note about Port A is that bits 6 and 7 are sometimes used for clock inputs. For this design, bit A7 is used for the 40 MHz clock input. Port B has 4 bits that can be set to an analog input or all eight can be used as digital inputs. Port B also can be used for an interrupt driven program with 4 pins used for external interrupts and 4 pins for interrupt on change processes. Bits 6 and 7 on Port B are used for PIC programming. The MPLAB ICD 2 connects to these two pins on the microcontroller. Bit 6 is used for the ICD clock and bit 7 for the ICD data. Port C can only be used for digital type I/Os. However, bits 6 and 7 can also be used for serial communication via a USART. These two pins will transmit the data from the microprocessor to the operator and receive a latch reset command via the USART. PORT D is used only for digital I/Os and PORT E, like PORT A can be used for both analog and digital. One thing to note about bit 3 of PORT E is that it does not have a way to define a data direction and it cannot be used as an output. With all this information in

mind, there are approximately 30 digital I/Os available for use on the microprocessor. Setting aside two of these for an interrupt driven system and a latch reset control. This leaves 28 bits available for signal individual signal input. For future expansion, these 28 digital bits could be reassigned as address bits. This would allow for 228 or over 250 million definable locations for an event. A wiring diagram for the PIC with a location of all port bit pins can be seen in figure 1.

MPLAB ICD2 1 2 3 4 5 6 18F4520 E3 10 k A0 A1 A2 A3 A4 A5 E0 E1 E2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 B7 B6 B5 B4 B3 B2 B1 B0

A7 A6 C0 C1 C2 C3 D0 D1

D7 D6 D5 D4 C7 C6 C5 C4 D3 D2

40 MHz Clock
T

10uF 10uF + -

+ 1 2 3 4 5 6 7 8 16 15 14 13 12 11 10 9

10uF + 10uF + -

RS 232 9 8 7 6 5 4 3 2 1

MAX232

Serial Out

Figure 1

Serial Communication The communication to an operator or computer was done using a MAX232N and RS232. The RS232 allows the circuit to connect to a serial cable which can then connect to a computer. The MAX232N converts the serial input and output levels so that the RS 232 and the PIC can communicate with each other. The wiring for the MAX232 and RS232 can be seen in figure 1. Conclusion The PIC 18F4520 provides an easy way to analyze multiple inputs and offers a simple method of communicating with an operator. By utilizing the different types of features available on the PIC, a much more efficient design can be obtained. References Pic Data Sheet: http://ww1.microchip.com/downloads/en/DeviceDoc/39631D.pdf MPLAB: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406& dDocName=en019469 PIC Configuration: http://ulcape.org/wiki/Tutorial-PIC_Programming_Basics MAX232 Data Sheet: http://focus.ti.com/lit/ds/symlink/max232.pdf

Das könnte Ihnen auch gefallen