Using the Analog in and LCD, turn the MBED into a simple Oscilloscope

Dependencies:   C12832_lcd DebounceIn mbed

/media/uploads/trichards1138/snapshot_20140609.jpg /media/uploads/trichards1138/snapshot_20140609_2.jpg

Introduction:

The MBED Oscilloscope uses the Analog Input on pin 17 to display connected waveforms from another MBED or a function generator. Note that the above left photo shows the Ain 1/8" phone jack on the side of the MBED being used as the input for a function generator. The crude photo on the right shows the waveform displayed on the MBED LCD screen (this is using the Application board available to plug the MBED processor board into. It includes the LCD screen as well as buttons, pots, temperature sensor, wifly socket, speaker, etc).

The waveform that is displayed on the MBED Oscilloscope is: /media/uploads/trichards1138/waveform.jpg This is from a Digilent combination function generator, Oscilloscope, and logic analyzer. The arbitrary waveform generator shown is one of the features of the unit and allows output of several types of signals from its analog output.

Notice that the frequency is set to 1kHz. The MBED Oscilloscope is set to 512 uS per division (due to display limitations, the settings cannot be displayed with the waveform). The displayed waveform shows a complete period in approximately 2 divisions. The scope is indicating that the period is 1mS or 1kHz.

Capabilities and Limitations:

The scope can display waveforms up to 5kHz with some clarity (although 5kHz is pushing its resolution 2-3kHz is a good practical limit). For displaying waveforms from a function generator running on another MBED, this is not a significant limitation. Except for the square-wave function, the function generator output of the MBED is around 1kHz realistically (the square-wave can output much higher frequencies since it only has two levels). (NOTE: this limitation is not strictly due to the ADC input. it also has to do with loop delay i.e. display update times...etc)

When an input is configured as an Analog input to the ADC, it is not 5V tolerant. The voltage on the pin must not exceed the reference-voltage-plus (set to approx 3V on the MBED board). So the amplitude input is limited to 3V (Although I've input signals at 3.3V with no immediate issues). Again this is not a significant limitation if debugging signals from another MBED. However, if you are using an external function generator, you must ensure you do not overdrive the input.

Usage:

Using the scope is fairly straight forward. Once you have the waveform source connected to pin 17 (either via the 1/8" phone jack or a wire directly connected to p17 through the header), the waveform should be displayed.

To change the time-base, use the right and left joystick buttons. You can check the current setting by pressing the middle button of the joystick. As long as you keep the middle button pressed, the settings page will be displayed. It shows the current settings of the time-base, vertical or volt-base, and the trigger mode. The photo below shows the settings page: /media/uploads/trichards1138/snapshot_20140609_8.jpg

Again, I apologize for the crudeness of the photo (a photographer I am not). Note that the time-base will change based on whether the grid is turned on. In the first photo above you see the grid lines painted on the display. You have the option to turn those off and there are instances where it is desirable. When this is done, the entire horizontal screen is viewed as one division. So the time-base will change accordingly.

Once you release the center button, the display will return to the waveform screen after about a second. If however you press the center button again within that window, you will be taken to the trigger selection window: /media/uploads/trichards1138/snapshot_20140609_9.jpg

There are five trigger modes:

1. Rising-Edge Main Signal (this finds the rising edge on the signal connected to pin 17)

2. Falling-Edge Main Signal (Same as above but finds the falling edge)

3. Rising-Edge Ext Signal (this finds the rising edge on the signal connected to pin 18)

4. Falling-Edge Ext Signal (Sam as in 3 for falling edge)

5. Auto or No Trigger (this does not look for a trigger - useful for dc signals)

Note that only three modes are displayed on the screen. The screen will scroll as you move the selection down. This is done with the "up" and "down" buttons on the joystick. Make your selection by pressing the center button again.

Once you make your trigger selection, you will then be taken to the grid selection menu: /media/uploads/trichards1138/snapshot_20140609_10.jpg

This allows the choice of whether to display the grid. Again there are situations you may want to disable the grid. Make the grid selection in the same way by pressing the center button of the joystick.

Once this selection is made, you will return the the waveform display.

The only additional control it connected to pot2. This is the pot furthest from the display. It controls the trigger level.

Know Issues:

1. The External triggering is not working at all right now. For some reason having two active signals connected to two different ADC inputs causes crosstalk that distorts both signals. I haven't looked into this yet so avoid using external triggering for the present. I will update when and if it is fixed. (any input or pointers would be appreciated)

2. The time base needs to be calibrated a little better. It is pretty close in most cases and good enough for rough work, but you would not want to keep time with it. It is a little like whack-a-mole and may never be perfect, but it can be improved.

3. The timeouts for the triggering mechanism may need some tweaking at some point as well. I think it is pretty good but may cause some fringe problems.

4. The trigger level is not currently displayed anywhere and should be part of the settings page. This would need to be added to a second settings page (and the menu system might get cumbersome at some point).

5. The pot is a little jittery for the trigger level. However, adding another menu to set it with the joystick will further push the problem in 4 of the menu system getting cumbersome. It may be good enough with some tweaks.

Future enhancements:

1. Getting the external triggering working is the first order of business.

2. Getting the time-base closer to reality will make things nicer.

3. I believe the grid would be nicer if the lines were dotted.

4. A classmate suggested adding FFT capabilities for a limited spectrum analyzer.

Any other suggestions?

Accessories:

I put together some faux scope probes by purchasing an inexpensive 3-foot audio cable (it is not shielded as the frequencies we are dealing with are fairly low). I cut this in half and soldered on some clips to connect the center and ground connections for the Ain 1/8" phone jack. The cable I got was actually stereo and I used a DMM to find which bare-wire was connected to pin 17 on the MBED. This accessory does make it nice in most cases.

However you can achieve the same results by connecting two wires directly one to pin 17 and the other to GND on the header connections of the application board directly to the input signal and GND of your waveform output.

Committer:
trichards1138
Date:
Sat Jun 07 16:58:08 2014 +0000
Revision:
3:fe3bab42f046
Parent:
2:71767eb23ac2
Child:
4:8eeaddfebd37
semi-final for project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trichards1138 0:9ccc4b6355a8 1 #include "mbed.h"
trichards1138 0:9ccc4b6355a8 2 #include "C12832_lcd.h"
trichards1138 1:4080ce288aea 3 #include "DebounceIn.h"
trichards1138 3:fe3bab42f046 4 #include "osc.h"
trichards1138 0:9ccc4b6355a8 5
trichards1138 3:fe3bab42f046 6 Serial pc(USBTX, USBRX);//debug output
trichards1138 3:fe3bab42f046 7 C12832_LCD LCD; //main LCD class
trichards1138 3:fe3bab42f046 8 AnalogIn Ain(p17); //main analog input
trichards1138 3:fe3bab42f046 9 AnalogIn Aintrig(p18); //External trigger input
trichards1138 1:4080ce288aea 10
trichards1138 1:4080ce288aea 11 //AnalogIn pot1(p19);
trichards1138 3:fe3bab42f046 12 AnalogIn pot2(p20); //sets trigger level
trichards1138 3:fe3bab42f046 13 DebounceIn Update(p14); //menu selection
trichards1138 3:fe3bab42f046 14 DebounceIn Up(p15); //menu selection and vert base set
trichards1138 3:fe3bab42f046 15 DebounceIn Down(p12); //menu selection and vert base set
trichards1138 3:fe3bab42f046 16 DebounceIn Left(p13); //horiz (time) base set
trichards1138 3:fe3bab42f046 17 DebounceIn Right(p16); //horiz (time) base set
trichards1138 2:71767eb23ac2 18
trichards1138 3:fe3bab42f046 19 //Repaint the LCD with the menu strings for the
trichards1138 3:fe3bab42f046 20 //current menu.
trichards1138 3:fe3bab42f046 21 //Inputs - An array of menustrings and the first string
trichards1138 3:fe3bab42f046 22 // to put on the display
trichards1138 3:fe3bab42f046 23 //Outputs - a freshly painted display with the menu
trichards1138 3:fe3bab42f046 24 #define FIRST_TEXTLINE 3 //Positions on the LCD
trichards1138 3:fe3bab42f046 25 #define SECOND_TEXTLINE 13
trichards1138 3:fe3bab42f046 26 #define THIRD_TEXTLINE 23
trichards1138 3:fe3bab42f046 27 int rePaint(char menustrings[][26], int first)
trichards1138 2:71767eb23ac2 28 {
trichards1138 3:fe3bab42f046 29 LCD.cls();
trichards1138 3:fe3bab42f046 30 LCD.locate( 0, FIRST_TEXTLINE );
trichards1138 3:fe3bab42f046 31 LCD.printf(menustrings[first]);
trichards1138 3:fe3bab42f046 32 LCD.locate( 0, SECOND_TEXTLINE );
trichards1138 3:fe3bab42f046 33 LCD.printf(menustrings[first+1]);
trichards1138 3:fe3bab42f046 34 LCD.locate( 0, THIRD_TEXTLINE );
trichards1138 3:fe3bab42f046 35 LCD.printf(menustrings[first+2]);
trichards1138 3:fe3bab42f046 36 return 0;
trichards1138 2:71767eb23ac2 37 }
trichards1138 3:fe3bab42f046 38 // Display a menu and allow scrolling until user
trichards1138 3:fe3bab42f046 39 // makes a selection. Show the current selection
trichards1138 3:fe3bab42f046 40 // with a row of asterisks (which scroll with the
trichards1138 3:fe3bab42f046 41 // up and down buttons).
trichards1138 3:fe3bab42f046 42 // Inputs - The current selection and window min
trichards1138 3:fe3bab42f046 43 // and max and strings for the current menu.
trichards1138 3:fe3bab42f046 44 // These will change depending on the menu
trichards1138 3:fe3bab42f046 45 // being displayed. The sel_start is where
trichards1138 3:fe3bab42f046 46 // the selection asterisks start for the
trichards1138 3:fe3bab42f046 47 // current display stings.
trichards1138 3:fe3bab42f046 48 // Outputs - A selection from the user from the current
trichards1138 3:fe3bab42f046 49 // menu.
trichards1138 3:fe3bab42f046 50 //
trichards1138 3:fe3bab42f046 51 #define CLEARTORUN 6
trichards1138 3:fe3bab42f046 52 #define SETTORUN 4
trichards1138 3:fe3bab42f046 53 int display_menu( int *cur_sel,
trichards1138 3:fe3bab42f046 54 int *cur_min,
trichards1138 3:fe3bab42f046 55 int *cur_max,
trichards1138 3:fe3bab42f046 56 char menustrings[][26],
trichards1138 3:fe3bab42f046 57 int sel_start,
trichards1138 3:fe3bab42f046 58 int menu_end )
trichards1138 2:71767eb23ac2 59 {
trichards1138 3:fe3bab42f046 60 while( 1 ) {
trichards1138 2:71767eb23ac2 61 if( Down ) {
trichards1138 3:fe3bab42f046 62 if( *cur_sel != menu_end ) {
trichards1138 3:fe3bab42f046 63 memset( &menustrings[*cur_sel][sel_start-1], ' ' , CLEARTORUN);
trichards1138 3:fe3bab42f046 64 *cur_sel += 1;
trichards1138 3:fe3bab42f046 65 memset( &menustrings[*cur_sel][sel_start], '*', SETTORUN);
trichards1138 3:fe3bab42f046 66 if( *cur_sel > *cur_max ) {
trichards1138 3:fe3bab42f046 67 *cur_max += 1;
trichards1138 3:fe3bab42f046 68 *cur_min += 1;
trichards1138 3:fe3bab42f046 69 rePaint(menustrings, *cur_min);
trichards1138 2:71767eb23ac2 70 }
trichards1138 2:71767eb23ac2 71 else
trichards1138 3:fe3bab42f046 72 rePaint(menustrings, *cur_min);
trichards1138 2:71767eb23ac2 73 }
trichards1138 2:71767eb23ac2 74 while( Down )
trichards1138 2:71767eb23ac2 75 wait_ms(50);
trichards1138 2:71767eb23ac2 76 }
trichards1138 2:71767eb23ac2 77 if( Up ) {
trichards1138 3:fe3bab42f046 78 if( *cur_sel != 0 ) {
trichards1138 3:fe3bab42f046 79 memset( &menustrings[*cur_sel][sel_start-1], ' ', CLEARTORUN);
trichards1138 3:fe3bab42f046 80 *cur_sel -= 1;
trichards1138 3:fe3bab42f046 81 memset( &menustrings[*cur_sel][sel_start], '*', SETTORUN);
trichards1138 3:fe3bab42f046 82 if( *cur_sel < *cur_min ) {
trichards1138 3:fe3bab42f046 83 *cur_max -= 1;
trichards1138 3:fe3bab42f046 84 *cur_min -= 1;
trichards1138 3:fe3bab42f046 85 rePaint(menustrings, *cur_min);
trichards1138 2:71767eb23ac2 86 }
trichards1138 2:71767eb23ac2 87 else
trichards1138 3:fe3bab42f046 88 rePaint(menustrings, *cur_min);
trichards1138 2:71767eb23ac2 89 }
trichards1138 2:71767eb23ac2 90 while( Up )
trichards1138 3:fe3bab42f046 91 wait_ms(50); //Smooth things out
trichards1138 2:71767eb23ac2 92 }
trichards1138 3:fe3bab42f046 93 if( Update ) { //When user presses center button, cur_sel has his selection
trichards1138 3:fe3bab42f046 94 return 0;
trichards1138 2:71767eb23ac2 95 }
trichards1138 2:71767eb23ac2 96 }
trichards1138 2:71767eb23ac2 97 }
trichards1138 3:fe3bab42f046 98 //Update the vertical and horizontal bases when the user presses the up or down joystick
trichards1138 3:fe3bab42f046 99 // buttons. The horizontal is the time base, and the vertical is the volt base.
trichards1138 3:fe3bab42f046 100 // Inputs - none
trichards1138 3:fe3bab42f046 101 // Outputs - updated vertical and horizontal bases
trichards1138 3:fe3bab42f046 102 #define VBASEMAX 17
trichards1138 1:4080ce288aea 103 #define TBASEMAX 9
trichards1138 1:4080ce288aea 104 void Update_params(void)
trichards1138 1:4080ce288aea 105 { //divisions 1=128uS, 5=640uS, 10=1280uS, 20=2560uS, 50=6.4mS, 100=12.8mS, 500=64mS, 1000=128mS
trichards1138 1:4080ce288aea 106 unsigned int next_tbase[] = { 1, 5, 10, 20, 50, 100, 500, 700, 1000 };
trichards1138 3:fe3bab42f046 107 float next_vbase[] = { 0.2, 0.4, 0.6, 0.8, 1.0, 1.4, 1.8, 2.0, 2.4, 2.8, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0 };
trichards1138 3:fe3bab42f046 108 static int vsel=4, tsel=0;
trichards1138 1:4080ce288aea 109 if( Up ) {
trichards1138 1:4080ce288aea 110 while( Up )
trichards1138 1:4080ce288aea 111 wait_ms(1);
trichards1138 3:fe3bab42f046 112 vsel++;
trichards1138 1:4080ce288aea 113 if( vsel == VBASEMAX )
trichards1138 1:4080ce288aea 114 vsel = VBASEMAX-1;
trichards1138 3:fe3bab42f046 115 volt_base = next_vbase[vsel];
trichards1138 1:4080ce288aea 116 }
trichards1138 1:4080ce288aea 117 if( Down ) {
trichards1138 1:4080ce288aea 118 while( Down )
trichards1138 1:4080ce288aea 119 wait_ms(1);
trichards1138 3:fe3bab42f046 120 vsel--;
trichards1138 1:4080ce288aea 121 if( vsel == -1 )
trichards1138 3:fe3bab42f046 122 vsel = 0;
trichards1138 3:fe3bab42f046 123 volt_base = next_vbase[vsel];
trichards1138 1:4080ce288aea 124 }
trichards1138 1:4080ce288aea 125 if( Right ) {
trichards1138 1:4080ce288aea 126 while( Right )
trichards1138 1:4080ce288aea 127 wait_ms(1);
trichards1138 3:fe3bab42f046 128 tsel++;
trichards1138 1:4080ce288aea 129 if( tsel == TBASEMAX )
trichards1138 1:4080ce288aea 130 tsel = TBASEMAX-1;
trichards1138 3:fe3bab42f046 131 time_base = next_tbase[tsel];
trichards1138 1:4080ce288aea 132 }
trichards1138 1:4080ce288aea 133 if( Left ) {
trichards1138 1:4080ce288aea 134 while( Left )
trichards1138 1:4080ce288aea 135 wait_ms(1);
trichards1138 3:fe3bab42f046 136 tsel--;
trichards1138 1:4080ce288aea 137 if( tsel == -1 )
trichards1138 1:4080ce288aea 138 tsel = 0;
trichards1138 3:fe3bab42f046 139 time_base = next_tbase[tsel];
trichards1138 1:4080ce288aea 140 }
trichards1138 3:fe3bab42f046 141 tbsel = tsel; //Global copy for menu
trichards1138 3:fe3bab42f046 142 trigger = pot2.read(); //set the trigger level
trichards1138 3:fe3bab42f046 143 }
trichards1138 3:fe3bab42f046 144 // Find an edge (either rising or falling based on trigger mode) and use
trichards1138 3:fe3bab42f046 145 // it to trigger a sweep of the scope display. The search for an edge is
trichards1138 3:fe3bab42f046 146 // timed in case there is not a periodic waveform currently connected to
trichards1138 3:fe3bab42f046 147 // Ain. This ensures the menu is not delayed too much.
trichards1138 3:fe3bab42f046 148 // Inputs - none
trichards1138 3:fe3bab42f046 149 // Outputs - time sync with a correct edge of the waveform
trichards1138 3:fe3bab42f046 150 // or quick return if "no_trigger" is selected.
trichards1138 3:fe3bab42f046 151 #define TRIG_TIMEOUT 100
trichards1138 3:fe3bab42f046 152 bool get_trigger(void)
trichards1138 3:fe3bab42f046 153 {
trichards1138 3:fe3bab42f046 154 int timeout=TRIG_TIMEOUT;
trichards1138 3:fe3bab42f046 155 //capture a rising edge on the main signal - default mode
trichards1138 3:fe3bab42f046 156 if( trigger_mode == main_rising_edge ) {
trichards1138 3:fe3bab42f046 157 if( Ain.read() > trigger )
trichards1138 3:fe3bab42f046 158 while( (Ain.read() > trigger) && timeout-- )
trichards1138 3:fe3bab42f046 159 wait_us(1);
trichards1138 3:fe3bab42f046 160 if( !timeout )
trichards1138 3:fe3bab42f046 161 return false;
trichards1138 3:fe3bab42f046 162 else
trichards1138 3:fe3bab42f046 163 timeout = TRIG_TIMEOUT;
trichards1138 3:fe3bab42f046 164 while( (Ain.read() < trigger) && timeout-- )
trichards1138 3:fe3bab42f046 165 wait_us(1);
trichards1138 3:fe3bab42f046 166 if( !timeout )
trichards1138 3:fe3bab42f046 167 return false;
trichards1138 3:fe3bab42f046 168 else
trichards1138 3:fe3bab42f046 169 return true;
trichards1138 3:fe3bab42f046 170 //capture a falling edge on the main signal
trichards1138 3:fe3bab42f046 171 } else if( trigger_mode == main_falling_edge ) {
trichards1138 3:fe3bab42f046 172 if( Ain.read() < trigger )
trichards1138 3:fe3bab42f046 173 while( (Ain.read() < trigger) && timeout-- )
trichards1138 3:fe3bab42f046 174 wait_us(1);
trichards1138 3:fe3bab42f046 175 if( !timeout )
trichards1138 3:fe3bab42f046 176 return false;
trichards1138 3:fe3bab42f046 177 else
trichards1138 3:fe3bab42f046 178 timeout = TRIG_TIMEOUT;
trichards1138 3:fe3bab42f046 179 while( (Ain.read() > trigger) && timeout-- )
trichards1138 3:fe3bab42f046 180 wait_us(1);
trichards1138 3:fe3bab42f046 181 if( !timeout )
trichards1138 3:fe3bab42f046 182 return false;
trichards1138 3:fe3bab42f046 183 else
trichards1138 3:fe3bab42f046 184 return true;
trichards1138 3:fe3bab42f046 185 //capture a rising edge on an external signal
trichards1138 3:fe3bab42f046 186 } else if( trigger_mode == ext_rising_edge ) {
trichards1138 3:fe3bab42f046 187 if( Aintrig.read() > trigger )
trichards1138 3:fe3bab42f046 188 while( (Aintrig.read() > trigger) && timeout-- )
trichards1138 3:fe3bab42f046 189 wait_us(1);
trichards1138 3:fe3bab42f046 190 if( !timeout )
trichards1138 3:fe3bab42f046 191 return false;
trichards1138 3:fe3bab42f046 192 else
trichards1138 3:fe3bab42f046 193 timeout = TRIG_TIMEOUT;
trichards1138 3:fe3bab42f046 194 while( (Aintrig.read() < trigger) && timeout-- )
trichards1138 3:fe3bab42f046 195 wait_us(1);
trichards1138 3:fe3bab42f046 196 if( !timeout )
trichards1138 3:fe3bab42f046 197 return false;
trichards1138 3:fe3bab42f046 198 else
trichards1138 3:fe3bab42f046 199 return true;
trichards1138 3:fe3bab42f046 200 //capture a falling edge on an external signal
trichards1138 3:fe3bab42f046 201 } else if( trigger_mode == ext_falling_edge ) {
trichards1138 3:fe3bab42f046 202 if( Aintrig.read() < trigger )
trichards1138 3:fe3bab42f046 203 while( (Aintrig.read() < trigger) && timeout-- )
trichards1138 3:fe3bab42f046 204 wait_us(1);
trichards1138 3:fe3bab42f046 205 if( !timeout )
trichards1138 3:fe3bab42f046 206 return false;
trichards1138 3:fe3bab42f046 207 else
trichards1138 3:fe3bab42f046 208 timeout = TRIG_TIMEOUT;
trichards1138 3:fe3bab42f046 209 while( (Aintrig.read() > trigger) && timeout-- )
trichards1138 3:fe3bab42f046 210 wait_us(1);
trichards1138 3:fe3bab42f046 211 if( !timeout )
trichards1138 3:fe3bab42f046 212 return false;
trichards1138 3:fe3bab42f046 213 else
trichards1138 3:fe3bab42f046 214 return true;
trichards1138 3:fe3bab42f046 215 } else if( trigger_mode == auto_no_trigger )
trichards1138 3:fe3bab42f046 216 //if auto no-trigger...do nothing. just return
trichards1138 3:fe3bab42f046 217 return true;
trichards1138 3:fe3bab42f046 218 return false; //Can't get here, but silence the warning
trichards1138 0:9ccc4b6355a8 219 }
trichards1138 0:9ccc4b6355a8 220
trichards1138 3:fe3bab42f046 221 //This routine only gets called if the "draw grid" mode is selected. The
trichards1138 3:fe3bab42f046 222 // default is "no grid" so the display is a continuous display with no
trichards1138 3:fe3bab42f046 223 // lines. The grid is more useful for some waveforms than others. It is
trichards1138 3:fe3bab42f046 224 // a matter of taste as to if the user wants to display with or without grid.
trichards1138 3:fe3bab42f046 225 // Inputs - none
trichards1138 3:fe3bab42f046 226 // Outputs - the display with grid lines painted.
trichards1138 3:fe3bab42f046 227 #define NUMHORIZPIXELS 128
trichards1138 3:fe3bab42f046 228 #define NUMVERTPIXELS 32
trichards1138 3:fe3bab42f046 229 #define FIRSTVERT 21
trichards1138 3:fe3bab42f046 230 #define SECONDVERT 42
trichards1138 3:fe3bab42f046 231 #define THIRDVERT 63
trichards1138 3:fe3bab42f046 232 #define FOURTHVERT 84
trichards1138 3:fe3bab42f046 233 #define FIFTHVERT 105
trichards1138 3:fe3bab42f046 234 #define FIRSTHORIZ 11
trichards1138 3:fe3bab42f046 235 #define SECONDHORIZ 22
trichards1138 3:fe3bab42f046 236 void place_grid(void)
trichards1138 3:fe3bab42f046 237 {
trichards1138 3:fe3bab42f046 238 LCD.line(FIRSTVERT, 0, FIRSTVERT, NUMVERTPIXELS-1, 1);
trichards1138 3:fe3bab42f046 239 LCD.line(SECONDVERT, 0, SECONDVERT, NUMVERTPIXELS-1, 1);
trichards1138 3:fe3bab42f046 240 LCD.line(THIRDVERT, 0, THIRDVERT, NUMVERTPIXELS-1, 1);
trichards1138 3:fe3bab42f046 241 LCD.line(FOURTHVERT, 0, FOURTHVERT, NUMVERTPIXELS-1, 1);
trichards1138 3:fe3bab42f046 242 LCD.line(FIFTHVERT, 0, FIFTHVERT, NUMVERTPIXELS-1, 1);
trichards1138 3:fe3bab42f046 243 LCD.line(0, FIRSTHORIZ, NUMHORIZPIXELS-1, FIRSTHORIZ, 1);
trichards1138 3:fe3bab42f046 244 LCD.line(0, SECONDHORIZ, NUMHORIZPIXELS-1, SECONDHORIZ, 1);
trichards1138 3:fe3bab42f046 245 }
trichards1138 3:fe3bab42f046 246
trichards1138 3:fe3bab42f046 247 void menu(void)
trichards1138 0:9ccc4b6355a8 248 {
trichards1138 3:fe3bab42f046 249 int timeout=100;
trichards1138 3:fe3bab42f046 250 //Corrects the faster time bases for loop delay
trichards1138 3:fe3bab42f046 251 unsigned int tbase_correction[] = { 24, 6, 3, 3, 1, 1, 1, 1, 1 };
trichards1138 3:fe3bab42f046 252 //While user has center button pressed, display the settings
trichards1138 3:fe3bab42f046 253 while( Update ) {
trichards1138 3:fe3bab42f046 254 LCD.cls();
trichards1138 3:fe3bab42f046 255 LCD.locate( 0, FIRST_TEXTLINE );
trichards1138 3:fe3bab42f046 256 LCD.printf("Vertical Base: %3.1f V/div", draw_grid? volt_base/3: volt_base );
trichards1138 3:fe3bab42f046 257 LCD.locate( 0, SECOND_TEXTLINE );
trichards1138 3:fe3bab42f046 258 LCD.printf("Horiz Base: %d uS/div", draw_grid? (((time_base*tbase_correction[tbsel])*128)/6): ((time_base*24)*128));
trichards1138 3:fe3bab42f046 259 LCD.locate( 0, THIRD_TEXTLINE );
trichards1138 3:fe3bab42f046 260 switch( trigger_mode ) {
trichards1138 3:fe3bab42f046 261 case main_rising_edge:
trichards1138 3:fe3bab42f046 262 LCD.printf("Trigger Mode: Main rising");
trichards1138 3:fe3bab42f046 263 break;
trichards1138 3:fe3bab42f046 264 case main_falling_edge:
trichards1138 3:fe3bab42f046 265 LCD.printf("Trigger Mode: Main falling");
trichards1138 3:fe3bab42f046 266 break;
trichards1138 3:fe3bab42f046 267 case ext_rising_edge:
trichards1138 3:fe3bab42f046 268 LCD.printf("Trigger Mode: Ext rising");
trichards1138 3:fe3bab42f046 269 break;
trichards1138 3:fe3bab42f046 270 case ext_falling_edge:
trichards1138 3:fe3bab42f046 271 LCD.printf("Trigger Mode: Ext falling");
trichards1138 3:fe3bab42f046 272 break;
trichards1138 3:fe3bab42f046 273 case auto_no_trigger:
trichards1138 3:fe3bab42f046 274 LCD.printf("Trigger Mode: No Trigger");
trichards1138 3:fe3bab42f046 275 }
trichards1138 3:fe3bab42f046 276 wait_ms(200);
trichards1138 3:fe3bab42f046 277 }
trichards1138 3:fe3bab42f046 278 //Wait a while in case user presses center again
trichards1138 3:fe3bab42f046 279 while( !Update ) {
trichards1138 3:fe3bab42f046 280 --timeout;
trichards1138 3:fe3bab42f046 281 if( !timeout )
trichards1138 3:fe3bab42f046 282 break; //If we hit time out, break out
trichards1138 3:fe3bab42f046 283 wait_ms(10);
trichards1138 3:fe3bab42f046 284 }
trichards1138 3:fe3bab42f046 285 if( timeout ) { //If we didn't time out...continue
trichards1138 3:fe3bab42f046 286 timeout = 100; //If we did..we just exit and go back to scope
trichards1138 3:fe3bab42f046 287 //User may be hitting center again, if so display tigger menu
trichards1138 3:fe3bab42f046 288 if( Update ) { //user hit update again
trichards1138 3:fe3bab42f046 289 while( Update )
trichards1138 3:fe3bab42f046 290 wait_ms(1); //ensure we only process on hit
trichards1138 3:fe3bab42f046 291 rePaint(trigstrings, trig_cur_min);
trichards1138 3:fe3bab42f046 292 //Get a new trigger mode
trichards1138 3:fe3bab42f046 293 display_menu(&trig_cur_sel, &trig_cur_min, &trig_cur_max,
trichards1138 3:fe3bab42f046 294 trigstrings, SELECTION_START, MAX_TRIG_MENU );
trichards1138 3:fe3bab42f046 295 trigger_mode = (trigger_mode_type)trig_cur_sel;
trichards1138 3:fe3bab42f046 296 }
trichards1138 3:fe3bab42f046 297 while( !Update ) { //See if user wants to update grid settings
trichards1138 3:fe3bab42f046 298 --timeout;
trichards1138 3:fe3bab42f046 299 if( !timeout )
trichards1138 3:fe3bab42f046 300 break; //If we hit time out, break out
trichards1138 3:fe3bab42f046 301 wait_ms(10);
trichards1138 3:fe3bab42f046 302 }
trichards1138 3:fe3bab42f046 303 if( timeout ) { //If we didn't time out..continue
trichards1138 3:fe3bab42f046 304 if( Update ) { //user hit update again
trichards1138 3:fe3bab42f046 305 while( Update )
trichards1138 3:fe3bab42f046 306 wait_ms(1); //ensure we only process one hit
trichards1138 3:fe3bab42f046 307 rePaint(gridstrings, grid_cur_min);
trichards1138 3:fe3bab42f046 308 //Get new grid settings
trichards1138 3:fe3bab42f046 309 display_menu(&grid_cur_sel, &grid_cur_min, &grid_cur_max,
trichards1138 3:fe3bab42f046 310 gridstrings, SELECTION_START, MAX_GRID_MENU );
trichards1138 3:fe3bab42f046 311 if( grid_cur_sel )
trichards1138 3:fe3bab42f046 312 draw_grid = true;
trichards1138 3:fe3bab42f046 313 else
trichards1138 3:fe3bab42f046 314 draw_grid = false;
trichards1138 3:fe3bab42f046 315 }
trichards1138 3:fe3bab42f046 316 while( Update ) //trickle out last switch hits
trichards1138 3:fe3bab42f046 317 wait_ms(1);
trichards1138 3:fe3bab42f046 318 }
trichards1138 1:4080ce288aea 319 }
trichards1138 0:9ccc4b6355a8 320 }
trichards1138 0:9ccc4b6355a8 321
trichards1138 3:fe3bab42f046 322 //Main entry point and control loop for the program. All routines
trichards1138 3:fe3bab42f046 323 // are called from here (and return here).
trichards1138 3:fe3bab42f046 324 //
trichards1138 1:4080ce288aea 325 int main()
trichards1138 0:9ccc4b6355a8 326 {
trichards1138 3:fe3bab42f046 327 pc.baud(115200); //debug output
trichards1138 3:fe3bab42f046 328 bool skip_first_trig = false;
trichards1138 0:9ccc4b6355a8 329 unsigned int i;
trichards1138 0:9ccc4b6355a8 330 unsigned int h = LCD.height()-2, w = LCD.width(), hhh;
trichards1138 0:9ccc4b6355a8 331 while(true) { // thread loop
trichards1138 3:fe3bab42f046 332 if( get_trigger() || skip_first_trig ) {
trichards1138 3:fe3bab42f046 333 LCD.cls();
trichards1138 3:fe3bab42f046 334 LCD.rect(0,0,NUMHORIZPIXELS-1, NUMVERTPIXELS-1, 1); //place boarder
trichards1138 3:fe3bab42f046 335 if(draw_grid)
trichards1138 3:fe3bab42f046 336 place_grid();
trichards1138 3:fe3bab42f046 337 for (i=0; i<w; i++) { //do a sweep
trichards1138 3:fe3bab42f046 338 //scale the incoming signal to the screen size and vertical
trichards1138 3:fe3bab42f046 339 //base setting.
trichards1138 3:fe3bab42f046 340 hhh = (int)((h)-(h*volt_base*Ain.read()));
trichards1138 3:fe3bab42f046 341 //does not paint the screen
trichards1138 3:fe3bab42f046 342 LCD.pixel(i, hhh ,1); // print pixel
trichards1138 3:fe3bab42f046 343 //implements the horizontal or time-base
trichards1138 3:fe3bab42f046 344 wait_us(time_base);
trichards1138 3:fe3bab42f046 345 }
trichards1138 3:fe3bab42f046 346 //paint the screen
trichards1138 3:fe3bab42f046 347 LCD.copy_to_lcd(); // LCD.pixel does not update the lcd
trichards1138 0:9ccc4b6355a8 348 }
trichards1138 3:fe3bab42f046 349 skip_first_trig = false;
trichards1138 1:4080ce288aea 350 Update_params();
trichards1138 2:71767eb23ac2 351 if( Update ) { //Hit the center button once to display stats
trichards1138 3:fe3bab42f046 352 skip_first_trig = true; //ensure quick screen update after menu
trichards1138 3:fe3bab42f046 353 menu(); //go get user input
trichards1138 3:fe3bab42f046 354 } else
trichards1138 3:fe3bab42f046 355 wait_ms(50); //Delay to smooth twitchy waveforms
trichards1138 0:9ccc4b6355a8 356 }
trichards1138 0:9ccc4b6355a8 357 }
trichards1138 0:9ccc4b6355a8 358