Sunteți pe pagina 1din 9

5.

Creating a Two Channel Oscilloscope (part 1)


In the Instrument Launcher we can choose a lot of instruments, e.g. the two channel oscilloscope. This oscilloscope works fine in most situations. However, sometimes you want to add some extra functionalities. In order to understand the working of a standard oscilloscope and to be able to make a dedicated oscilloscope if needed we will end this course making a two channel oscilloscope. A lot of programming principles will be needed. In the exercises you will learn to work with them. In the final assignment all these principles will be combined and used. Of course, like with any other programming language, your program should be well structured. And for efficiency reasons we will first make a one channel oscilloscope. Using Express VIs is forbidden. Only for the input (DAQ Assistant) and the output (XY-graph) you may use Express VIs. All the other manipulations will be done with plain 1D arrays, without any timing information in it, without DDT-lines. To become (more) familiar with array manipulations, we will start with some exercises with them.

Exercise 5.1: Array manipulations


Start Help (Help, Show Context Help or Ctrl+H) Now a little window will appear on your screen giving some short information about a block when you move your mouse over that block. Open the Array Functions Palette (Functions, Programming, Array). Examine all the functions in this palette carefully and try to understand their purpose. We will use some of them now. First, we have to create an array. We did this already once, using a For Loop. Now we will use the Simulate signal (this is more copy of exercise 4.1, with some minor modifications) 1. 2. 3. 4. 5. 6. 7. 8. 9. Start LabVIEW Start a Blank VI Tile left and right (Window, Tile Left and Right or Ctrl+T) Place Simulate Signal (Functions, Express, Input, Simulate Signal) You will get a screen with an example signal Change the Frequency to 21 Hz Change the Number of samples to 101 (deselect Automatic) Leave the rest unchanged and click OK Connect a graph indicator to the data output of Simulate Signal (right click on the output, Create, Graph Indicator) 10. Put a while Loop around your program 11. Test and try your program 12. You will see a moving sine and an X-axis having 101 values, this is because we have chosen a array size of 101 points (why?). The sample frequency is 1 kHz, so we will see 0,1 seconds each time. With the chosen frequency of 21 Hz, we will
MMSp Assignment 5 One channel oscilloscope -1-

see approximately 2 periods. Because the two periods do not fit exactly in this 101 points, we see the signal moving. 13. Now we will extract the array information from the Dynamic Data line (use From DDT, 1D array of scalars) 14. Connect a graph to this signal 15. Test and try your program and see the difference between the two graphs This array will be used now to do some experiments or exercises 16. Check the function of Array Size 17. Check the function of Index Array (connect the original array, connect a control to Index, connect an indicator to Element) 18. Because the program is running so fast, it will be difficult to see this, but you can stop the program to freeze the information 19. Check the function of Array Subset (connect the original array, connect a control to Index, use a Graph to see the result, dont connect Length: default the rest of the array will be taken then). This is a general rule: if you do not connect an input of a block, the default value (given between brackets) will be taken. Note: all bold variables in the Context Help must be connected. 20. Now do connect a constant to Length (e.g. 41). 21. Check the function of Array subset again 22. Check the function of Array Max & Min (perhaps you used it already) 23. Check the function of Search 1D Array (connect a control to Element and an indicator to Index) 24. Search for 0 and for 0,5: you will get -1, which means: not found, why? Alas, the Search function will not be able to find a trigger point for our (future) oscilloscope, but we will use this function later. 25. Check the function of Threshold 1D Array (connect a control to Threshold y and an indicator to Fractional Index or x) 26. Search for 0 and for 0,5: you will get a number, but many times you will get 0 If the fractional index is 21,4287 for example, this means that the value at index 21 is below the threshold and the value at index 22 is above the threshold. Only crossings from below to above the threshold are detected this way. But if the first value (at index 0) is above the threshold the result will be 0. So, this function will also not be able to find a stable trigger point. 27. Check this At this point we have investigated the most important functions in the Array Palette.
MMSp Assignment 5 One channel oscilloscope -2-

Exercise 5.2: The Time Base


The purpose of an oscilloscope is to make (periodic) signals visible on a graph. In order to make these signals look good we should at least have 10 points per period of the signal (rule of thumb). The maximum sampling rate of the myDAQ is 200 kHz. So the maximum frequency of a signal to be seen good with our oscilloscope will be 20 kHz. It is good practice (rule of thumb) to show 2 periods of the signal on the graph. In this case we will show 21 (20 + 1, why?) sampling points: the length of the array to be shown must be 21. The total time of the X axis in this case will be 100 s (check!). If we use 10 divisions along the X axis the time/div will be 10 s. If the signal to be seen has a frequency of 10 kHz, we get a better picture because now we have 20 samples per period available (at the same maximum sampling rate). To show two periods now we need an array of 41. The total time will now be 200 s, so time/div = 20 s. The X axis will be controlled by a (select)knob called time/div. If we use the same sampling frequency for all signals this knob should control the array length. Fill in the table below (at a constant sampling rate of 200 kHz). Signal frequency 20 kHz 10 kHz 4 kHz Period time 50 s 100 s 250 s Total time on graph 100 s 200 s 500 s Time/div Number of samples 10 s 21 20 s 41 50 s 100 s 200 s 500 s 1 ms 2 ms 5 ms 10 ms 20 ms 50 ms

4 Hz

250 ms

500 ms

MMSp Assignment 5

One channel oscilloscope

-3-

Of course we can go on like this, making an oscilloscope for very low frequencies. But doing so we will meet a problem: the array length, the number of samples which is stored in a register on the myDAQ is limited. On the other hand, it is not useful or necessary to show a signal on a graph made out of so many points: the resolution of the screen is too low to see it anyway. So, as a rule of thumb, we choose the array length to be maximum 1001 points. In order to get the desired total time on the screen, we now have to lower the sampling rate. For example, to get a total time of 500 ms in 1000 time steps (1001 samples), we need a sampling rate of 2 kHz (check!). Now, fill in the table below, taking into account the considerations above. Signal frequency 20 kHz 10 kHz 4 kHz Period time 50 s 100 s 250 s Total time on graph 100 s 200 s 500 s Time/div 10 s 20 s 50 s 100 s 200 s 500 s 1 ms 2 ms 5 ms 10 ms 20 ms 50 ms Length 21 41 Rate 200 kHz 200 kHz

4 Hz

250 ms

500 ms

1001

2 kHz

Check the procedure above using a Simulate Signal as signal source, adjust the Frequency, the Number of samples and the Sampling rate following the table above. Remove the DDT information from the data, using From DDT, to get a plain array and show the array on a Graph. In all cases you should see 2 periods of the signal. You should check all or some of the situations from the table (randomly chosen).

MMSp Assignment 5

One channel oscilloscope

-4-

Exercise 5.3: Controlling the DAQ Assistant


We use the DAQ Assistant in order to get data. We have seen that we want to control (change) the Sampling rate and the Number of samples (depending on the time/div) while the oscilloscope program is running. 1. First, connect you myDAQ 2. Start LabVIEW 3. Start a Blank VI 4. Place the DAQ Assistant in your diagram 5. Choose Acquire Signals 6. Choose Voltage 7. Choose ai0 8. Click Finish. 9. Choose Continuous Samples 10. Click OK 11. The next screen appears

12. Click Ja (Yes) 13. Connect a Graph to the data line of the DAQ Assistant (use From DDT!) When you enlarge the DAQ Assistant a number of inputs and outputs become visible. We will do some experiments with them. 14. Connect a control to number of samples and rate 15. Apply a signal to analog input 0 16. Test your program, check if the two controls change the number of samples and the rate while the program is running

MMSp Assignment 5

One channel oscilloscope

-5-

You will notice that number of samples works fine, but rate doesnt 17. Press the stop button 18. Start the program again You will notice that rate now can be changed too. Of course this is not what we want: stopping and starting the program when we want to change the rate. You can see in the diagram that if we press the stop button, not only the DAQ Assistant will stop, but also the While Loop. 19. Remove the (green) line between stopped and the condition terminal of the While Loop 20. Add an extra stop button to control the While Loop 21. Test your program, check if the two controls change the number of samples and the rate while the program is running, by stopping and starting the DAQ Assistant

MMSp Assignment 5

One channel oscilloscope

-6-

This way of changing the rate is not convenient. We want to make this automatically. We want to stop the DAQ Assistant when the rate has to be changed and after that start the DAQ Assistant again. To do this we want to check if the rate has to be changed. We use a Shift Register for this purpose. A Shift Register will pass values of variables from one loop to the next. 22. Place a Shift Register on the While Loop (Right click on the right border of the While Loop: Add Shift Register

Two little black block appear on the While Loop. You can send a value of a signal to the right block. The next time the loop executes, this value appears in the left block. So, it will be possible to check if there is a change in that variable. Is the new value different from the last one? If so, we will have to stop the DAQ Assistant. If not, we dont. 23. Remove the stop button of the DAQ Assistant 24. Connect rate to the right block of the Shift Register 25. Place a comparator to check if there is a change and connect the new and the old (last) value of rate 26. Connect the output of this comparator to the stop input of the DAQ Assistant Doing this, the DAQ Assistant will be stopped as soon as there is a change in rate. In the next loop, the new and value will be equal again, so the DAQ Assistant will be started again.

MMSp Assignment 5

One channel oscilloscope

-7-

27. Test your program,

MMSp Assignment 5

One channel oscilloscope

-8-

Assignment 5
Make an one channel oscilloscope Specifications: 1. One channel 2. No Express VIs allowed, except one DAQ Assistant 3. Use plains arrays (use From DDT immediately after the DAQ Assistant) 4. Use a Graph to show the result (let the X axis visible) 5. Free running (no triggering function yet) 6. Time/div functionality ranging from 10 s to 50 ms, following the procedures in exercises 3.1, 5.2 & 5.3 7. Volt/div functionality (2, 1, 0.5, 0.2, 0.1, 50m, 20m, 10m, 5m, 2m, 1m), following the procedure in exercises 3.1 and assignment 3 8. Position functionality (vertical shift), following assignment 3. Test your design, by applying a signal to the myDAQ, use: 1. a desktop function generator or 2. the function generator from the instrument launcher or 3. the function generator you made yourself in exercise 4. When finished, show the result to the teacher: demonstration required!

MMSp Assignment 5

One channel oscilloscope

-9-