PostLab 1 Quiz Digital Thermometer Digital Storage Oscilloscope
Post-Lab 1 Quiz Digital Thermometer Digital Storage Oscilloscope M. Smith, Electrical and Computer Engineering, University of Calgary, Canada smithmr @ ucalgary. ca
Modeling an audio channel using an ADSP 21061 processor z. Typical DSP algorithms y. Many memory fetches for data y. Many memory fetches for instructions y. Loop – often very tight y. Extensive multiplications and additions y. Real-time requirement – meaning must finish between successive interrupts or else lose samples (audio fidelity) 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 2
Modeling an audio channel using an ADSP 21061 processor 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 3
Post. Lab 1 Quiz z Digital oscilloscope display y Essentially the code from Lab. 0 but using a 40 Hz audio signal generated using Analog Devices TMP 03 – digital thermometer y “Oscilloscope” display using a modified TCL capability z Digital thermometer y Essentially the code from Lab. 1, but using a 40 Hz audio signal generated using Analog Devices TMP 03 – digital thermometer z Synchronized (stable) digital oscilloscope y Combination of first two parts of the quiz and assignment 2 z Timing report required y Looking at relative code efficiency between “C++” and your assembly language routine 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 4
Needed for Post Lab 1 Quiz z All the files required from Lab. 0 y www. enel. ucalgary. ca/People/Smith/2004 webs/encm 515_04/04 labs/04 Lab 0/requ ired_files_for_lab 0. htm y clanguage_register_defines. i -- Changes ADSP 21 O 6 X register names to something more readable – get the updated version from the web z All the files required for Lab. 1 y www. enel. ucalgary. ca/People/Smith/2004 webs/encm 515_04/04 labs/04 L ab 1/required_files_for_lab_1. htm y Your IIR filter must be modified to run using “real-time” points rather than an “off-line” predetermined array y You will also need the 21061 ON-LINE library (from Lab. 1 link) z Ear-phones z Analog Devices TMP 03 digital thermometer + documentation z Some of this quiz is done with your laboratory partner – some done on your own 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 5
Essence of “main. c” void main ( ) { int channel 1_in, channel 2_in; // Input channels int leftchannel_out, rightchannel_out; // Output channels int processor = PROCESSOR; // Auto defined #define SOURCE_DESCRIPTION OFFLINE_AUDIOSOURCE | IMPULSE | MONO; int which_soundsource = SOURCE_DESCRIPTION; ADISound. Source sounddemo (processor, which_soundsource, processing_options); // Get the sound samples while(sounddemo. Read. Source(&channel 1_in, &channel 2_in)) { sounddemo. Stop_Audio. Interrupts(); // Don't forget to turn interrupts back on Known. Location. For. Break. Point(); // Needed for running some TCL tools Volume. Control(&channel 1_in, &channel 2_in, &sounddemo); // Checks to see if button FLAG 1 is pressed on the board. if (!sounddemo. Do. Not. Process()) Process. Sound(channel 1_in, channel 2_in, &leftchannel_out, ……. else { leftchannel_out = channel 1_in; rightchannel_out = channel 2_in; } sounddemo. Start_Audio. Interrupts( ); // Restart the interrupts // Write the sound samples sounddemo. Write. Source(leftchannel_out, rightchannel_out); } ENCM 515 -- Post Lab 1 Details } 9/10/2021 6 Copyright M. Smith -- smithmr@ucalgary, ca
Essence of “main. c” // Get the sound samples while(sounddemo. Read. Source(&channel 1_in, &channel 2_in)) { sounddemo. Stop_Audio. Interrupts(); Known. Location. For. Break. Point(); Volume. Control(&channel 1_in, &channel 2_in, &sounddemo); // Checks to see if button FLAG 1 is pressed on the board. if (!sounddemo. Do. Not. Process()) Process. Sound(channel 1_in, channel 2_in, &leftchannel_out, ……. else { leftchannel_out = channel 1_in; rightchannel_out = channel 2_in; } sounddemo. Start_Audio. Interrupts( ); // Write the sound samples sounddemo. Write. Source(leftchannel_out, rightchannel_out); } 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 7
Arrays available z. Input_channels 1 and 2 yused to provide known signals to the Read. Source( ) method – both offline and online libraries z. Left_channel and Right_channel yused to provide a location to store Write. Source ( ) method output – offline only z. Embedded systems – typical memory poor – so re-use arrays when possible 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 8
Essence of Process. Sound( ) void Memory. Move_Delay_CPP(int *channel 1_in, int *channel 2_in, ……); extern "C" void Memory. Move_Delay_ASM(int *channel 1_in, int *channel 2_in, …); void Over. Simple. IIR_CPP( float iir_coeff, int *channel 1_in, int *channel 2_in); extern "C" void Over. Simple. IIR_ASM( float iir_coeff, int *channel 1_in, …. ); #warning "All audio processing algorithms currently performed in High Level language #define Over. Simple. IIR(PAR 1, PAR 2, PAR 3) Over. Simple. IIR_CPP(PAR 1, PAR 2, PAR 3) #define Memory. Move_Delay(PAR 1, PAR 2, PAR 3) Memory. Move_Delay_CPP(PAR 1, P void Process. Sound(int channel 1_in, int channel 2_in, int *leftchannel_out, int *rightchannel_out, ADISound. Source *sounddemo ) { if (sounddemo->Getprocessoroptions() & OVERSIMPLEIIR) Over. Simple. IIR(/* IIR_COEFF = */ 0. 1, &channel 1_in, &channel 2_in); if ((sounddemo->Getprocessoroptions() & MOVEDELAY) == MOVEDELAY) { Memory. Move_Delay(&channel 1_in, &channel 2_in, sounddemo); *leftchannel_out = channel 1_in; *rightchannel_out = channel 2_in; } 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 9
Essence of audio algorithm static float left_delayline[FIFO_LENGTH] = {0}; static float right_delayline[FIFO_LENGTH] = {0}; void Memory. Move_Delay_CPP(int *channel 1_in, int *channel 2_in, ADISound. Source *sounddemo) { int count; // Insert new value into the back of the FIFO delay line left_delayline[0 + LEFT_DELAY_VALUE] = *channel 1_in; // Grab delayed value from the front of the FIFO delay line *channel 1_in = left_delayline[0]; // Update the FIFO delay line using inefficient memory to memory moves for (count = 0; count < LEFT_DELAY_VALUE; count++) left_delayline[count] = left_delayline[count + 1]; } IIR Filter is your code from Lab. 1 modified for single point real-time operation 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 10
Test 1 – IIR filter test z Design and test your “OFF-LINE” code – offline. dlb y y NOTE: “OFF-LINE” means that you are linking with the offline library using a known signal It does not necessarily mean that you are running with the simulator. You can run with the real-board if you want and can get access to the lab. Required test 1) 2) 3) 4) 5) 6) 7) 9/10/2021 Show that your IIR low pass and IIR high pass filter works using the SQUARE-WAVE off-line source IIR low pass output into left channel IIR high pass output into right channel De-activate delay at this time Display on plot routine – capture onto clip board using “Print -screen” key and paste into. doc file Provide code for your low pass and high pass filters High pass filter should be implemented by calling low-pass filter routine and then subtracting low pass output from original signal ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 11
Sample test result 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 12
Test 2 – Impulse the High-pass signal Once the processing of the input array has stopped z Write a routine that checks for the maximum and minimum values of an array z Call the routine to determine maximum and minimum values of IIR high pass output z Write a routine that uses the maximum and minimum values as follows z For each point in array if value < 98% of max and value > 98% of min then value is 0 else value is unchanged unless the previous value is not 0 z The output of this routine is a series of positive and negative pulses that correspond to the sharp rising and falling edges of the input signal 1) Display on plot routine – capture onto clip board using “Print -screen” key and paste into. doc file 2) Provide code for determine max / min and “impulsification” routines 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 13
Temperature Calculation T 1 T 2 z. Centigrade = A 1 – B 1 T 1 / T 2 z. Fahrenheit = A 2 – B 2 T 1 / T 2 z. T 1 essentially constant – check formula from chip documentation 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 14
Test 3 z Using the impulse version of the IIR filter calculate an average of five T 1 and T 2 values z Calculate the temperature (to an accuracy of 0. 25 degrees) in both Centigrade and Fahrenheit z Store in external variables z Modify the TCL file so that you have a menu item that will allow you to display these memory values 1) Capture onto clip board using “Print-screen” key and paste into. doc file 2) Provide code for determining average AND TCL changes 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 15
Code developed during Assignment 2 void Find. Max. Min (long int *array_IN, long int num_points_array_IN, long int *max_value, long int *min_value) Returns the largest and smallest value in the array_IN void Binarize. Signal (long int *array_IN, long int *array_OUT, long int num_points_array_IN, long int min_amplitude) e. g input -1, 2, -4, 3, 5 with min amplitude of 4 becomes 0, 0, -4, 0, 5 long int Find. First (long int *array_IN, long int num_points_array_IN) returns the array position of the first non-zero element of the array_IN void Reposition. Array (long int *array_IN, long int *array_OUT, long int num_points_array_IN, long int postion) Returns the array_OUT where array_OUT[N] = array_IN[N + position] 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 16
Test 4 – Positioning the signal z y y You have 1. 2. 3. Low-pass filter signal in left-channel array High-pass filter signal in right-channel array Impulse signal in input 2 channel array 1) Capture before and after onto clip board using “Print-screen” key and paste into. doc file Provide code for determining identification and repositioning algorithm Write a routine to identify when the first negative signal appears in the impulse signal channel Use that information to reposition the low-pass filter signal so that the first negative value of the low-pass signal is at location 10 in the array 2) y y Developing and testing this code (In C and assembly code) is going to form assignment 2 This code will also be used during Laboratory 2 and 3 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 17
Real-time code z. We have the following routines – and are going to use them for a real-time digital oscilloscope 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 18
Quick Test of TMP 03 z Basically – 3 pins y +5 V y GND y Output +5 V GND SIGNAL z These are new I/O boards and have not been tested – voltage wise z Hook up the boards – and connect output to oscilloscope and check that output voltage is no more than 1 V peakto-peak with small DC offset z If too far from this, check with Warren z Warning the “potentiometer” on the board is very fragile – self destructs after 10 changes – leave it to Warren 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 19
Temperature Calculation z Test by warming with your hands – examine on the scope T 1 T 2 z Centigrade = A 1 – B 1 T 1 / T 2 z Fahrenheit = A 2 – B 2 T 1 / T 2 z T 1 essentially constant – check formula’s accuracy from chip documentation 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 20
ICE hardware TAKE CARE -- THESE ARE VERY EXPENSIVE PROBES -- I want to use them for a number of years! z Look at the set-up for Lab. 1 for the care and handling of the ICE hardware 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 21
Quick test of ONLINE. DLB z. Using project and files from Lab. 0 z. Link project with on-line. dlb rather than off-line. dlb z. Recompile with –D LOCAL_AUDIOTEST compiler option z. Test – you should hear an audio tune with the sound source “placed” nearer your right ear because of “audio delay” z. Press the FLAG 1 button on the board to remove processing 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 22
Quick test of ONLINE. DLB z Recompile with –D CODEC_AUDIOTEST compiler option z Test – Use a radio or CD input you should hear an audio tune with the sound source “placed” nearer your right ear because of “audio delay” z Press the FLAG 1 button on the board to remove processing z Proceed -- provided TMP 03 volume (amplitude) is not too large y Use the TMP 03 as an audio signal (around 40 Hz) y Display both the left and right output channel on an oscilloscope y Expect some minor distortion in the square wave as the audio input is AC, rather than DC, coupled to the CODEC. However watch out for overload as this will cause the algorithms to fail. Volume adjust on output? y The left channel output should be delayed by 40 sample periods (@ 44 k. Hz) 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 23
Digital Thermometer z You will need to run with the CODEC source activated z You will need to capture 1/10 s of the squarewave signal from the digital thermometer output to guarantee that you get at least two full cycles z You can’t store that amount of information – assume that the maximum available array size is 512 points z Calculate the input decimation rate (downsampling) necessary so that you can store the required signal 1. Report on your calculation 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 24
Real-time temperature guage z. In a loop y. Capture two cycles of the digital thermometer signal y. Apply the high pass filter, and “impulsify” the signal using the routines you have developed y. Calculate and display the temperature z. Warm the temperature gauge with your hands to check that it works z. This is a “batch” style of operation – see Assignment 2 for more details 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 25
Real time oscilloscope z In a loop y. Capture two cycles of the digital thermometer signal y. Apply the high pass filter, and “impulsify” the signal using the routines you have developed y. Use your adjusting subroutine so that the “digital thermometer” signal is placed in the same position in the array z Show the stable signal in a plot window, and demonstrate that the oscilloscope works by warming thermometer and see the changes in pulse width (or is the resolution too small? ) 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 26
Final documentation z All the required code previously discussed Together with ethics statements, the final working code and screen dumps from the plot and temperature windows running in real time z Some of the routines should be running in assembly code – see assignment 2 z Due at the start of the lecture on the Friday when you have your Lab. 2 start – but will accept up to 1 week later if you have time constraints but have participated in class discussions 9/10/2021 ENCM 515 -- Post Lab 1 Details Copyright M. Smith -- smithmr@ucalgary, ca 27
- Slides: 27