Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hello attached is a various pictures for an assignment. the flowchart shows what the code should be doing. please use C, c++, to code the

hello attached is a various pictures for an assignment. the flowchart shows what the code should be doing. please use C, c++, to code the assignment. all the information is provided .

image text in transcribed

image text in transcribed

image text in transcribed

TODO: Design the code above. NOTES: - Recall that the TRIG is connected to the PIN PAO. To send the chirp, you need to set TRIG to HIGH (TTL level) for at least 10 microseconds. Recall that, to set an output port PAO with HIGH, you must use the function HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0,GPIO_PIN_SET). And to set the PAO to low, use GPIO_PIN_RESET. Note: The STM 32L476 HIGH level is at least 2.9V, which is above the minimum level for the HIGH TTL level. - To measure the duration of the echo, you will need to monitor the state of the ECHO signal. Recall that the ECHO is connected to the PIN PA1 and it will switch from LOW to HIGH as soon as the chirp is sent and will switch from HIGH to LOW as soon as the echo arrives. (See figure in the first page of the document). - For this stepping stone code, you can simply write a while loop that monitors the state of the PIN PA1 (see more details in the next paragraph). - Use TIM16 to measure the time of the ECHO signal. For this: a) start the timer outside the infinite for (;;) loop. For this, use the function HAL_TIM Base_Start (\&htim16) ; b) Before any of the ECHO signals starts, reset the TIM16 timer with HAL TIM_SetCounter ( \&htim16,0);. c) Use a while loop to monitor the state of PIN PA1 and, as soon as the PA1 becomes HIGH, read the value of timer with HAL TIM_GET_COUNTER ( ghtim16). This function returns a uint16 t type. Store the value in a uint16_ t variable N_start. d) Use another while loop to monitor the state of PA1 and, as soon as it becomes LOW, read its value and store it in another uint16 t variable \( N_{\text {_ end. }} \). The echo duration in microseconds will be Nend N start. - Use a "double" type variable to report the average. - IMPORTANT: the "printf" in the STM32 library cannot print doubles or floats. Thus, round it to an integer. You do this by adding 0.5 to the double variable and casting it to an integer. C. 4) c) Compile and test your code in the debugger as in previous labs. Verify that the code is reporting measurements that change with the distance between the sensor and an object. Try different distances to see if the echo duration reduces with nearby (510cm ) target and increases with far away targets (up to 50cm ). C.4)-d) TODO: Change your code so that the measurements are started only after the user presses the button B1. Make it timeout with 5 s and print the message: "TaskCollectMeas: Waiting for user to press button." Notes: - Use the MeasTokenSemaphore that we defined. Your code should wait on the semaphore before starting the sequence of 10 echo measurements. - IMPORTANT: Check the return value of osSemaphoreAcquire!! - Recall that the button B1 is connected to the Pin PC13, which is configured to generate an interrupt! To treat the interrupt, you will have to add the Interrupt Service Routine HAL_GPIO_EXTI_Callback as shown below. Add it in between the /* USER CODE BEGIN 4/ and / *SER CODE END 4 - IMPORTANT: Recall that semaphores can be used not only to control the access of a resource, but also to trigger other tasks! In here, the semaphore is used to trigger the TaskCollectMeas!! Thus, in TaskCollectMeas do NOT release the semaphore! In other words, in here, the semaphore is released only by the Interrupt Service Routine HAL_GPIO_EXTI_Callback() and taken only by the TaskCollectMeas !! - OPTIONAL: you may add code for button debouncing (similar to a previous lab)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

What were some tough decisions you had to make at your last job?

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago