EENG 383

Lab 13 - Ultrasonic Parking Assistant

Lab: 13
Status Live

InLab 13

Some self guided activities.

Lab 13 assignment

I have been having some difficulty parking my car in the tight parking spaces available in front of Brown building and I would like your help building a digital parking assistant. The reason that I am having difficulty is that I cannot determine how much room I have behind my car as I am backing into a space. I am planning on mounting an ultrasonic range finder on my rear bumper and running a cable from the range finder to my dashboard where the development board will reside. The RGB LED on the development board will provide me with the proximity to any obstruction behind me using color as follows:


Software

The software should use CCP4 interrupt to measure the echo pulse duration from the ultrasonic range finder. The code for the CCP4 interrupt should be placed in void myCCP4ISR(uint16_t capturedValue); Note the argument to the ISR is provided by the CCP4_CaptureISR which is the MCC provided function which calls your myCCP4ISR function. You need to tell the compiler to call myCCP4ISR whenever a capture event occurs using the following configuration at the top of main in it's usual place.
    SYSTEM_Initialize();
    TMR0_SetInterruptHandler(myTMR0ISR);
    CCP4_SetCallBack(myCCP4ISR);
    INTERRUPT_GlobalInterruptEnable();
    INTERRUPT_PeripheralInterruptEnable();
Your myCCP4ISR should put the duration of the echo pulse into a global uint16_t variable "echoPulse". Every time that myCCP4ISR writes a new value into echoPulse, the ISR should also set a global variable "newSample" to true. main can poll the newSample variable to determine when a new echoPulse is available.

Our ultrasonic range finders have a tendency to occasionally generate an invalid echo pulse. I would like your software to filter out these invalid values as follows. Your program should gather 8 consecutive echo pulse durations into an array of uint16_t. After collecting 8 echo pulse durations in an array, sort the array, in decreasing order, using an algorithm like bubble sort. Do not use a complex set of if/then's to sort. Then go into this sorted array and choose the the middle element of the array (array index 3) as the echo pulse duration on which to base the parking assistant range value on. Choosing the middle element of the sorted list allows your code to ignore the occasional invalid pulse duration. And since the echo pulse durations are being generated at 10Hz there isn't much delay in taking 8 range measurements.

For example, my code collected the following 8 echo pulse durations, where two of the values where invalid. My algorithm returns the 3rd element of the sorted list (remember indexes start at 0) as the echo pulse duration to use for the parking assistant. In the case below this would be 33,224 timer counts. This range is used until another 8 echo pulse durations have been collected, sorted and the 3rd element selected.
Unsorted
33230    33231    33226    33221    33224    10984    10885    33227

Sorted
10885    10984    33221    33224    33226    33227    33230    33231
Your software should use the TMR0 roll-over interrupt to generate a 25us trigger pulse at exactly 10Hz.

Your program should use two PWM channels, one for the red LED and one for the green, to produce the parking assistant color patterns.

At start-up your program should present a splash screen - this would be a great place for some ascii art. The splash screen should also contain connection instruction for the development board (where to install jumper wires). For example, my program generates the following splash screen.
Development Board
Lab 13 terminal
RGB Connections:
    RC2:    Red
    RC1:    Green
Ultrasonic Connections:
    Vcc: left pin on JP1 header (closest to mini USB).
    Trig:   RC7
    Echo:   RB0
    GND:    GND header pin on PIC breakout header.
When you press "?" you should be greeted with the following menu.
------------------------------
echoPulse = 29638
distance = 247 cm
------------------------------
?: Help menu
o: k
Z: Reset processor
z: Clear the terminal
s: Stream Echo pulse length
S: Stream distance
c: collect and sort distances
C: convert distances to color
------------------------------

Turn-in

You may work with a single partner (or alone) to complete this lab. Submit your main.c file on Canvas using the instructions posted there. You should take note of the Rubric that will be used to evaluate your assignment. Please form a group before submitting using the instructions posted on Canvas. You will demonstrate your code at the beginning of lab.