UNIVERSITI TEKNIKAL MALAYSIA MELAKA ELECTRICAL ENGINEERING FACULTY Document No. : DEKC3453 By : TC.Ma SUBJECT : MICROPROCESSOR Issue No. / Rev : 3 / 2 PRACTICAL 4 SIMPLE APPLICATION BY FLIGHT-68K (MICROPROCESSOR LAB) TITLE: Simple Application by Flight-68K LAB 3 GROUP : 2 DEK TITLE : SIMPLE APPLICATION BY FLIGHT-68K DURATION : 3 HRS WEEK : 8 M/S : - 1 - UNIVERSITI TEKNIKAL MALAYSIA MELAKA ELECTRICAL ENGINEERING FACULTY Document No. : DEKC3453 By : TC.Ma SUBJECT : MICROPROCESSOR Issue No. / Rev : 3 / 2 OBJECTIVE: At the end of this session, student should be able to: 1. Create a ‘delay’ by writing a program (software delay). 2. Control output devices such as LED and DC motor. 3. Learn various programming technique using a microcomputer Flight-68K Training System. TOOLS: a) FLT-68K Microprocessor board. b) Multi Applications Board. c) Stop watch LAB 3 GROUP : 2 DEK TITLE : SIMPLE APPLICATION BY FLIGHT-68K DURATION : 3 HRS WEEK : 8 M/S : - 2 - UNIVERSITI TEKNIKAL MALAYSIA MELAKA ELECTRICAL ENGINEERING FACULTY Document No. : DEKC3453 By : TC.Ma SUBJECT : MICROPROCESSOR Issue No. / Rev : 3 / 2 SEKSYEN A (DELAY) THEORY: It is often necessary to control how long certain actions last. This can be achieved using software delays or more accurately by use of a timer. In the various states of the sequence, lights have to be on (or off) for a clearly defined time measured in seconds. So our program must contain a means of measuring one second. The easiest way, which does not need any further hardware devices, is a software delay. Generally, in a microprocessor-based system, the processing speed of a program is depends on the speed of a clock used in the system. It is also known that each command line will take a few cycles to be executed. Thus, the higher the speed of the clock, the faster the microprocessor executes every command line in the program. For example, if a system used a 10MHz of clock oscillator, the time for 1 cycle is 1/f = 0.1µs. Assumed the following command lines are to be executed by the microprocessor, MOVE.L # 384614, D6 ; load D6 with a fixed value SUBI.L #1,D6 By referring to the Instruction Execution Times Table, the number of cycles taken to execute each command is: MOVE.L # 384614, D6 is 12 cycles SUBI.L #1,D6 is 16 cycles Thus, the number of cycles to execute the above two command lines is 28 cycles. Since the system use a 10MHz clock oscillator, the number of times taken is 28 cycles x 0.1µs = 2.8µs If we create a program which loops round on it and does this for a fixed number of times, for a given processor, running at a given clock rate, this process will always take the same time. All we have to do is write such a multiple loop so that it takes one second to complete. (i.e. Load a register with a large number, decrement the number, test to see if it is zero yet, and if not decrement again, and test for zero again etc. finally leaving the loop when the decremented count = 0.) LAB 3 GROUP : 2 DEK TITLE : SIMPLE APPLICATION BY FLIGHT-68K DURATION : 3 HRS WEEK : 8 M/S : - 3 - ELECTRICAL ENGINEERING FACULTY UNIVERSITI TEKNIKAL MALAYSIA MELAKA Document No. : DEKC3453 By : TC.Ma SUBJECT : MICROPROCESSOR Issue No. / Rev : 3 / 2 PROCEDURE: 1. Let’s examine a suitable delay timer as below: DELAY DEL1 MOVE.L SUBI.L BNE RTS #1000, D6 #1,D6 DEL1 * load D6 with a fixed value of 1000 * decrement D6 * is it zero, if not jump back to DEL1 * it is zero, then exit 2. By using the simple program above, the applications board and a stopwatch, explain how you could measure a delay for 1 second. QUESTION: What is the fix value of D6 for 1 second? SEKSYEN B (RUNNING LIGHT APPLICATION) PROCEDURE: 1. IDE 68K Simulation for running light i) Launch the IDE68K and write this program LOOP DELAY DEL1 ii) iii) iv) v) ORG $400400 MOVE.B MOVE.B JSR ROL.B BRA #1,D0 D0,$0000E004 DELAY #1,D0 LOOP MOVE.L SUB.L BNE SUB.B BNE RTS #25000,D6 #1,D6 DEL1 #1,D2 DELAY ;load D6 Compile the code and click the run visual simulator At Peripheral drop down menu, click Configure peripherals. For LED’s peripheral address is set to 0000E004 and click OK. Go back to the peripheral drop down menu again and click LED’s to launch 8 bits of LED. Run the simulation by clicking the run button. Give your observation. LAB 3 GROUP : 2 DEK TITLE : SIMPLE APPLICATION BY FLIGHT-68K DURATION : 3 HRS WEEK : 8 M/S : - 4 - ELECTRICAL ENGINEERING FACULTY UNIVERSITI TEKNIKAL MALAYSIA MELAKA Document No. : DEKC3453 By : TC.Ma SUBJECT : MICROPROCESSOR Issue No. / Rev : 3 / 2 2. Implementation on Flight 68K i) By using the same code above, compile and load it to flight 68K. Give observation ii) Change the value load to D6 from 2500 to 384614. Compile and load back to flight 68K board. Compare the result from both experiments. QUESTION: In your opinion, why there is a difference on the delay time set by the IDE68K simulator versus Flight 68K board when D6 is set to 2500? SEKSYEN C (DC MOTOR) THEORY: A DC motor can be controlled by simply ON or OFF i.e. either stop or run, at its maximum speed. Figure 1 below shows the flow of motor control in this practical: Application Board Description : A small dc motor with 3 bladed propellers is limited to approximately 8000 RPM by two current limiting resistors that are connected to the board. The polarity of the voltage applied to the motor, hence forward and reverse is selected by relay K1. Motor ON either forward/reverse is selected by output bits 6 &7 on Port B. Their value is decoded by U4 such that: (SET bit 6) and (CLEAR bit 7) - produce forward motion (CLEAR bit 6) and (SET bit7) - produce reverse motion (CLEAR bit 6) and (CLEAR bit 7) - cause motor to stop LAB 3 GROUP : 2 DEK TITLE : SIMPLE APPLICATION BY FLIGHT-68K DURATION : 3 HRS WEEK : 8 M/S : - 5 - UNIVERSITI TEKNIKAL MALAYSIA MELAKA ELECTRICAL ENGINEERING FACULTY Document No. : DEKC3453 By : TC.Ma SUBJECT : MICROPROCESSOR Issue No. / Rev : 3 / 2 PROCEDURE : 1. Write and complete the program below by referring the theoretical methods above. (You can refer the comments at the right of program for reference) INITIALISE THE PI/T MOTOR MOVE.B BSR MOVE.B BSR MOVE.B BSR MOVE.B BSR BRA DELAY DEL1 MOVE.L SUBI.L BNE RTS # , PBDR DELAY # , PBDR DELAY # , PBDR DELAY # , PBDR DELAY MOTOR # , D6 #1 , D6 DEL1 ; set to ‘forward’ bit ; run ‘forward’ for 1s ; set to ‘stop’ bit ; the motor stop for 1s ; set to ‘reverse’ bit ; run ‘reverse’ for 1s ; set to ‘stop’ bit ; the motor stop for 1s ; repeat the whole program ; set the value for 1s delay END 2. Test the program by using FLT-68K and Application Board. Set the switch to motor DC on application board located in the MODE SWITCHES section. 3. Use the procedure, which you have been done before to assemble, download and execute the program by using Flight and Application Board. 4. Give your observation. QUESTION: a. Write your own program for 6 seconds Forward, 6 seconds Reverse, then 2 seconds pause and demo to the lecturer. LAB 3 GROUP : 2 DEK TITLE : SIMPLE APPLICATION BY FLIGHT-68K DURATION : 3 HRS WEEK : 8 M/S : - 6 - UNIVERSITI TEKNIKAL MALAYSIA MELAKA ELECTRICAL ENGINEERING FACULTY Document No. : DEKC3453 By : TC.Ma SUBJECT : MICROPROCESSOR Issue No. / Rev : 3 / 2 REPORT LAB 4 Name : Matric no. : Course : Group : SEKSYEN A Question: What is the fix value of D6 for 1 second? D6 = ________________________ SEKSYEN B Observation & Comparison: Question: In your opinion, why there is a differences on the delay time set by the IDE68K simulator vs Flight 68K board when D6 is set to 2500? LAB 3 GROUP : 2 DEK TITLE : SIMPLE APPLICATION BY FLIGHT-68K DURATION : 3 HRS WEEK : 8 M/S : - 7 - UNIVERSITI TEKNIKAL MALAYSIA MELAKA ELECTRICAL ENGINEERING FACULTY Document No. : DEKC3453 By : TC.Ma SUBJECT : MICROPROCESSOR Issue No. / Rev : 3 / 2 SEKSYEN C Program code: MOTOR MOVE.B BSR MOVE.B BSR MOVE.B BSR MOVE.B BSR BRA DELAY DEL1 MOVE.L SUBI.L BNE RTS # , PBDR DELAY # , PBDR DELAY # , PBDR DELAY # , PBDR DELAY MOTOR # , D6 #1 , D6 DEL1 ; set to ‘forward’ bit ; run ‘forward’ for 1s ; set to ‘stop’ bit ; the motor stop for 1s ; set to ‘reverse’ bit ; run ‘reverse’ for 1s ; set to ‘stop’ bit ; the motor stop for 1s ; repeat the whole program ; set the value for 1s delay END Observation: Program code for triggering motor 6 seconds forward, 6 seconds reverse, then 2 seconds pause and demo to the lecturer. LAB 3 GROUP : 2 DEK TITLE : SIMPLE APPLICATION BY FLIGHT-68K DURATION : 3 HRS WEEK : 8 M/S : - 8 -