Programming the Microchip Pic 16f84a Microcontroller As a Signal Generator Frequencies in Railway Automation

Similar documents
Embedded Systems. PIC16F84A Internal Architecture. Eng. Anis Nazer First Semester

Physics 335 Intro to MicroControllers and the PIC Microcontroller

PIC 16F84A programming (II)

JOINT-STOCK COMPANY GIDROPRIVOD. RADIAL PISTON PUMPS OF VARIABLE DISPLACEMENT type 50 НРР

CHAPTER 6 CONCLUSION AND SCOPE FOR FUTURE WORK

Section 11. Timer0. Timer0 HIGHLIGHTS. This section of the manual contains the following major topics:

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

Chapter 2 Sections 1 8 Dr. Iyad Jafar

8051 Microcontroller Interrupts

uninsta un in sta 9 weights & italics 5 numeral variations Full Cyrillic alphabet

Operating Manual version 1.2

CENG-336 Introduction to Embedded Systems Development. Timers

ME 6405 Introduction to Mechatronics

ME 515 Mechatronics. A microprocessor

Lecture (03) PIC16F84 (2)

R E N E W A B L E E N E R G Y D E V E L O P M E N T I N K A Z A K H S T A N MINISTRY OF ENERGY OF THE REPUBLIC OF KAZAKHSTAN

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

PIC Discussion. By Eng. Tamar Jomaa

NH-67, TRICHY MAIN ROAD, PULIYUR, C.F , KARUR DT. DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING COURSE MATERIAL

Embedded Systems Design (630470) Lecture 4. Memory Organization. Prof. Kasim M. Al-Aubidy Computer Eng. Dept.

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

DERTS Design Requirements (1): Microcontroller Architecture & Programming

University of Jordan Faculty of Engineering and Technology Department of Computer Engineering Embedded Systems Laboratory

«, 68, 55, 23. (, -, ).,,.,,. (workcamps).,. :.. 2

Embedded System Design

THE MATHEMATICAL MODEL OF AN OPERATOR IN A HUMAN MACHINE SYSTEMS. PROBLEMS AND SOLUTIONS

Lecture (04) PIC 16F84A programming I

Lecture (02) PIC16F84 (I)

Computer Hardware Requirements for ERTSs: Microprocessors & Microcontrollers

Lecture (04) PIC16F84A (3)

EE6008-Microcontroller Based System Design Department Of EEE/ DCE

PIC Microcontroller Introduction

4WCE * 5 * : GEO. Air Products and Chemicals, Inc., 2009

Laboratory 9. Programming a PIC Microcontroller - Part I

OFFER VALID FROM R. 15 COLORS TEXT DISPLAYS SERIES RGB12-K SERIES RGB16-K SERIES RGB20-K SERIES RGB25-K SERIES RGB30-K

Infusion Pump CODAN ARGUS 717 / 718 V - Release Notes. Firmware V

LAB WORK 2. 1) Debugger-Select Tool-MPLAB SIM View-Program Memory Trace the program by F7 button. Lab Work

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

Dept. of Computer Engineering Final Exam, First Semester: 2016/2017

Microcontroller Overview

NON-PROFIT ORGANIZATION CHARITY FUND

Lesson 14. Title of the Experiment: Introduction to Microcontroller (Activity number of the GCE Advanced Level practical Guide 27)

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

Figure 1.1: Some embedded device. In this course we shall learn microcontroller and FPGA based embedded system.

PIC16F87X. 28/40-pin 8-Bit CMOS FLASH Microcontrollers. Devices Included in this Data Sheet: Pin Diagram PDIP. Microcontroller Core Features:

Embedded Systems Programming and Architectures

University of Hawaii EE 361L MPLab Quick Tutorial and Project 2.1 Last updated September 1, 2011

Embedded Systems Lab Lab 1 Introduction to Microcontrollers Eng. Dalia A. Awad

PIC Discussion By Eng. Tamar Jomaa

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

8051 Microcontroller

APPLICATION NOTE Wire Communication with a Microchip PICmicro Microcontroller

C and Embedded Systems. So Why Learn Assembly Language? C Compilation. PICC Lite C Compiler. PICC Lite C Optimization Results (Lab #13)

Laboratory: Introduction to Mechatronics

EEE111A/B Microprocessors

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING MSC SYSTEMS ENGINEERING AND ENGINEERING MANAGEMENT SEMESTER 2 EXAMINATION 2016/2017

Myriad Pro Light. Lining proportional. Latin capitals. Alphabetic. Oldstyle tabular. Oldstyle proportional. Superscript ⁰ ¹ ² ³ ⁴ ⁵ ⁶ ⁷ ⁸ ⁹,.

Interface DAC to a PC. Control Word of MC1480 DAC (or DAC 808) 8255 Design Example. Engineering 4862 Microprocessors

which means that writing to a port implies that the port pins are first read, then this value is modified and then written to the port data latch.

Section 13. Timer0 HIGHLIGHTS. Timer0. This section of the manual contains the following major topics:

UNIVERSITY OF ULSTER UNIVERSITY EXAMINATIONS : 2001/2002. Semester 2. Year 2 MICROCONTROLLER SYSTEMS. Module Code: EEE305J2. Time allowed: 3 Hours

KbdKaz 500 layout tables

CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT. Spring 2006

/* PROGRAM FOR BLINKING LEDs CONEECTED TO PORT-D */

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

EE 361L Digital Systems and Computer Design Laboratory

OFFER VALID FROM R. TEXT DISPLAYS SERIES A SERIES D SERIES K SERIES M

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

Professor E. Ambikairajah UNSW Sydney

Outline. Micriprocessor vs Microcontroller Introduction to PIC MCU PIC16F877 Hardware:

Introduction to Embedded Systems

Section 8. Reset HIGHLIGHTS. Reset. This section of the manual contains the following major topics:

eip-10 Embedded TCP/IP 10-BaseT Network Module Features Description Applications

MicroProcessor. MicroProcessor. MicroProcessor. MicroProcessor

Learning Objectives:

, «Ruby»..,

University of Dayton. Electrical & Computer Engineering. ECE 536 Microprocessor Applications. Dr. Ralph Barrera. Assignment (4)

Embedded Systems. PIC16F84A Sample Programs. Eng. Anis Nazer First Semester

Section 9. Watchdog Timer (WDT)

Using Timers of Microchip PIC18F Microcontrollers

n/a PIC12F629-I/P (RC) n/a PIC12F629-I/SN (RC) n/a PIC12F675-I/P (RC) n/a PIC12F675-I/SN MICROCONTROLLER (RC)

Town Development Fund

Introduction to general architectures of 8 and 16 bit micro-processor and micro-controllers

PIC16C84. 8-bit CMOS EEPROM Microcontroller PIC16C84. Pin Diagram. High Performance RISC CPU Features: CMOS Technology: Peripheral Features:

Microcontroller systems Lec 2 PIC18LF8722 Microcontroller s s core

UCA Chart Help. Primary difference. Secondary Difference. Tertiary difference. Quarternary difference or no difference

Section 16. Basic Sychronous Serial Port (BSSP)

Section 9. Watchdog Timer (WDT) and Power-Saving Modes

Introduction to PIC Programming

PIC16F84A. 18-pin Enhanced Flash/EEPROM 8-Bit Microcontroller. Devices Included in this Data Sheet: Pin Diagrams. High Performance RISC CPU Features:

А. Љто нќша кђшка That s our cat

Introducing Microcontrollers System Design

CHAPTER 1 MICROCOMPUTER SYSTEMS. 1.1 Introduction. 1.2 Microcontroller Evolution

Micro II and Embedded Systems

EEE3410 Microcontroller Applications Department of Electrical Engineering Lecture 4 The 8051 Architecture

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

Microprocessors B Lab 1 Spring The PIC24HJ32GP202

Interrupts on PIC18F252 Part 2

The Freescale MC908JL16 Microcontroller

Chapter 11: Interrupt On Change

Transcription:

988 Programming the Microchip Pic 16f84a Microcontroller As a Signal Generator Frequencies in Railway Automation High School of Transport "Todor Kableshkov" 1574 Sofia, 158 Geo Milev str. Ivan Velev Abstract Using a new method of obtaining a signal frequency by a programmable microcontroller Microchip PIC 16F84A, data communication and management of projects in the transport of high responsibility. It is operated in generating regular rectangular pulse Ti = TA, and their duration is programmable and determines the frequency of the signal. The microcontroller has its own LC clock, but for stable operation it is advisable to use an external crystal resonator. We use system environment MPLab of Microchip, the creation of the program itself. The program is written in assembly language, creating a file with the extension. asm. The advantages of this method are: simple structure, low cost, high reliability. The computer model was tested in the software Proteus7.2. Laboratory tests were performed with a physical model to confirm reliable operation of the microcontroller. Key words: generator of frequency, microcontroller, programming, MPLab 1. Introduction The theme of the report is formulated as a result of research work of the microcontroller Microchip PIC16F84A. PIC16F84A is an 8-bit RISC-company microcontroller Microchip, shown in Fig. 1 belongs to the family of PIC16X8X PIC16FXXX. In addition, with this group belong also: PIC16F83, PIC16CR83, PIC16F84, PIC16CR84. The difference between the microcontrollers are mostly expressed in their operation and in the capacity of the memory, and in that some of it is reprogrammable, and the others -. Of these microcontrollers, PIC16F84A has the best features, namely: maximum clock frequency of 20MHz (which corresponds to a minimum instruction cycle - 200ns); a set of instructions 35, each of which has a length of one word; All instructions are executed by the microprocessor cycle with the exception of the transitions that take two cycles; capacity of the program (Flash) memory - 1024 words; 68 bytes of RAM data items; 64 bytes EEPROM memory data items; separate 14-bit instructions for highway and 8-bit data hardware stack with eight levels; Four sources of interrupting, respectively: - From an external source (INT); - Overflow of Timer 0; - In case of the bits 4 to 7 of the PORT B; - Upon completion of the entry in the EEPROM memory;

989 More than 1000 cycles erase / write FLASH program memory and 1,000,000 to EEPROM memory; During storage of the data stored in non-volatile memory EERROM - more than 40 years; Frequency of the supply voltage - from 2 to 5,5 V; Consumption: - Offer a small current of 2mA of power at 5 V and a clock frequency of 4 MHz - Current 15tsA at 2V supply and clock frequency 32kHz; - Current 0.5 / ua in SLEEP mode and supply voltage 2V. Operating temperature range: - 0 to +70 C - for commercial purposes; - From -40 to +70 C - for industrial purposes. In PIC microcontrollers and in particular in P1C16F84A basic connection diagram shown in Fig. 1 contains frequency element (depending on the type of generator) and elements that make up the chain reset (FT). As a timing element in this case is used quartz resonator - X1 running at 4MHz, This is the clock frequency that will work itself microcontroller. Fig.1 Depending on the needs, can be used, and other resonators, but it should be borne in mind that these will inevitably be accompanied with a change in timing of the program in question. This is cause for From clock directly dependent time that runs every hin ling or alteration, and hence the program. Provided circuit reset (FT) includes "Reset" button and RC built elements Rl, C1. By pressing the "Reset" is carried FT MCLR. and the purpose of the capacitor C1 to filter out transient input interference that microcontroller restarted. Also, thanks to the use of this capacitor, this artificial cc realized externally FT at power (POR). In principle, the supply voltage to the microcontroller may be varied between 2 and 5V, but in most cases (including here) is applied 5V. This value is suitable for two reasons: first, it can relatively easily be obtained by using the popular stabilizer 7805 and a second, relatively large part of the digital integrated circuits (which may be connected to microcontroller and to work together with it), using such power. An exemplary embodiment of the pattern, which can be prepared feeder voltage - is shown in Fig. 2.

990 Here, the desired value or 5V CE prepared beforehand line voltage falls to a value of about 9-12V, and then stand by Graecia bridge circuit (Budge) and filtered by electrolytic capacitor C1, and thus formed upright and filtered voltage is fed to compensation stabilizer 7805 that supports (stable) value of 5V, capacitors C2 and NW are to be used for additional filtration and bipolar capacitor prevents the microcontroller from RF interference coming from the mains. Thus, to achieve a better effect, it is recommended that the capacitor to be located as close to microcontroller (dandruff when installing the circuit board). 2. Materials and Method Fig.2 Generating A Square Wave With A PIC-Microcontroller With this realization, we will demonstrate how a conclusion from the microcontroller can receive and highlight, the simplest possible signal - a series of regular, rectangular pulses. I will explain in more detail how it works with PIC16F84A microcontroller. The duration of the pulses in this case can be set programmatically, and since it is a regular pulse (duration and pulse pause pa equal to Ti = TA. When specifying its duration will be very clearly defined and signal frequency (F = l / 2 Ti). this signal must be received on conclusion RB0. Having in mind that this series is actually a sequence of zeros and ones of the same length, then the receiving terminal and RB0, sequential programs need to reset and assigned to a unit Fig.3 Resetting the conclusions it with instructions "BCF PORTB, 0," and the establishment in one - with similar such "BSF PORTB, 0". To obtain, however, the desired duration of the pulse (Tи) and pause (Tп), respectively, the desired frequency, it is necessary after every down or reset the terminal to be measured given time interval (also called time-delay) equal to duration pulse (or pause). Once the algorithm description, which will generate a pulse signal is addressed and the program through which this algorithm will be realized. At first LIST directive is through the type of the microcontroller (CPU). On the next line, they shared program code includes the header file, "p16f84a.inc", contains the definitions of all SFR registers (of the corresponding microcontroller) with their bits. This and all other header files used for granted as they are set in the middle and MPLAB are recorded on the hard disk for installation in. The Directive " CONFIG_CP_OFF & _WDT_0FF & _PWRTE_ON & XT OSC", to ASM-file information is added to the configuration of the microcontroller, which is loaded directly used charter recording software. In this case, the protection code (Code Protection) and timer WDT is disabled. "CP_ OFF & _WDT_OFF", timer power-included "_PWRTE ON", and the type of generator c "_XT_OSC" quartz resonator. In the section "Defining Constants and Variables" Now therefore define the addresses used in the program general-purpose registers (GPR), plus the values of the various constants. In this case, the specific program used a GPR register

991 (Counter) and two constants w and f. These constants will be used when setting a destination (d), in the instruction requiring it. For example, if the result of the operation must be recorded in the working register (W), instead of "dccfsz Counter, 0" will record "dcctsz Counter, w". Similar will be recorded, where the result should be recorded in a register f, participating in the operation "dccfsz Counter, 1" - "dccfsz Counter, f". On the following lines define the start address of the recording of the program in the microcontroller and will move to the beginning of the program. In this case, the instruction "goto start" will be located of address 000h, corresponding to the reset vector. Thus, in the FT of the microcontroller will execute this instruction first, thanks to which, the program will start from the address specified by the label "start". The need for this conversion lies in the fact that the interrupt vector is located at address 0004h, three upstanding cell vector FT. In this sense, if used continuously (they currently do not have), address 0004h is reserved and can not contain any instructions from the main program, so it should be skipped. To avoid fragmenting the program however, the straight ss jump remaining three cells located between two vectors. Thus the user program starts immediately after the address corresponding to the interrupt vector. The program may be conditionally divided into three parts: "Start the program", "Used subroutines" (they shared them can be assigned to program service of interrupt) and "Main Program" At the beginning of the program shall be called. starting initialization microcontroller. It generally lies in charge of the register (OPTION_REG) - log options and initialization of input and output ports. When changing the status of individual bits can OPTION_REG: - Authorize or prohibit the pull (pull-up) registers - bit 7; - Sets the pulse for switching from terminal RV0) - bit 6; - Selects the source clock so TMR0 - bit 5; - Sets the pulse of TMR0 when working with an external clock 4-bit - Selects the divisor function - bit 3; - Sets the coefficient of the divisor - bits 2-0. l i st p= 1 6 F84A ; З а д а в а ти п а н а п роц е с о ра # in clu d e < p16f84a.i n c> ; Д е фи н и ц и и за SF R р ег и ст ри т е CONFIG _ CP_ O FF & _ WDT _ O FF & _ P WRT E_ ON & _ XT_ O SC ; ** * * ** * *Д е фи н и ра н е н а к он ста н ти и п р ом ен ли в и ** * * * * ** * * * * ** * * * * ** * * * * ** * w EQ U 0 f EQ U 1 Cou nt e r EQ U H '0 C ' ; Потреб и т е л с ка п р ог ра ма ORG H '0 0 0 0 ' ; В е кт о р н а Н У g ot o s ta rt ; П р е х од към н а ч а л о т о н а п рог ра ма та ; Начало н а п р ог ра ма та sta rt b s f ST AT U S, RP0 ; И з б о р н а Банка 1 m o vl w B '1 1 0 1 0 1 1 1 ' ; 1 1 0 1 0 1 11b -> W m o vl w O PT ION_R EG ; ( W) -> OPT ION_ REG b c f ST AT U S, RP0 ; И з б о р н а Банка 0 cl r f PO RT B ; 0 0 h -> P O RT B b sf ST AT U S, RP0 ; И з б о р н а Банка 1 m o vl w B '1 1 1 1 1 1 1 0 ' ; 1 1 1 1 1 1 1 0 b -> W m o v w f T RISB ; RB7-RB1-Входове, RB0-Изход b c f ST AT U S, RP0 ; И з б о р н а Банка 0 g ot o ma i n ; Изп о л зв а н и п од п р ог ра ми ; ------ П од п р ог ра ма "Wa it ", ф ор ми ра ща в р е м еза д ръж ка о т 4 6 0 ms ----- - Wa it m o vl w D '7 ' ; 7 -> W m o v w f Cou nt e r ; ( W) -> C ou n t er cl r f T MR0 ; 0 0 h -> T MR O

992 a ga i n b c f INT CON, T 0 IF ; Н у ли ра й б и т T O I F lo o p bt fss INT CON, T 0 IF ; Би т T O I F= 1? g ot o lo o p ; Н е, п р ов ери о тн ов о d e c fsz Cou nt e r, f ; Д а, C ou nt er= (C ou n t er)=1, Cou nt e r=0? g ot o a ga i n ; Н е, и зп ъ лн и ц и к ъ ла о тн ов о retu r n ; В р ъща н е к ъм г ла в н а та п р ог ра ма ; Гла в н а п р ог ра ма ma i n b s f PO RT B,0 ; R BO=1 ca l l Wa it ; И зч а ка й 460ms b c f PO RT B,0 ; RBO=0 ca l l Wa it ; И зч а ка й 460ms g ot o ma i n ; П ов т о ри ц и къ ла о тн ов о END ; Д и р ек ти в а за к ра й н а п р ог ра ма та In this program are selected and are important following options: - Internal clock module Timer 0 - TMRO content will be increased every cycle of the instruction; - Work with the divisor Timer 0; -Factor of division: 1:256. Although OPTION_REG loaded at the beginning of the program if at work and have to change one or the above options, there is no problem it is loaded with a new value. The only thing that should not be forgotten is the registry entries OPTION_REG be preceded by a choice of Bank 1, as it is situated in it. The same goes for the record registers the direction of data TR1SA and TRISB. As in the case of the microcontroller is used only conclusion RB0, the only thing that should be done in the init is the conclusion is defined as output (lines 22,23). You will note only that the reset bit of the register for the direction of data defining the terminal as an output, and the establishment of the same bit to "1", defined as an input terminal. If all terminals of a given port are used as inputs, the latter does not need to be initialized at the start of the program because the FT in the microcontroller, and all terminals are defined as inputs. After starting initialization microcontroller begins execution of the main program (lines 42-46). The latter consists of an endlessly repeating cycle ss, wherein ss performed sequentially down to "1" and the reset terminal RB0. To set the pulse duration and the pause time (time outputting RBO is maintained at "1" or "0") after each instruction for setting or resetting the terminal, it is necessary to dispense the time interval of a duration equal to the pulse duration (or pause). For this purpose, after each of these instructions subroutine "Wait" (Wait - wait) by which a measured time interval desired. Subroutine "Wait" is implemented using TMR0 (Timer 0) and can say it is used in almost all of the programs and can realize time intervals of varying duration. This program measures time by counting each full to register TMR0 (by value FFh to 00). When it is used the fact that the TMR0 overflow takes some time, depending on the selected division ratio, the initial value loaded into TMR0 register and a cycle time of instructions (when working on Timer 0 with internal clock). The relationship between these three parameters and time prepalvaps of TMR0 can cc gave the following relationship: 1 4 Tover [ 256 TMR0] Kps Fosc wherein: Tover - time which overflows (Overflow) TMR0 [ms]; (TMR0) - initial value loaded into register TMR0; Kps - coefficient of division (for example, if a selected ratio 1:256, 1/Kps = 256);

993 4/F osc - a cycle of instruction [ms]; F osc - speed, microcontroller [MHz]. Using this expression and maneuvering some of the parameters (most often these are Kps or (TMR0), can obtain many different values for the time interval Tover, Taking into account the values of the parameters that are valid for consideration program: Kps = l: 256, Fosc = 4MHz, (TMR0) = 0 we get; 4 Tover [ 256 0] 256 65536 s, 4 Which means that an overflow TMR0 in the case would take approximately 65,5 ms. In subroutine "Wait" for the right moment to full KBC TMR0 cc judged by determine flags bit T0IF (INTCON <2>) to "1". This practice test is implemented in cycles, located in rows 34-35 or program. An adequate examination, however, before entering into this cycle should be beaten T0IF reset "bcf 1NTCON. T0IF ". In any overflow TMR0, the value of register "Counter" (with which he is charged at the beginning of the subroutine - lines 30, 31) is reduced by one. If the result of this operation is different from zero, the execution of the subroutine continues ("golo again"), but otherwise the place back to the main program - "return" (46). Thus, in the subroutine "Wait" to form a two-cycle: - Through the first monitor overflow TMRO, - By the second - for their number. Since the value loaded into register "Counter" is 7 and the total time that will be measured by the program in this case is 7x65, 5ms, approximately 460m from the foregoing that, by changing the value loaded into register "Counter", the total time can be varied in the range of 65,5 ms (at Counter = l) to 16,7 s (at Counter = 255). This does not have time limits that can be obtained through this program. In case you need a time interval less than 65,5 ms can maneuver through Tover and if necessary time interval greater than 16,7 s, you just have to organize one, two or as many additional cycles need to monitor number of overflow TMR0. For example, using one more cycle time interval of maximum length will be: 255x255x65, 5ms, i.e. about 4259s (approximately 1 hour and 20 minutes). Considering the time interval provided by one examined subroutine, we can determine the frequency of the output signal received on conclusion RB0, namely: f 1 1 1 Hz T tи tп 460.10 460.10 1 3 3 If necessary, the preparation of a higher (lower) than the frequency need to be reduced (increased), the length of the time interval formed by the subroutine "Wait". To be loaded into the microcontroller need to convert the file into machine code. This is also done in the system environment MPLab, as the new file already obtained an extension hex.

994 Fig.4 Fig 4 shows how to generate a frequency 79 by microcontroller PIC16F84A and is committed to the program Proteus 7.0 Reference to a sites: [1] PIC16F84A Data Sheet - Microchip-www.microchip.com [2] www.constructor.bg/mk/