Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hardware Setup and 1/0 - Use three momentary switches (or one multi-way switch) to drive speaker SP1 from a GPIO output (labeled Audio below). Capacitor

image text in transcribed

Hardware Setup and 1/0 - Use three momentary switches (or one multi-way switch) to drive speaker SP1 from a GPIO output (labeled Audio below). Capacitor C1 should be used to block DC current. Resistor R1 is optional and reduces the volume of the sound. Fra Up Play RI (opt) C! Hot Hot Audio Fra Down 339 Figure 1. Schematic diagram Write C code to do the following: The tone of the speaker should sound when SW2 is pressed down. The frequency value of the tone should rise while SW1 is pressed. The frequency value of the tone should fall while SW3 is pressed. The following software design is suggested: Create an initialization function which configures GPIO inputs and outputs based on which pins you have wired to your switches and speaker. Create and calibrate a delay-loop function Delay_us(unsigned int time_del) which creates a delay of approximately "time_del" microseconds. Tune your delay loop through experimentation. (Hint: The delay loop will be a simple while or for loop that performs no useful operation. This simply uses the clock frequency of the processor to determine the delay. It is incredibly imprecise, but it is close enough for our use right now.) Create a function Play_Tone(unsigned int period, unsigned int duration) which generates a square wave with the given period (specified in microseconds) and duration (milliseconds). This can be done by toggling the audio output pin, waiting for a time delay, and repeating this process. Calculate the necessary time_del value to pass to Delay_us based on period (inverse of frequency). Calculate the number of times to toggle the output based on period and duration. Create a function Slide_Whistle(void) to repeatedly check to see if any switches are pressed and respond accordingly. If SW1 or SW3 is pressed, adjust the period accordingly. Limit the value of period to within 25 microseconds and 2,500 microseconds. If SW2 is pressed, call Play_Tone() with the current period and duration of your choice. The processor executes this loop very quickly if SW2 is not pressed, so the value of period will quickly reach the upper or lower limit if SW1 or SW3 is pressed. To slow the code down, call Delay_us(e.g. for 1000 microseconds). Hardware Setup and 1/0 - Use three momentary switches (or one multi-way switch) to drive speaker SP1 from a GPIO output (labeled Audio below). Capacitor C1 should be used to block DC current. Resistor R1 is optional and reduces the volume of the sound. Fra Up Play RI (opt) C! Hot Hot Audio Fra Down 339 Figure 1. Schematic diagram Write C code to do the following: The tone of the speaker should sound when SW2 is pressed down. The frequency value of the tone should rise while SW1 is pressed. The frequency value of the tone should fall while SW3 is pressed. The following software design is suggested: Create an initialization function which configures GPIO inputs and outputs based on which pins you have wired to your switches and speaker. Create and calibrate a delay-loop function Delay_us(unsigned int time_del) which creates a delay of approximately "time_del" microseconds. Tune your delay loop through experimentation. (Hint: The delay loop will be a simple while or for loop that performs no useful operation. This simply uses the clock frequency of the processor to determine the delay. It is incredibly imprecise, but it is close enough for our use right now.) Create a function Play_Tone(unsigned int period, unsigned int duration) which generates a square wave with the given period (specified in microseconds) and duration (milliseconds). This can be done by toggling the audio output pin, waiting for a time delay, and repeating this process. Calculate the necessary time_del value to pass to Delay_us based on period (inverse of frequency). Calculate the number of times to toggle the output based on period and duration. Create a function Slide_Whistle(void) to repeatedly check to see if any switches are pressed and respond accordingly. If SW1 or SW3 is pressed, adjust the period accordingly. Limit the value of period to within 25 microseconds and 2,500 microseconds. If SW2 is pressed, call Play_Tone() with the current period and duration of your choice. The processor executes this loop very quickly if SW2 is not pressed, so the value of period will quickly reach the upper or lower limit if SW1 or SW3 is pressed. To slow the code down, call Delay_us(e.g. for 1000 microseconds)

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

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

Students also viewed these Databases questions