[SOLVED] ENCE361-Lab 3 Accelerometer, Buttons and Display

30.99 $

Category:

Description

5/5 - (1 vote)

The build of this program needs access to the ustdlib module and to the OLED support module.

ustdlib.c:                    Right-click on the week3Lab project, Add Files

browse to C:\ti\TivaWare_C_Series-2.1.4.178\utils\ustdlib.c

                                      Open, then choose Link

                                      ustdlib.c will appear in the project with a link icon alongside. OrbitOLED:           File | New | Folder | Advanced >> | Link to alternate location

Browse to the OrbitOLED folder in your workspace, click Finish

                                                                    The OrbitOLED folder will appear in the project with a link icon alongside. Add   P:\Courses\ENCE361\labs   (i.e., your workspace containing the OrbitOLED folder) to the compiler include paths,

                                              using Properties | ARM Compiler | Include Options  and  +

 

Remember: use “Exclude from Build” to only compile the .c files that are part of each program.

 

This very straightforward program puts 4 lines of characters on the display, with the third row updating the display of 0 to 255 at about 2 Hz.  It does not use the buttons.  It illustrates how to initialise and use the Orbit OLED display for text.

 

4.3 Compile and link butsTest4.c

NB: This file needs access to the OLED support module and to the ustdlib module. Remember to exclude OLEDTest.c from your build at this stage.

Confirm that each button push is detected by the program as a single “PUSH”, followed by a “RELS” (release). This may seem trivial, but it is not, because most simple switches “bounce”, as described in section 4 above.

 

4.4 Compile, link and load readAcc.c

NB: This file needs access to the OLED support module. You also need to exclude butsTest4.c from your build.

Run the program and watch the values on the OLED display update as you hold your Tiva board in different orientations. Confirm that the program behaves as the description in the file header states.

 

4.5 Prepare a new version, say ‘readAcc2.c’, which displays acceleration in m/s2 on the Orbit display.  Change the accelerometer’s settings to give the best possible sensitivity (m/s2/bit).

Hint: Consult the ADXL345 datasheet to find out how to change the accelerometer’s resolution and range.

 

4.6 Prepare a third version, say ‘readAcc3.c’, which causes the Tiva’s red and green LEDs to light up when the device is held approximately level in the x and y directions, respectively.

 

4.7 Prepare a fourth version, say ‘readAcc4.c’, which calculates the orientation (pitch and roll) of the Tiva board based on the acceleration vector. Display the pitch and roll as percentages, where 0% corresponds to a completely level orientation and 100% corresponds to a 90° rotation in the relevant direction.  

 

  1. Guidance:

 

  • Before you start modifying a source file that has been provided to you, always use SaveAs to first copy it to a new file and a new name. Remember to exclude the original file from the next build.

 

  • Prepare the new programs one step-at-a-time.

 

  • Some code that you may link to requires the use of the “heap”. This requires that the heap size is increased from its default of 0 bytes.  Change this to (say) 512  via the Project Properties | ARM Linker | Basic Options window.  The stack size may need to be increased also in some cases, as your programs become more extensive.

 

  • Make new code as modular as possible, using appropriately designed and named functions. This will pay off when you come to build a much bigger program to control the helicopter.  If an existing and already tested function does what you want, leave it alone.

 

Test, test, and test once more.  Make sure your tests cover the specification fully.  A lot of problems with software occur because the developer has not been thorough in testing their code