DIGITAL COMMUNICATION USING THE PIC16F84A MICROCONTROLLER

3y ago
74 Views
6 Downloads
272.06 KB
21 Pages
Last View : 10d ago
Last Download : 3m ago
Upload by : Luis Wallis
Transcription

DIGITAL COMMUNICATION USING THE PIC16F84AMICROCONTROLLERMelonee WisePhysics344Fall 2003

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve ErredeTABLE OF CONTENTSPURPOSE . 3A PROTOTYPE ROBOT . 4Alpha Zippy. 4Tether Controlled H-bridge Circuit. 5COMMUNICATION HARDWARE AND METHODS . 61. PIC Setup. 6Project Window. 62. Initial Testing . 7LED Flasher Code. 7Simple LED Flasher Circuit . 83. Interrupts. 8Interrupt Code . 94. PWM (Pulse Width Modulation). 10PWM Code. 10PWM Test Circuit . 125. Sending and Receiving Data . 13Send Code . 13Receiver Code. 15Sender/Receiver Circuit . 186. RF . 19Transmitter Circuit . 19Receiver Circuit . 20THE TEST DRIVE . 20THE CREATOR . 21Melonee and Zippy. 21Page 2/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve ErredePurposeThe purpose of this project is to develop digital communication using the PIC16F84Amicrocontroller for interface with RF transceivers to control a robot. The specific goals ofthe project are:1. Construct Prototype Robot2. PIC Chip Setup- Obtain necessary software (MPLAB IDE and PICPRO).- Setup new project within MPLAB.- Configure the assembler code properly for the PIC16F84A chip.3. Hardware Design- Design necessary test circuitry to test each software progression.- Design necessary circuitry to interface the PIC chips and the RF moduleswith the prototype robot.4. Software Design- Write a LED flasher program.- Write an interrupt program.- Write a PWM program.- Write a sender program.- Write a receiver program.5. Test the PIC send and receive protocol.6. Test the PIC chip with RF.7. Drive robot around using digital RF controller.Page 3/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve ErredeA Prototype RobotFor this project a prototype robot, Zippy, was built (Figure 1).Figure 1 Alpha ZippyZippy’s main components consist of:2 pieces of plywood2 bicycle training wheels4 bicycle training wheel brackets2 Pitman motors (donated by the ECE department)1 12V motorcycle battery2 pieces of 1 ½ PVC pipe (hold the motors and shafts in place)2 yards of rope2 tape holders (counterbalance the battery)10 or so nuts and bolts2 H-bridges1 receiver1 kill switchOf the hardware used to construct Zippy only the electrical components will bediscussed within this report because it obvious to see the degree of craftsmanshipthat was necessary to construct the prototype.Initially Zippy was a tether controlled robot, a switch controller was linkeddirectly to the speed controller. The speed controller consisted of two H-bridgesthat controlled each motor separately. The N-type and P-type mosfets weresalvaged off of old computer boards and can handle a max of 6 Amps. A 12Vmotor cycle battery was used to power the motors and four, slightly used, 1.5V(double A) batteries were used to power the switch logic. A 3 Amp fuse was usedon the 12V battery to stop potential hazards (i.e. fires, exploding mosfets, ect.).Page 4/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve ErredePNMPNOptical NMPN12V3 AmpPIN1PIN2PIN3PIN4PIN5PIN6PIN7PIN8Figure 2 Tether Controlled H-bridge CircuitPage 5/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve ErredeCommunication Hardware and Methods1. PIC SetupBefore beginning the project, the necessary programs must be obtained. MPLABcan be downloaded for free from http://www.microchip.com and a programmerand programming software can obtained from http://ramseyelectronics.com. Afterthe proper software and equipment are obtained the PIC chip must be correctlyconfigured in MPLAB so that it can be programmed properly and functionsproperly when tested. Remember to always read the PIC data sheet beforebeginning any project.First a project must be setup in MPLAB by creating a new project using theproject wizard. The project wizard will step through selecting the proper device(PIC16F84A), the proper language toolsuite (MPASM Assembler), and finally theproject name and directory. Within the project the proper include and linker filesmust be added, the include files can be found in the MPLAB IDE folder underdisPIC Tools/support/inc and the linker files in the MPLAB IDE folder underMCHIP Tools/Lkr. Finally a main source file must be created for executablecode. When these steps are completed the project window should look similar toFigure 3.Figure 3 Project WindowNext it is important to have the proper configuration; this sets the oscillator type,the watchdog timer, copy protection, and power up timer. For this project, themain source file is configured in the following manor,config WDT OFF & PWRTE ON & HS OSC & CP OFF,Page 6/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve Erredethis turns the watchdog timer off, the power up timer on, sets the oscillator to highspeed, and turns copy protection off.Finally the banks, ports, and interrupts must be configured properly. For thisproject, the bank is set to bank 0, A ports are set as inputs, B ports are set asoutputs, and to begin with all of the interrupts are disabled. The interrupts will beused later in the project but for initial testing and setup they are disabled.2. Initial TestingTo quickly test whether the PIC chip has been configured correctly the followingassembler program and circuit (Figure 4) can be used.LED Flasher Code:#include P16F84A.INC processor 16f84Aconfig WDT OFF & PWRTE ON & HS OSC & CP OFFRESET CODE 0GOTO INITCODEINIT:BCF STATUS, RP1BSF STATUS, RP0CLRF INTCONMOVLW B'11111111'MOVWF TRISAMOVLW B'00000000'MOVWF TRISBMOVLW B'10001000'MOVWF OPTION REGBCF STATUS, RP0START:MOVF PORTA, WMOVWF PORTBCLRWDTGOTO STARTEND;set to bank 1;disable all interrupts;make A ports input;make B ports output;return to bank 0;copy PORTA to PORTBPage 7/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve ErredeFigure 4 Simple LED Flasher Circuit3. InterruptsTiming is very important when trying to send and receive data; interrupts can beused to create the necessary timing. The timer interrupt for the PIC16F84A occursevery 256 instruction cycles. The amount it takes to complete one instructioncycle varies based on the frequency of oscillator input and can be calculated usingequation 1,1 time to complete one instruction . Oscillator frequency 4 (1)The time between interrupts is given by equation 2, 4 Oscillator frequency time between interrupts .256(2)The timer interrupt can be used to call functions at constant intervals by countingthe number of interrupts that occur between calls. Equation 3 can be used tocalculate the number of interrupts that happen in a certain time interval.Page 8/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve Errede Oscillator frequency time 4 number of interrupts in x seconds .256(3)For this project a 16.25MHz clock was used, all calculations are based on thisoscillator frequency.When an interrupt occurs the PCL of the chip is set to register 4 in the memorybank, i.e. the interrupt code must start at 4. When using an interrupt special caremust be taken so that the program returns with all of the correct values in the Wand STATUS registers. For this project interrupts were used as a timer, each timethe interrupt was called it incremented a register which the main programchecked. When the registers reached a certain value/time the send or receivefunction was called to send or receive data. Make sure to use the appropriatenumber of registers for the amount of time needed, each register can only holdtwo bits in HEX.The following interrupt code demonstrates how to store the W and STATUSregisters and increment counter registers for timing.Interrupt Code:#include P16F84A.INC processor 16f84AUDATAW TEMP res 1STATUS TEMP res 1GLOBAL TIMEC1TIMEC1 res 1GLOBAL TIMEC2TIMEC2 res 1INTERRUPT CODE 4GOTO PUSH;sets code start to 4th registerCODEGLOBAL PUSHPUSH:;save W and statusMOVWF W TEMPSWAPF STATUS, WMOVWF STATUS TEMPISR:INCFSZ TIMEC1, FGOTO POPINCF TIMEC2, FPOP:;interrupt service routine;if zero increment next register;if zero increment next register;restore W and statusBCF INTCON, T0IFSWAPF STATUS TEMP, WMOVWF STATUSSWAPF W TEMP, FSWAPF W TEMP, WPage 9/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WiseRETFIEENDPhysics Department, University of IllinoisInstructor: Steve Errede;return from interrupt4. PWM (Pulse Width Modulation)Pulse width modulation, in its simplest form, takes a binary number and creates apulse of the appropriate width, as shown in Figure 5.001010011Figure 5 PWM examplePWM is extremely useful for motor speed control, if a motor is turned on and offquickly (quick enough to have smooth motion) the motor speed is determined bythe portion of time it is on. The PWM code for this project was mainly used to testthe interrupt code but will be used in a later project to create a variable speedcontroller for the robot.The code and circuitry (Figure 6) shown below can be used to create a verysimple and slow PWM to visually check whether the interrupts have been setupcorrectly. Basically it takes a three bit (0-8) binary number from PORTA and usesit to make a modulated pulse. Each segment of the pulse is one second long, so ifthe input is two then the output would be high for two seconds and low for sixseconds. The code has three parts, a main function, PWM function, and aninterrupt (the interrupt code is shown above).PWM Code:PWM#include P16F84A.INC processor 16f84AUDATAPWMC res 1Page 10/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve ErredeGLOBAL PWMCODEPWM:MOVLW .6;decrement or reset counterDECF PWMC, FBTFSC PWMC, 7MOVWF PWMC;output the low bits of PORTA onto the low bits of PORTBMOVLW B'00000111'ANDWF PORTA, WIORWF PORTB, FMOVLW B'11111000'IORWF PORTA, WANDWF PORTB, FMOVFW PORTA;check count against input valueANDLW B'00000111'SUBWF PWMC, WBTFSS STATUS, CGOTO HIGHOUTGOTO LOWOUTHIGHOUT:BSF PORTB, 6GOTO NEXT;set bit 6 highLOWOUT:BCF PORTB, 6;set bit 6 lowNEXT:RETURNENDMAIN#include P16F84A.INC processor 16f84Aconfig WDT OFF & PWRTE ON & HS OSC & CP OFFEXTERN TIMEC1EXTERN TIMEC2EXTERN PWMRESET CODE 0GOTO INITCODEINIT:BCF STATUS, RP1BSF STATUS, RP0CLRF INTCONMOVLW B'11111111'MOVWF TRISAMOVLW B'00000000'MOVWF TRISBMOVLW B'10001000'MOVWF OPTION REGBCFSTATUS, RP0MOVLW B'10100000'MOVWF INTCONSTART:BCF INTCON, GIEMOVLW H'FD';set to bank 1;disable all interrupts;make A ports input;make B ports output;return to bank 0;enable timer interrupt;checking to see if has been 1s;stop interrupt while checking timePage 11/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WiseSUBWF TIMEC1, WBTFSS STATUS, ZGOTO NEXTMOVLW H'3D'SUBWF TIMEC2, WBTFSS STATUS, ZGOTO NEXTMOVLW B'10000000'XORWF PORTB, FCLRF TIMEC1CLRF TIMEC2CALL PWMPhysics Department, University of IllinoisInstructor: Steve Errede;clearing out the timers after 1sNEXT:BSF INTCON, GIECLRWDTGOTO STARTEND;turning interrupts back onFigure 6 PWM Test CircuitPage 12/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WisePhysics Department, University of IllinoisInstructor: Steve Errede5. Sending and Receiving DataTypically when sending data a protocol is developed so that the receiving endknows when to start and stop accepting data. A start and stop bit are used for thispurpose. Parity checking can also be added to the end of words/data ensure thatthe data receive is actually what was sent. For this project, the protocol consistedof a start bit and a long wait in-between data packets. This is an extremelysimplified method of sending and receiving data, the follow up project will createa more robust protocol that includes a decent checking scheme.The code shown below can be used to create a very simple sending program thatsends data at about 110Kbs. Basically it takes the input from PORTA, adds a startbit, sends it serially, waits, and then sends PORTA again. The code has threeparts, a main function, send function, and an interrupt (the interrupt code is shownabove).Send Code:SEND#include P16F84A.INC processor 16f84AUDATASPTR res 1TEMP A res 1SENDC res 1GLOBAL SENDGLOBAL SINIT;this points to the correct state;temp for the PORTA data;counter for send/wait;Initialize to put the pointer to STARTBCODESINIT:MOVLW STARTBMOVWF SPTRRETURNSEND:MOVFWXORWFANDLWXORWFSENDC;OUTPUT SEND COUNTPORTB, WB'00011111'PORTB, FMOVFW SPTRMOVWF PCLSTARTB:BSF PORTB, 6BSF PORTB, 5MOVFW PORTAMOVWF TEMP ABSF TEMP A, 7BCF TEMP A, 6MOVLW .9MOVWF SENDC;GOTO SPTR;sends start bit;set bits that can’t be read inPage 13/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WiseNEXTB:MOVLW ONEOUTBTFSS TEMP A, 0MOVLW ZEROOUTMOVWF SPTRRRF TEMP A, FDECFSZ SENDC, FRETURNMOVLW SENDWMOVWF SPTRMOVLW .9MOVWF SENDCRETURNONEOUT:BCF PORTB, 5BSF PORTB, 6GOTO NEXTBZEROOUT:BCF PORTB, 5BCF PORTB, 6GOTO NEXTBSENDW:BCF PORTB, 6DECFSZ SENDC, FRETURNMOVLW STARTBMOVWF SPTRRETURNENDPhysics Department, University of IllinoisInstructor: Steve Errede;figures out next bit to output;sets the pointer to the right output;if done sending go wait for awhile;wait a little bit before resending data;output high;go figure out next bit;output low;go figure out next bit;go low while waitingMAIN#include P16F84A.INC processor 16f84Aconfig WDT OFF & PWRTE ON & HS OSC & CP SET CODE 0GOTO INITCODEINIT:BCF STATUS, RP1BSF STATUS, RP0CLRF INTCONMOVLW B'11111111'MOVWF TRISAMOVLW B'00000000'MOVWF TRISBMOVLW B'10001000'MOVWF OPTION REGBCFSTATUS, RP0CALL SINITMOVLW B'10100000'MOVWF INTCONSTART:;set to bank 1;disable all interrupts;make A ports input;make B ports output;return to bank 0;enable timer interrupt;checking to see if has been .009sPage 14/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WiseBCF INTCON, GIEMOVLW H'90'SUBWF TIMEC1, WBTFSS STATUS, ZGOTO NEXTMOVLW H'00'SUBWF TIMEC2, WBTFSS STATUS, ZGOTO NEXTMOVLW B'10000000'XORWF PORTB, FCLRF TIMEC1CLRF TIMEC2CALL SENDPhysics Department, University of IllinoisInstructor: Steve Errede;stop interrupt while checking time;clearing out the timers after 1sNEXT:BSF INTCON, GIECLRWDTGOTO STARTEND;turning interrupts back onOn the other end of the process is the matching receiver PIC chip which checksfor the incoming data, process it, and outputs it in the desired manner.The code shown below can be used to create a very simple receiving program thatcontinually receives data by latching on to a start bit. Basically it waits forPORTA to go high and then begins reading in data after the initial bit. Typicallythe start bit would be different than the other bits sent and the receiver wouldcheck for this but because there is such a long wait between transmissions it isunnecessary. The code has three parts, a main function, receive function, and aninterrupt (the interrupt code is shown above).Receiver Code:RECEIVE#include P16F84A.INC processor 16f84AUDATARPTR res 1TEMP B res 1RECEIVEC res 1WAITC res 1GLOBAL RECEIVEGLOBAL RINIT;this points to the correct state;temp for the PORTA data;counter for bits received;wait counter;Initialization to RECEIVECODERINIT:MOVLW CHECKMOVWF RPTRMOVLW .1MOVWF WAITCRETURNRECEIVE:DECFSZ WAITC, FPage 15/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee WiseRETURNMOVFW RPTRMOVWF PCLPhysics Department, University of IllinoisInstructor: Steve Errede;GOTO RPTRCHECK:MOVLW .1MOVWF WAITCBTFSS PORTA, 0RETURN;runs receive when line goes highSTARTB:MOVLW .8MOVWF RECEIVECMOVLW .9MOVWF WAITCMOVLW READINMOVWF RPTRBSF PORTA, 2BSF PORTA, 3RETURN;sees start bitREADIN:BCF PORTA, 3MOVLW B'00000100'XORWF PORTA, FRRF TEMP B, FBSF TEMP B, 7BTFSS PORTA, 0BCF TEMP B, 7MOVLW .6MOVWF WAITCDECFSZ RECEIVEC, FRETURNBCF PORTA, 2MOVFW TEMP BMOVWF PORTBMOVLW .12MOVWF WAITCMOVLW CHECKMOVWF RPTRRETURNEND;number of bits to read in;wait until middle of bit0;set wait state;read in new bit;wait for new bit;check to see if 8 bits were read;finished receiving one byte ;wait;wait for next startMAIN#include P16F84A.INC processor 16f84Aconfig WDT OFF & PWRTE ON & HS OSC & CP TRESET CODE 0GOTO INITCODEINIT:BCF STATUS, RP1BSF STATUS, RP0CLRF INTCONMOVLW B'11111111';set to bank 1;disable all interruptsPage 16/21

Physics 344 Final Project Fall 2003Digital Communication By Melonee AB'00000000'TRISBB'10001000'OPTION REGSTATUS, RP0RINITB'10100000'INTCONSTART:BCF INTCON, GIEMOVLW H'18'SUBWF TIMEC1, WBTFSS STATUS, ZGOTO NEXTMOVLW H'00'SUBWF TIMEC2, WBTFSS STATUS, ZGOTO NEXTMOVLW B'10000000'XORWF PORTB, FCLRF TIMEC1CLRF TIMEC2CALL RECEIVEPhysics Department, University of IllinoisInstructor: Steve Errede;make A ports input;make B ports output;return to bank 0;enable timer interrupt;checking to see if has been .0015s;stop interrupt wh

Digital Communication By Melonee Wise Instructor: Steve Errede Page 3/21 Purpose The purpose of this project is to develop digital communication using the PIC16F84A microcontroller for interface with RF transceivers to control a robot. The specific goals of the project are: 1. Construct Prototype Robot 2. PIC Chip Setup

Related Documents:

May 02, 2018 · D. Program Evaluation ͟The organization has provided a description of the framework for how each program will be evaluated. The framework should include all the elements below: ͟The evaluation methods are cost-effective for the organization ͟Quantitative and qualitative data is being collected (at Basics tier, data collection must have begun)

Silat is a combative art of self-defense and survival rooted from Matay archipelago. It was traced at thé early of Langkasuka Kingdom (2nd century CE) till thé reign of Melaka (Malaysia) Sultanate era (13th century). Silat has now evolved to become part of social culture and tradition with thé appearance of a fine physical and spiritual .

6.3 State the function of Time Out Sequence and Power Down Status bits (TO/PD) of PIC16F84A. 6.4 State the function of each interrupts sources used in PIC16F84A. 6.5 Describe the operation of Watchdog Timer in PIC16F84A. 6.6 State the function of Power down Mode (Sleep and Wake up from sleep) in PIC16F84A. 7. Understand the functions of PLC

On an exceptional basis, Member States may request UNESCO to provide thé candidates with access to thé platform so they can complète thé form by themselves. Thèse requests must be addressed to esd rize unesco. or by 15 A ril 2021 UNESCO will provide thé nomineewith accessto thé platform via their émail address.

̶The leading indicator of employee engagement is based on the quality of the relationship between employee and supervisor Empower your managers! ̶Help them understand the impact on the organization ̶Share important changes, plan options, tasks, and deadlines ̶Provide key messages and talking points ̶Prepare them to answer employee questions

Dr. Sunita Bharatwal** Dr. Pawan Garga*** Abstract Customer satisfaction is derived from thè functionalities and values, a product or Service can provide. The current study aims to segregate thè dimensions of ordine Service quality and gather insights on its impact on web shopping. The trends of purchases have

Chính Văn.- Còn đức Thế tôn thì tuệ giác cực kỳ trong sạch 8: hiện hành bất nhị 9, đạt đến vô tướng 10, đứng vào chỗ đứng của các đức Thế tôn 11, thể hiện tính bình đẳng của các Ngài, đến chỗ không còn chướng ngại 12, giáo pháp không thể khuynh đảo, tâm thức không bị cản trở, cái được

American Gear Manufacturers Association 500 Montgomery Street, Suite 350 Alexandria, VA 22314--1560 Phone: (703) 684--0211 FAX: (703) 684--0242 E--Mail: tech@agma.org website: www.agma.org Leading the Gear Industry Since 1916. February 2007 Publications Catalogiii How to Purchase Documents Unless otherwise indicated, all current AGMA Standards, Information Sheets and papers presented at Fall .