A simple oscilloscope using Adafruit 2.8" TFT with touch. Runs on FRDM-KL25Z, FRDM-K22F, FRDM-K64F, NUCLEO-F411RE. 2 channel analog inputs with 4 trigger modes and time division.

Dependencies:   SPI_STMPE610 UniGraphic mbed vt100

My first attempt of implementing an oscilloscope using FRDM-KL25Z and Adafruit 2.8" TFT with touch.

FRDM-KL25Z と Adafruit 2.8" TFT with touch を使用して作ってみた最初のオシロスコープです。

On 25-Sep-2017, wrong calculation of trigger pos/val fixed.
On 25-Nov-2015, FRDM-K64F and NUCLEO-F411RE platforms were added.
On 26-Nov-2015, FRDM-K22F is added (tested).
Note: Now ch2 is A2 instead of A1!

25-Sep-2017, トリガー値と位置の計算の誤りを修正しました。
25-Nov-2015, FRDM-K64F と NUCLEO-F411RE でも動くようになりました。
26-Nov-2015, FRDM-K22F でも動作確認が出来ました。 ※一身上の都合で、アナログ入力の ch2 は A1 から A2 に変更しましたので、ご注意ください。m(_ _)m

/media/uploads/Rhyme/oscillo_top.jpg

This supports two analog inputs A0 for channel 1 and A2 for channel 2
and four trigger modes (NONE, RISE, FALL, LEVEL),
time division is 30us to 20ms per pixel which will make 300us/div to 200.0ms/div (as 10 pixels per div)

A0と A2 のアナログ2入力にて、
4種類のトリガーモード(NONE: フリーラン RISE: 立ち上がりエッジ、FALL: 立下りエッジ、LEVEL: レベル) 。
サンプリングは30us から 20ms, チャートの1メモリが10ピクセルなので、300us/dev から 200.0ms/div となっています。

The analog signals and gnd was picked at the pins in the picture above.
Note: now you need to pick A0 and A2 instead of A0 and A1.

信号は上記の写真のように、Adafruit のピンからつまみました。
変更により、A0とA2が入力となります。

/media/uploads/Rhyme/freerunmode.jpg

When powered on or reset, the program starts in Trigger Mode = NONE (Free Run Mode)

電源投入、リセット後 プログラムはトリガーモード NONE (フリーランモード) で起動します。

To change trigger mode and/or time division, press run/stop button.

トリガーモードを変えたり、サンプリング時間を変えるのには run/stop ボタンを押してください。

Each time you push Trig button, the trigger mode changes
NONE -> RISE -> FALL -> LEVEL ( -> NONE).

トリガーボタンを押すたびにトリガーモードは
NONE(フリーラン) -> RISE (立ち上がりエッジ) -> FALL (立下りエッジ) -> LEVEL (レベル)
と変化します。

When trigger mode is not NONE,
to specify the trigger position, level and channel, push inside the wave frame.
Then green trigger marks will be shown and value of trigger position and voltage will be printed.

トリガーモードが NONE でないときに、チャネルの枠内をタッチしますと、
その位置がトリガーのポジション、レベル、チャネルになります。 そして、緑色のトリガーマークが表示され、下部にはトリガーの具体的なポジションとボルテージが表示されます。

/media/uploads/Rhyme/usage_screen1.jpg

To change time division push "1/2" to Zoom Out (sampling interval will be bigger) or
"x2" to Zoom In (Sampling interval will be smaller).

サンプリングタイムを変更するのには
"1/2" ズームアウト (サンプリング間隔が長くなります) か
"x2" ズームイン (サンプリング間隔が短くなります。) を押してください。

/media/uploads/Rhyme/helps.jpg

On 7-Mar-2015 updated to UniGraphic library version!

2015年3月7日 UniGraphic ライブラリ使用版にアップデートしました。

/media/uploads/Rhyme/frdm-kl25z-ss.jpg FRDM-KL25Z
/media/uploads/Rhyme/frdm-k64f-ss.jpg FRDM-K64F
/media/uploads/Rhyme/nucleo-f411re-ss.jpg NUCLEO-F411RE

Committer:
Rhyme
Date:
Sat Mar 07 00:53:42 2015 +0000
Revision:
3:ea0c3cffa988
Parent:
2:4b9260139892
Child:
4:6f3532a1a962
Child:
7:e58e106c6232
UniGraphic library version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:2b9a6c5fcd52 1 /** mbed oscilloscope my implementation of a oscillo scope
Rhyme 0:2b9a6c5fcd52 2 * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab
Rhyme 0:2b9a6c5fcd52 3 *
Rhyme 0:2b9a6c5fcd52 4 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Rhyme 0:2b9a6c5fcd52 5 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Rhyme 0:2b9a6c5fcd52 6 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Rhyme 0:2b9a6c5fcd52 7 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Rhyme 0:2b9a6c5fcd52 8 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Rhyme 0:2b9a6c5fcd52 9 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Rhyme 0:2b9a6c5fcd52 10 * THE SOFTWARE.
Rhyme 0:2b9a6c5fcd52 11 */
Rhyme 0:2b9a6c5fcd52 12 #ifndef _MAIN_H_
Rhyme 0:2b9a6c5fcd52 13 #define _MAIN_H_ inluded
Rhyme 0:2b9a6c5fcd52 14
Rhyme 2:4b9260139892 15 #if defined (TARGET_KL25Z)
Rhyme 0:2b9a6c5fcd52 16 #define PIN_MOSI PTD2
Rhyme 0:2b9a6c5fcd52 17 #define PIN_MISO PTD3
Rhyme 0:2b9a6c5fcd52 18 #define PIN_SCLK PTD1
Rhyme 0:2b9a6c5fcd52 19 #define PIN_CS_TFT PTD0
Rhyme 0:2b9a6c5fcd52 20 #define PIN_DC_TFT PTD5
Rhyme 0:2b9a6c5fcd52 21 #define PIN_BL_TFT PTC9
Rhyme 0:2b9a6c5fcd52 22 #define PIN_CS_SD PTA4
Rhyme 0:2b9a6c5fcd52 23 #define PIN_CS_TSC PTA13
Rhyme 0:2b9a6c5fcd52 24 #define PIN_TSC_INTR PTC9
Rhyme 3:ea0c3cffa988 25 #define PIN_RESET_TFT PTB10
Rhyme 0:2b9a6c5fcd52 26
Rhyme 2:4b9260139892 27 #elif defined (TARGET_KL46Z)
Rhyme 2:4b9260139892 28 #define PIN_MOSI PTD6
Rhyme 2:4b9260139892 29 #define PIN_MISO PTD7
Rhyme 2:4b9260139892 30 #define PIN_SCLK PTD5
Rhyme 2:4b9260139892 31 #define PIN_CS_TFT PTD4
Rhyme 2:4b9260139892 32 #define PIN_DC_TFT PTD2
Rhyme 2:4b9260139892 33 #define PIN_BL_TFT PTC9
Rhyme 2:4b9260139892 34 #define PIN_CS_SD PTA4
Rhyme 2:4b9260139892 35 #define PIN_CS_TSC PTA13
Rhyme 2:4b9260139892 36 #define PIN_TSC_INTR PTC9
Rhyme 2:4b9260139892 37
Rhyme 2:4b9260139892 38 #else
Rhyme 2:4b9260139892 39 #error TARGET NOT DEFINED
Rhyme 2:4b9260139892 40 #endif
Rhyme 2:4b9260139892 41
Rhyme 0:2b9a6c5fcd52 42 #define CHART_LEN 198
Rhyme 0:2b9a6c5fcd52 43
Rhyme 0:2b9a6c5fcd52 44 // NOTE: in case MIN_INTERVAL is too small
Rhyme 0:2b9a6c5fcd52 45 // the program hangs during ADC and timer interrupt
Rhyme 0:2b9a6c5fcd52 46 #define MIN_INTERVAL 30
Rhyme 0:2b9a6c5fcd52 47 #define MAX_INTERVAL 20000
Rhyme 0:2b9a6c5fcd52 48 #define NUM_MAX_MENU 20
Rhyme 0:2b9a6c5fcd52 49 #define NUM_MAX_ANALOG_CH 2
Rhyme 0:2b9a6c5fcd52 50 #define MODE_RUN 1
Rhyme 0:2b9a6c5fcd52 51 #define MODE_STOP 0
Rhyme 0:2b9a6c5fcd52 52
Rhyme 0:2b9a6c5fcd52 53 extern vt100 tty ;
Rhyme 0:2b9a6c5fcd52 54 extern AnalogIn *ach[] ;
Rhyme 0:2b9a6c5fcd52 55 extern Ticker timer ;
Rhyme 0:2b9a6c5fcd52 56
Rhyme 0:2b9a6c5fcd52 57 extern DigitalOut backlight ;
Rhyme 3:ea0c3cffa988 58 extern ILI9341 TFT ;
Rhyme 0:2b9a6c5fcd52 59 extern SPI_STMPE610 TSC ;
Rhyme 0:2b9a6c5fcd52 60 extern TFTMenuItem *menu[] ;
Rhyme 0:2b9a6c5fcd52 61 extern int numMenu ;
Rhyme 0:2b9a6c5fcd52 62
Rhyme 0:2b9a6c5fcd52 63 extern float vref ; // input range 0 - 3.3V
Rhyme 0:2b9a6c5fcd52 64
Rhyme 0:2b9a6c5fcd52 65 extern uint16_t udata[2][NUM_MAX_ANALOG_CH][CHART_LEN] ;
Rhyme 0:2b9a6c5fcd52 66 extern int data_index ;
Rhyme 0:2b9a6c5fcd52 67 extern uint16_t bor[2] ; // begin of ring buffer
Rhyme 0:2b9a6c5fcd52 68
Rhyme 0:2b9a6c5fcd52 69 extern int numAnalogIn ;
Rhyme 0:2b9a6c5fcd52 70 extern int memLength ;
Rhyme 0:2b9a6c5fcd52 71 extern int us_interval ; // 20us = 50KHz
Rhyme 0:2b9a6c5fcd52 72 extern bool frame_full ;
Rhyme 0:2b9a6c5fcd52 73 extern int page ; //
Rhyme 0:2b9a6c5fcd52 74 extern int prev_page ;
Rhyme 0:2b9a6c5fcd52 75 extern int mode ;
Rhyme 0:2b9a6c5fcd52 76
Rhyme 0:2b9a6c5fcd52 77 float u2v(uint16_t uvalue) ;
Rhyme 0:2b9a6c5fcd52 78 uint16_t v2u(float voltage) ;
Rhyme 0:2b9a6c5fcd52 79 float u2f(uint16_t value) ;
Rhyme 0:2b9a6c5fcd52 80
Rhyme 0:2b9a6c5fcd52 81 void initADC(void) ;
Rhyme 0:2b9a6c5fcd52 82 void envChanged(void) ;
Rhyme 0:2b9a6c5fcd52 83 bool checkTrigger(void) ;
Rhyme 0:2b9a6c5fcd52 84 void sampleAD(void) ;
Rhyme 0:2b9a6c5fcd52 85 #endif /* _MAIN_H_ */