





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Instructions for an exercise aimed at verifying a student's understanding of dc motor functionality and developing a dc motor tachometer program. The exercise covers various aspects of dc motor theory, including the electromechanical model, heat power dissipation, and the use of mcu timer functions. Additionally, students will learn how to calculate the time between two consecutive passes of the hole through the emitter-detector sensor, scale down time values, and calculate the rotation speed in 100s rpm.
Typology: Lab Reports
1 / 9
This page cannot be seen from the preview
Don't miss anything!
819329-3288363-k-20ex-dc-motor-rpm-doc.doc
The objectives of this exercise are: To verify the student’s understanding of DC motor functionality To develop a DC motor tachometer (RPM counter) program to be used in the lab Review the use of MCU Timer functions (free running clock, TCNT, overflow flag, TOF, input capture clock, TIC1, and its event flag, IC1F, the selection of signal transition to be captured (here rising edge, EDG1B) and that the MCU is only sensitive to that particular transition. Introduce the use of soft masks (here, IC1_MSK, TOF_MSK). Introduce the concept of layered flowcharting of a program: big-picture with generic descriptions; detailed flowcharts for particular sections of the program. Review the use of two time captures to calculate the time duration of an event Illustrate the use of scaling factors (100s) to deal with numbers that are larger than the microcontroller word length Introduce the method of calculating multiplication through repeated additions and decrementation of a counter Introduce the use of a conversion subroutine to convert from hex to BCD Illustrate rotation speed calculation using the recorded period of rotation Illustrate the use of scaling factors (100s) to present the result on a display with limited number of digits.
819329-3288363-k-20ex-dc-motor-rpm-doc.doc
819329-3288363-k-20ex-dc-motor-rpm-doc.doc
i. Use the microcontroller input-capture functions to capture the times, T1 and T2, and the number of overflows, NOF, corresponding to two consecutive passes of the aperture through the emitter-detector sensor. ii. Use decimal 100 to scale down T1 and T2, and obtain the scaled values T1_100 and T2_100, i.e. the time values in 100’s of cycles. iii. Calculate the time taken by overflows, TOVFL, in 100’s of cycles iv. Calculate the total time, T_100, in 100’s of cycles v. Use T_100 to calculate N_100_hex, the rotation speed in 100’s RPM vi. Convert the hex number N_100_hex to 2-digit BCD representation using subroutine HEX_BCD. Store the 2-digit BCD representation to N_100_BCD vii. Output the N_100_BCD to port B to be routed to a 2 digit 7-segment LED display. This display will show the rotation speed in 100s RPM.
Draw, below, a flowchart for your program. 5 point(s)
Use the flowchart to code your program in the simulator using the standard template. Save the program in the personalized file name LASTNAME_Firstname_RPM.asm. Write or paste your coded program below. 5 point(s)
819329-3288363-k-20ex-dc-motor-rpm-doc.doc
Open THRSim11. Close the Commands window. View CPU registers, timer registers, port A pins, memory list. Open and assemble your program. Set breakpoints at After first input capture on IC When an overflow happens After second input capture on IC SWI Reset registers and memory. Set standard labels. Set display of TCTL2, TFLG1, TFLG2 to binary. Arrange windows for maximum benefit: Press the RESET button. Paste your screen below: 1 point(s) a) Toggle pin IC1 to 1. Start the program. The program should stay in a loop waiting for a falling edge transition on pin IC1. b) Toggle pin IC1 to 0. The program should stop at the first breakpoint. Notice that IC1F is set in TFLG1 (bit 2). Also notice the value captured in TIC1. This value should be very close to the value in TCNT (It is not identical, since the program executed a few operations before stopping at the breakpoint, hence TCNT is slightly more than TIC1.) c) Step through your program until IC1F is cleared, TIC1 is loaded into D and then stored in T1, TOF is cleared, and NOF is zeroed. d) Run. The program enters the second IC1 capture loop. Let the program run until the timer counter, TCNT, goes through an overflow. At this point, the program should stop at a breakpoint. e) Step through your program and notice the overflow counter, NOF, being incremented, and the overflow flag, TOF, being reset. f) Let the program run. Toggle pin IC1 back to 1. Nothing should happen since only falling edges should be detected. Toggle IC1 to 0 again. The program should stop at the second IC1 capture breakpoint. The value of TIC1 should be updated to a new value. g) Step through your program. The new value of TIC1 is loaded and then stored in T2. The program branches back to the beginning (LABEL0). After returning to the beginning, the program zeros the NOF counter and goes through the process again. h) Let the program run again and repeat the steps above until you are satisfied that your program runs well. i) Run again but, after each breakpoint, simply hit the run button and let the program run until the next breakpoint. Make sure you verify that the generation of a falling edge signal on pin IC1 (by you toggling from 1 to 0) generates an input capture. j) Make sure to run the program long enough such that at least one overflow takes place. Observe how the overflow counter is incremented and the overflow flag is reset.
819329-3288363-k-20ex-dc-motor-rpm-doc.doc T1_100=____________________1 point(s) T2_100=____________________1 point(s) c) Step through the section of your program that calculates TOVFL, the time taken by overflows, expressed in 100s of cycles. TOVFL=_____________________ 1 point(s) d) Step through the section of your program that calculates T_100, the total time in 100s of cycles. Note how the formula T_100= TOVFL + T2_100 – T1_100 (1d) is applied in two steps, first the addition, then the subtraction. T_100=_____________________1 point(s) e) Step through the section of your program that calculates the variable N_100_HEX, the hex speed of rotation, in 100s of rpm. Note that the ‘magic’ number is loaded into accD and then divided by T_100. At the end of the process, the value N_100_HEX is obtained. N_100_HEX=________________ 1 point(s) f) Step through the last section of your program and calculate the variable N_100_BCD, which represent the decimal expression of the hex speed of rotation, in 100s of rpm. The conversion from hex to BCD is achieved by invoking the subroutine HEX-BCD. N_100_BCD=________________ 1 point(s)
Recall data from Case 2 of Example_RPM_2: NOF=2, T1=$fffd, T2=$1103. Note that this data represents the same time interval as in Case 1, only that a backwards time shift of 9 cycles took place. For this reason, the times T1 and T2 are on different sides of the time-change line. T1 happens before the time change, T2 happens after. Therefore, between T1 and T2, the time counter TCNT goes through a timer overflow. Hence, the overflow counter has the value NOF=2, instead of 1 as in Case 1. Use your pocket hex calculator to estimate the result to be expected at the end of the program: 6 point(s) T_100 = (NOF$10000+T2-T1)/100 = ($02$10000+$1103-$fffd)/$64 = $______ (1) N_100_HEX = (200000060/100/100/T_100) = $2ee0/$____ = $______ (2) N_100_BCD = ______ (3) Because the program needs to work with a finite word size, the variables in Equation (1) are first divided by decimal100, such that Equation (1) is actually treated as: T_100 = NOF($10000)/100+T2/100-T1/
819329-3288363-k-20ex-dc-motor-rpm-doc.doc The terms of equation (1) are calculated separately, as TOVFL, T1_100, T2_100. Hence, the following operations are performed: 4 point(s) T1_100 = T1/100 = $fffd/$64 = $______ (1a) T2_100 = T2/100 = $1103/$64 = $______ (1b) TOVFL = NOF($10000)/100 = $02$028f = $______ (1c) T_100= TOVFL + T2_100 – T1_100 = $051e + $____ - $____ = $______ (1d) Note that the result of Equation (1d) is the same as that of equation (1). Hence, Equations (2) and (3) still stand. Next, verify these arithmetic operations step-by-step: g) Put Case 2 data in memory: NOF=2, T1=$fffd, T2=$1103. h) Step through the section of your program that divides the variables T1 and T2 by decimal 100 to obtain T1_100 and T2_100. Use the hex pocket calculator to verify these results. T1_100=___________________ 1point(s) T2_100=___________________ 1point(s) i) Step through the section of your program that calculates TOVFL, the time taken by overflows, expressed in 100s of cycles. Note that, initially, TOVFL=___________________ 1 point(s) j) Step through the section of your program that calculates T_100, the total time in 100s of cycles. Note how the formula T_100= TOVFL + T2_100 – T1_100 (1d) is applied in two steps, first the addition, then the subtraction. At the end of the process, the same T_100 value as in Case 1 should be obtained. T_100=____________________1 point(s) k) Step through the section of your program that calculates the variable N_100_HEX, the hex speed of rotation, in 100s of rpm. Note that the ‘magic’ number is loaded into accD and then divided by T_100. At the end of the process, the value N_100_HEX is obtained, which is the same as in Case 1. N_100_HEX=______________ 1 point(s) l) Step through the last section of your program and calculate the variable N_100_BCD, which represent the decimal expression of the hex speed of rotation, in 100s of rpm. The conversion from hex to BCD is achieved by invoking the subroutine HEX-BCD. At the end of the process, the same N_100_BCD value as in Case 1 should be obtained. N_100_BCD=______________ 1 point(s)