Engineering H192 - Computer Programming Software Design Project Lecture 29 Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 1 Engineering H192 - Computer Programming ENG H192 Software Design Project • Problem: Detect frequency of IR transmitter • Two-person teams will -– Design – Code – Test – Document • Teams will be provided -– Handy Board – Sharp GP1U5 IR receiver – Access to IR transmitter beacon Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 2 Engineering H192 - Computer Programming The Handy Board Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 3 Engineering H192 - Computer Programming The Sharp GP1U5 IR Receiver Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 4 Engineering H192 - Computer Programming General Description • Your software must detect each of five (5) possible frequencies of transmitted IR light • Frequency detected must be displayed on Handy Board LCD screen • Frequencies will in the range of 20 to 150 Hz • No frequency will be closer than 20 Hz to any other possible frequency • Transmitted frequency will change automatically and randomly to one of the other possible frequencies Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 5 Engineering H192 - Computer Programming IR Transmission and Reception • Program should continuously detect frequency of the transmitting beacon • Handy Board screen should display received frequency in Hertz as an "integer" value • Only one of the specified frequencies (or 0) should be displayed 6 to 12 inches IR Receiver Winter Quarter IR Transmitter Gateway Engineering Education Coalition Lect 29 P. 6 Engineering H192 - Computer Programming The IR Beacon Signal IR Beacon Signal X X X X X X X 0 X 1 X X X X X X X X X X X X "Digitized" copy of signal Time Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 7 Engineering H192 - Computer Programming A Possible Approach • Take a number of measurements of the received signal at regular intervals • Determine how long it took to take those measurements • Analyze set of measurements • Display appropriate frequency • Repeat Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 8 Engineering H192 - Computer Programming Useful Handy Board Functions • digital (p) -- Returns the value of the sensor connected to digital port "p" as a true/false value. – The parameter "p" should be in the range of 7 through 15, matching port to which receiver is connected – Note that "true" = zero volts, which is sometimes called "active low" • start_button ( ) -- Returns the value of the start button. "True" when button is pressed. Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 9 Engineering H192 - Computer Programming Useful Handy Board Functions • stop_button ( ) -- Returns the value of the stop button. "True" when button is pressed. • mseconds ( ) -- Returns a long integer value representing the system time in milliseconds. – Like the seconds ( ) function, but data type of returned value is long & units are milliseconds • reset_system_time ( ) -- Resets the count of system time to zero milliseconds. Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 10 Engineering H192 - Computer Programming Interactive C • Remember, there are things that are different in IC (compared to ANSI C): – No function prototypes – Limited formats possible in printf – Array bounds checked at run time – No #include statements – Smaller set of allowable data types -- only int, long, float, char, and struct (v3.2 only) – Character strings are supported, but simple char variables are not Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 11 Engineering H192 - Computer Programming Interactive C • More things that are different in IC (compared to ANSI C): – No switch/case construct – Can only do +, -, and * on long int – All source files must be compiled together – #define has global scope – User functions come first in source file – No do/while construct – No mixed mode arithmetic Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 12 Engineering H192 - Computer Programming Design Project "Deliverables" • List of brainstorming ideas • Neatly written algorithm and/or flow chart of userwritten functions • Documentation package which includes: – A description of the program for use by developers, complete with a list of variable names and uses – A description of the program for use by a general user with an abstracted discussion of the program. Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 13 Engineering H192 - Computer Programming Receiving in a "Noisy" World • Real world communications are affected or "degraded" by noise, for example: – Normal conversations in a busy public place – Cell phones in fringe reception areas ("Can you hear me now?"™) – AM radio stations during thunderstorms • Often measured as a "signal-to-noise" ratio which is usually called SNR • Almost all forms of communication are range dependent -- longer range => lower SNR Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 14 Engineering H192 - Computer Programming Receiving in a "Noisy" World • The IR transmitter and receiver system we are using is "range dependent" – How does light intensity vary as a function of distance? • IR receiver "drops out" if transmitted signal is too weak – What does "drops out" mean? • Can we improve our ability to "see"? Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 15 Engineering H192 - Computer Programming The "Noisy" IR Beacon Signal IR Beacon Signal 1 0 X X X X X X X X X X X X X X X X X X X X X X X X X "Digitized" copy of signal Time Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 16 Engineering H192 - Computer Programming A Possible "Noisy" Approach • Take a number of measurements of the received signal at regular intervals • Determine how long it took to take those measurements • Analyze set of measurements and ignore periods that are shorter than average • Compare results of several sets (Steps 1 - 3) • Display appropriate frequency • Repeat from beginning Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 17 Engineering H192 - Computer Programming Possible Programming Pitfalls • Failing to use global variables, particularly for medium or large arrays • Scarcity of comments in code (comments don’t take any memory space) • Improper use of Handy Board functions • Not using modular approach to designing code • Too much floating point arithmetic • Too much code – exceed memory of Handy Board Winter Quarter Gateway Engineering Education Coalition Lect 29 P. 18