EENG6670 Embedded Computer Systems
Engine Control Lab – Lab Group 13
EENG6670: Microcomputer Applications, Architectures and Performance (MAAP)
Introduction
This experiment supports some of the material in the MAAP lectures. You will look at a real-time system problem, generating the spark in an internal combustion engine.
Safety
This experiment has been reviewed under the Control of Substances Hazardous to Health (COSHH) regulations with a conclusion that there are no hazards covered by this act. The equipment has a revolving disc which may cause minor abrasions if touched while in operation. As with any electrically operated equipment, you should take care not to short out power supplies so metallic objects such as pens and watches should be kept clear.
Assessment
This experiment will be assessed by means of a formal report (as a guideline of about 10-12 sides, including diagrams and code listings) (note: do not list the whole code in your report as part of your answer to each task. Instead, only sections of code that relate to the task and where code modifications have been made). As a guide, you should spend about 6 hours on this and you can return to the lab to finish off or check results if you wish. You should each separately prepare your formal report. The emphasis should be on what you did and discovered with a discussion of these discoveries rather than a restatement of this script. For this reason, you should keep detailed records of your activities in an open Word document or note book including screenshots of the oscilloscope trace and the MBED LCD display which you must include in your final report with your answer to each part/question. Make sure you caption each screenshot properly and refer to it when you are providing your answer to each part/question.
Background theory for this lab is provided through the MAAP lecture 10 slideset/recording on Moodle. Throughout this script. you will find questions/topics which I would like you to answer and discuss in the report.
The Experiment
Rather than writing an exhaustive script. for this experiment, I have outlined the aims and method of each section. Generally, text in italics is used for aspects you will observe or carry out in the lab. Text in bold is used for questions you have to answer. Text in red is used for additional hints on each topic.
Note: Avoid the use floating point variables and math in any of the calculations you implement within the code – it’s too slow.
Please feel free to ask questions of the demonstrator and lecturer during or after the demonstrated sessions (please include both in your email):
Demonstrators: George Frangulea ([email protected]), Hazim Abdulsada ([email protected])
Lecturer: Philippos Assimakopoulos ([email protected])
Preamble
Before starting the lab, go through the background theory (MAAP lecture 10 slideset and recording on Moodle). If you haven’t used the MBED for some time, remember to check your MBED login prior to the lab and make sure it works (you will need it for the lab).
Note: Make sure that you stay within your allocated lab group and work on the correct lab script. version as the lab script changes every week. Submissions that are not for the correct lab group script will receive zero marks.
PART 1 [1 Mark]
In the lab we do not have a real petrol engine. Instead, we use a circuit board with a rotating disc/ flywheel (rotating counter-clockwise) to simulate some aspects of a petrol engine. The rotating disc can be made to spin at different rotational speeds (rpm). It has a TDC sensor and small hole in the disc to view LEDs. It also has some LEDs in the board that light up when the disc is at TDC and when you get a spark (the demonstrator will answer any questions you may have regarding the setup).
Log on to the MBED Keil Studio Cloud and create a new design called “measure”. Copy and paste the file measure.cpp from Moodle into your new design. The program uses the LCD12832 display to print out results, so you will need to import the LCD12832_lcd library into your design.
Connect the black flying lead from the flywheel to the GNDpin of the MBED, and the TDC output (red lead) to pin 30. Compile, download and run the project ‘measure’. Observe the program’s output on the LCD Display and/or the PC using Tera Term (a terminal emulator) (example LCD output is shown in Fig.1).
Fig. 1. Example of information displayed on the LCD display
The measure.cpp program uses the MBED’s CAP2.0 capture pin (pin 30) and Timer 2 to measure the rotational period of the disc. Go through the code (use the course lecture slides as reference if needed) and ensure that you understand how the program works.
Use the oscilloscope to look at the TDC pulse. It would look similar to Fig. 2 (note: if you are unfamiliar with the operation of an oscilloscope, ask the demonstrator).
Fig. 2. Oscilloscope view of TDC pulses. Note that measurement markers have been placed such that the period (Δt) between two consecutive TDC pulses can be measured.
Using the scope, determine and explain the relationship between the rotational period displayed by the program (in the LCD) and the timings measured using the oscilloscope – i.e, work out and state what a change of ‘1’ in the displayed LCD value corresponds to in actual time. Explain and note this in your report. Relate your answer to how the code in measure.cpp is implemented.
[Hint: Check the code, especially for the Timer2_init() function, try to work out the period of Timer- Counter 2 which is based on the pre-scaler value and the main frequency of the MBED core chip (the LPC1768 microcontroller). Once you have done this, you should be able to explain the relationship between the period displayed in LCD and the measured Δt from oscilloscope.]
Useful notes (based on the Lecture 10 slideset):
. The disc represents the crankshaft of the engine.
. Pistons are normally attached to the crankshaft and they slide up and down within cylinders.
. When the piston is at the top of its travel within the cylinder, it is said to be at Top Dead Centre
(TDC) . It is from here that the angles are measured i.e. it is 0° .
. The TDC sensor gives a positive pulse of about 4 milliseconds when the piston is at TDC. The rising edge (seen for example in Fig.2) represents TDC.
PART 2 [2 Marks]
Add a digital output called something like ‘spark’ on pin 12 to the measure.cpp code, to generate a "spark" at TDC with a duration of 0.5 ms.
Attach the white lead (spark wire) to your spark output and use the scope to observe the TDC sensor output and the spark. Sketch/Capture the result.
Useful notes (based on the Lecture 10 slideset):
. In this context a "spark" is a short positive pulse of 0.5 millisecond duration. It should be generated on the specified MBED pin which needs to be connected to the engine simulator. There, the spark pulse causes the LEDs to flash briefly.
. There is a small hole in the disc to view the LEDs. Since the LEDs are at a point just before TDC, in this instance you will not see them by looking from above. [The disc rotates anti clockwise]. They will be visible from the side.
. The simplest way to generate the spark is to set the spark output high at TDC, then wait for 0.5 millisecond before setting it low again. Note – You will need to configure the Spark output pin as a DigitalOut.
[Hint: The rising edge of spark signal should be generated at the rising edge of TDC. To implement this, figure out where the TDC signal is generated in measure.cpp file. Once you figure out this part, you should be able to find out where to make the addition to the code to generate the spark signal. Moreover, when you use the built-in wait(), wait_ms() or wait_us() functions from MBED library, for some reason, sometimes the wait_ms() function does not work properly. To tackle this issue, try to use the wait() function instead, but remember that the parameter passed into the wait() function is in unit of seconds. Lastly, DO NOT use any aforementioned wait() function inside the Timer2_isr() - as we discussed in the lectures it is not good practice to add delays in an ISR.]
Part 3 [5 Marks]
Create a new design called ‘timing’, copy and paste the file timing.cpp from Moodle into your new design. Compile and run timing.cpp. It produces a spark pulse, on pin 10, at 180 degrees before TDC.
Modify the programme so that it produces the spark at 15 degrees before TDC. Useful notes (based on the Lecture 10 slideset):
. A spark has to occur some time before TDC to allow the petrol/air mixture to be burning when the piston reaches TDC. This is known as the Advance Angle (AA) since the spark occurs "in advance of" TDC.
. You should be able to see the LEDs flash through the hole in the disc. The green LED is at 15 degrees before TDC.
[Hint: The disk rotates counter-clockwise (NOT clockwise).]
Observe the variation in the timing while the disc speed is being increased and decreased. You will see this as a change in the colour of the LED illuminated through the hole at the time of the "spark". That is, the spark pulse does not occur at the correct angle when accelerating or decelerating.
Why does this occur (provide an explanation in your report)?
[Hint: Check how is the period calculated in the code.]
Explain in your report how you could reduce this effect by modifying:
(i) the software and
(ii) the hardware
Save the code you have generated in Part 3, you will need to return to it later…
Now modify your code such that it displays not the period of rotation of the flywheel, instead it displays the rotational speed in revolutions per minute (rpm).
[Hint: You will need to inspect the Timer initialisation code to determine the significance of the displayed value of period. In addition, as you should not use floating point calculations, all variables should be declared as volatile INTEGER type, pay close attention when performing division arithmetic operations during the conversion from period of rotation to the rotational speed in revolutions per minute as any small value divided by a big value will end up with a zero result. For example, if you have three integer variables, int a = 2; int b = 10; and int c = 5, then a/b * c = 2/10 * 5 will give you 0 in this case, NOT 1 as 2/10 = 0 and 0 * 5 = 0. To solve this, rearrange the expression to (2 * 5) / 10 which will give you the desired output 1.]
Part 4 [4 Marks]
For best engine efficiency, the advance angle is small for low revolution rates and much larger at high revolution rates.
Alter your program so that it calculates the Advance Angle (AA), which should be 20 degrees up to 600 rpm and constant at 80 degrees beyond 1500 rpm. Between these two rotation speeds, there should be a linear change in the AA.
Test your AA calculation code by displaying the AA (along with the RPM) on the LCD display, line 2.
[Hint: Background information useful for solving this is available in the Lecture 10 slideset. You will need to derive the mathematical formula of the linear part of the AA graph.]
Once you have an AA varying between the two limits, modify the programme so that the spark occurs at the calculated time. Do not use floating point in your calculations since it is slow. Use your program to work out the angle before TDC of the right-hand red LED.
[Hint: In PART 3, the spark occurs at a fixed advance angle which is 15 degrees. Now you will need to utilise the calculated advance angle from above and replace the hard-coded one you did in PART 3]
Part 5 [2 Marks]
A realtime system can be defined as a system in which an action or calculation must occur within a limited period of time. As such, the system you have devised above can be considered as a real time one.
How much time is available for the calculation of the advance angle given a speed of 2100 revolutions per minute?
[Hint: This is a calculation problem. Background information useful for solving this is available in the lecture 10 slideset on Moodle.]
Part 6 [2 Marks]
Implement your software modification suggested in Part 3 to maintain the correct advance angle during acceleration and deceleration. Test your solution and see if it works.
Part 7 [2 Marks]
The code provided for Parts 3-5 uses a general purpose I/O Pin configured as an output and named ‘spark’ plus two Match Registers MR0 and MR1. An interrupt from MR0 sets the spark output high and an interrupt from MR1 resets spark low. The use of two match registers for a single output is not efficient, neither is the use of an extra output pin and DigitialOut API, when the processor can drive a pin automatically from the Match Register.
Copy the original timing.cpp code to a new design name and modify the code such that it uses just Match Register 1 to set the spark pin high, and then to return it low. Set the AA at a constant 15 degrees, to keep things simple and make testing easier.
Note: It is not safe just to toggle the Spark output, you need to set it high on the first Match Register Interrupt following TDC then set it low on the next interrupt. If you just toggle Spark, there is always the chance that the spark signal could become inverted following a glitch, so set it explicitly high and then low.
Part 8 [2 Marks]
The code is still using an extra output pin and DigitalOut API.
Modify your program such that the spark is generated directly from the MAT2.2 signal. To do this you will need to configure pin 6 such that it is driven by MAT2.2, and the pin should be set high and then set low using the Timer 2 Match Register 2.
Note: Pin 6 is used by the application board to drive the LCD Display, so this change will mess up the display. But give it a try anyway and checked the results on the oscilloscope. (It’s likely that you will have to remove the lcd library from your project for this). Once again, you should avoid toggling the spark output on a match.
版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。