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

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Mon Sep 25 02:09:53 2017 +0000
Parent:
9:657155f03cb8
Commit message:
miss calc of trigger value/pos fixed

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
trig.cpp Show annotated file Show diff for this revision Revisions of this file
view.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Jul 13 03:58:37 2017 +0000
+++ b/main.cpp	Mon Sep 25 02:09:53 2017 +0000
@@ -237,7 +237,7 @@
             trig_ch = i ;
             trig_pos = x - left_margin;
             post_trig_len = memLength - trig_pos ;
-            y_offset = head_h + (pane_h + 5) * i + 1;
+            y_offset = head_h + pane_h * i + 5 * (i - 1) + 1;
             trig_level = vref *(1 -  ((float)(y - y_offset) / (float)(pane_h - 2))) ;
             if (trig_level > vref) {
                 trig_level = vref ;
@@ -279,7 +279,8 @@
     while(1) {
         drawChart() ;
         touched = TSC.getPoint(&x, &y) ;
-        if (touched && ((x != 0)||(y != 0))) { // TSC sometimes returns (0,0)
+        if (touched && ((x != 0) && (y != 0))) { // discard value 0 for x, y
+// printf("x = %d, y = %d\n",x, y) ;
             if (mode == MODE_RUN) {
                 timer.detach() ;
             }
--- a/mbed.bld	Thu Jul 13 03:58:37 2017 +0000
+++ b/mbed.bld	Mon Sep 25 02:09:53 2017 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf
\ No newline at end of file
+https://mbed.org/users/mbed_official/code/mbed/builds/e2bfab296f20
\ No newline at end of file
--- a/trig.cpp	Thu Jul 13 03:58:37 2017 +0000
+++ b/trig.cpp	Mon Sep 25 02:09:53 2017 +0000
@@ -12,14 +12,16 @@
  * THE SOFTWARE.
  */
 #include "trig.h"
-
+extern int pane_w ;
+extern float vref ;
 // trigger related values
 int trig_mode = TRIG_MODE_NONE ;
 int sampling_status = ST_TRIG_HIT ;
 int trig_ch = 0 ;
-int trig_pos = 0 ;
+int trig_pos = pane_w / 2 ; /* half of the frame */
 int post_trig_len = memLength ; 
-float trig_level = 0.0 ;
+//float trig_level = 0.0 ;
+float trig_level = vref / 2.0 ;
 uint16_t utrig_level = 0 ;
 int trig_index = 0 ; 
 int post_trig_index = 0 ;
--- a/view.cpp	Thu Jul 13 03:58:37 2017 +0000
+++ b/view.cpp	Mon Sep 25 02:09:53 2017 +0000
@@ -315,8 +315,8 @@
 // draw level mark
     x1 = left_margin + pane_w + 3 ;
     x2 = x1 + 7 ;
-    y_offset = head_h + (pane_h + 5) * (trig_ch+1) + 1;
-    y1 = ((pane_h - 2) * (1.0 - trig_level)) + y_offset ;
+    y_offset = head_h + (pane_h * (trig_ch+1)) +  (5 * trig_ch) - 1;
+    y1 = y_offset - ((pane_h - 2) * (trig_level/vref)) ;
     y2 = y1 ;
     TFT.line(x1, y1, x2, y2, color) ;
     x2 = x1 + 3 ;
@@ -325,6 +325,8 @@
     y2 = y1 + 3 ;
     TFT.line(x1, y1, x2, y2, color) ;
     TFT.BusEnable(false) ;
+// printf("trig_ch = %d, trig level = %.2f, y1 = %d yoffset = %d\n", 
+//         trig_ch, trig_level, y1, y_offset) ;
 }
 
 void drawTrigMark(void)