Dual Trace Oscilloscope




Introduction: Dual Trace Oscilloscope

When I build my previous mini oscilloscope I wanted to see how well I could make my smallest ARM microcontroller a STM32F030 (F030) perform, and it did a nice job.

In one of the comments it was suggested that a "Blue Pill" with a STM32F103 (F103) might be better, smaller than the development board with the F030 and possibly even cheaper. But for the mini oscilloscope I did not use the development board but the F030 on an even smaller SMD-DIP board, so there a Blue Pill would certainly not be any smaller and I doubt that it would be cheaper too.

Code is now available on Gitlab:



Part list:
- plastic box - perfboard (double sided prototype board 8x12cm) - Blue Pill - ST7735s TFT display - lithium-ion battery - HT7333 3.3V low dropout regulator - MCP6L92 dual opamp - TSSOP8 to DIP8 board - 12 MHz crystal (not necessary) - rotary encoder plus knob (2x) - powerswitch - banana terminals (4x) - lithium-ion charger board - several resistors and capacitors - nylon spacers, nuts and screws


- soldering station - solder 0.7mm - some wire - side cutter - glasses and loupe - drill - multimeter - oscilloscope - STLink-V2


- STM32IDE - STM32CubeMX - STLink Utility - LowLayer library - adapted library for ST7735s - Notepad++ - Kicad

Step 1: Interleave or SImultaneous Mode

Blue Pill

But the idea was there, and I knew that the F103 has two ADCs! What if I used those two ADCs together in "interleave" mode, something I have done before with the STM32F407 (F407). The sampling speed would double. That, combine that with a faster microcontroller and it would make for a great successor to the mini oscilloscope.

Interleave mode
Oddly the ADCs in the F103 are less advanced than the one in the F030 (and the F407), you cannot choose the resolution. More important is that you also cannot change the timing between the two ADCs. Now, when you use the interleave mode usually you want the sampling as fast as possible with the shortest time between any samples, but with an oscilloscope it is neccessary to change the timing. Maybe it still can be done, I'm not a professional oscilloscope designer, but I dropped the plan to use interleave-mode.

Simultaneous mode

But, having two ADCs gives many more options, the two ADCs can be set to "regular-simultaneous" mode too. How about a dual trace-oscilloscope?

Having decided to try to make a dual trace oscilloscope I also wanted to have variable input sensitivity, an option that I did not have on the mini oscilloscope. That means an attenuator (and amplifier) on the inputs. And maybe I wanted even more? So I made a small list of "nice-to-haves".


two channels

variable sensitivity on both channels

triggering on both channels

variable trigger level on both channels

variable offset

single battery power

fit in the same box as the mini-oscilloscope

Step 2: Prototyping

As usual I started this projects on a breadboard. (See picture) And before soldering everything on the perfboard I try to find out if and how it will fit in the chosen project box. It fits, but only just. Some parts are hidden under the screen, other under the Blue Pill. And again, just as for most of my projects, this is a once-only project and I will not design a PCB for it.

Step 3: Attenuators

In regular oscilloscopes the input attenuators are circuits that change attenuation and amplification by switching in and out resistors with small signal relays. While I have some of those relays, I know they will not switch at less than 4 Volt, that means that they will only work with a fully loaded Lithium Ion battery (4.2V). So I needed another way to switch those resistors. Of course I could just install mechanical switches, but that would certainly no longer fit in the project box in had in mind, perhaps I could try a better digital potentiometer again (the one I have is way too noisy).

Then I thought of "analog switches", with those I can make a digital potentiometer myself. In my parts collection I found the CD4066 with four analog switches. The idea is to make the feedback resistor of an opamp variable by switching in and out resistors parallel to the feedback resistor.

It works very well, but having just 4 switches in the 4066 and having 2 channels it was not possible to make more than three sensitivity levels. I chose 500mV, 1V and 2V per division as those are the voltage levels that I use most. The screen is divided into 6 divisions, so that makes for the ranges -1.5V to +1.5V, -3V to +3V and -6V to 6V.

With the "virtual-ground" you can move these ranges up and down so even 0v to +12V is possible.

Step 4: Virtual Ground

Because the oscilloscope uses a single power rail (3.3V) the opamps need a virtual ground level or they will not work. This virtual ground level is made with PWM on one output channel of TIM4, the duty cycle of it changes from just a few percent to almost a hundred percent. A low pass filter with a 1k resistor and a 10uF capacitor transforms that into a voltage of (almost) 0V to (almost) 3.3V. The frequency of the squarewave is just under 100kHz, so the simple low pass filter is good enough.

Rather late in the building of this oscilloscope I realized that you cannot have two separate offsets for the channels. This is because of the fact that with a single power supply the input-ground-level has to be separate from the real ground level of the opamps. So both channels move in the same way as you change the GND-setting.

Step 5: Rotary Encoders and Debugging

On the mini oscilloscope I used just one rotary encoder for all functions. That would make a dual oscilloscope very difficult to use, so here I need two. One encoder for the attenuators and virtual ground level and the other encoder for the timebase and triggering. Sadly, just as in my other project, these rotary encoders are very "noisy". They are so bad that they simply would not work with timers in "encoder-mode", the standard way of reading them. I had to make a debouncing mechanism with timer TIM2, checking the encoders every 100us. This timer in turn is started (only) when there is some activity on the encoders, this is checked with the EXTI functionality on the input ports. Now the encoders work well.

And as you can see, having a display can also be very handy to display debugging information.

Step 6: Display and Timebase

The display has a resolution of 160 x 128 pixels so there are 160 samples needed for one screenfull, I managed to speed up the ADCs to do 1.6 million samples per second and that, with the much overclocked microcontroller (more on that later), gives a minimum timebase of 20us per division (100us per screen). Thus a waveform of 10kHz will fill the whole screen.

That is only twice as fast a the mini oscilloscope I made before. Oh well, now it is with two channels :-).

As said, the display is 160 pixels wide so only 160 values are needed per screen. But all buffers actually contain 320 samples. So the DMA stores 320 values before it triggers a transmission complete interrupt (TC). This is because the triggering is done in software. The sampling starts at a random moment, so it is very unlikely that the first value in the buffer is the place where the trigger point should be.

Therefore the trigger point is found by reading through the trace_x_buffer, if the value is at the wanted trigger value en if the previous value is just below it, the trigger_point is found. This works quite well, but you need a bigger buffer than the actual display size is.

This too is the reason that the refresh rate on the lower timebase settings is slower than you might expect. When you use the 200ms/div setting one screen full of data is 1 second, but because double the amount of conversions is done, that takes 2 seconds. On the faster timebase settings you will not notice it that much.

TIM3 is used to generate the timebase. It triggers the ADCs with the speed as required by the selected timebase setting. Its clock of TIM3 is 120MHz (see OVERCLOCKING), the maximum number to which it counts (ARR) determines how other it overflows or, in ST language it updates. Via TRGO these update pulses trigger the ADCs. The lowest frequency it generates is 160 Hz, the highest is 1.6MHz.

Step 7: ADCs and DMA

The two ADCs convert the voltage on their inputs at the same time, they store those two 12 bit values in a single 32bit variable. So the DMA has just one variable per (double) conversion to transfer.

To use these values it is therefore necessary to split them into the two values so they can be used to display the two traces. As said, ADCs in the F103 cannot be set to other resolutions than 12 bits. They are always in 12 bit mode and so conversions always take the same number of clock pulses. Still, with the overclocking of the ADCs , 1.6 MSamples per second can be done (see Extra: Overclocking).

The reference of the ADCs is Vdd, the 3.3V rail. To convert that to more convenient values (per division) I have calculated the values of the attenuators, because I do not have the exact resistor values that come out of those calculations some corrections are done in software.

In this project I use DMA in "regular-mode". In this mode the DMA stops transferring data (from de ADCs to memory) when the number of words (or half-words or bytes) all are transferred. In the other possible mode, "circular mode" the DMA resets itself and continues transferring data un-interrupted. That did not work with the F103, it is so fast that it overwrites the data in the adc_buffer[] before the rest of the program could read it. So now the process is as follows:

- setup DMA to the number of data to be transferred and enable DMA

- start the triggering of the ADCs, these will request DMA transfers after each (double) conversion

- after the set number of conversions are transfered, DMA stops

- immediately also stop triggering of the ADCs

- do all manipulation needed on the data in memory

- show traces on the screen

- start the process again

Step 8: User Interface

A 160 by 128 pixel screen isn't very big and I want to use as much of it as possible. So there is no part of it reserved for the currents settings. In the last few rows the vertical sensitivity, timebase, trigger level and trigger channel are displayed, but when the signals are big enough they will appear in the same area. The option that is active is shown in yellow, the rest is shown in white.

Step 9: Building and Possible Improvements

I'm pretty happy about this project. It works fine and does the job, but it could be better.

The project box is too small to fit everything in comfortably, this results in having to put components under the Blue Pill. To make that possible the Blue Pill couldn't be soldered to the "main-board" directly. And because this made it all too high I had to remove many parts from the Blue Pill, such as the jumpers for selecting BOOT0 and BOOT1 (things I never use anyway) and I even had to move the crystal from the top to the bottom of the pcb.

I made life more difficult by using banana connectors instead of BNC or SMA connectors, it meant that a big part of the perfboard was a "no-go-area", to make that clear for myself I put kapton tape over it to prevent myself from putting parts on it.

Another problem with putting it all in such a small project box is that the analog and digital circuits are very close together. You can see that there is quite a lot of noise visible on both traces. This I did not even have on the breadboard! By moving the power lines for analog and digital circuits as far apart as possible a small improvement was made, but not enough for my liking. Reducing all resistor values in the analog circuits even further than I did (the input resistance is 100kOhm instead of 1MOhm) did not help. I suspect that triggering on the fastest timebase setting (20us/div), which isn't great, will also improve with less noise on the signals.

If you make this design on a "real" pcb, with all smd parts and separate layers for analog, digital and power (that's 4 layers!) it will probably work very well. It'll be much smaller, it will not use a complete Blue Pill but just the F103 and that will make it possible to supply it with a separate (clean) analog Vdda for the ADCs.

As a final touch I decided to spray the box black, it makes a change from all the beige boxes it have.

Step 10: The Code and a Short Video

Step 11: EXTRA: Overclocking

Just as I did with the F03, I wanted to see how well a F103 can be overclocked. The specifications for this microcontroller claim that the maximum clock speed should not exceed 72MHz (which of course is already faster than the F030) but I had read in several blogs that overclocking it was easy, so why not?

The Blue Pill is provided with an 8MHz crystal, the PLL multiplies that with a factor of 9 to 72MHz. The PLL can be increased up to 16 giving a clock of 128MHz. That was no problem at all for my Blue Pill, in fact, all my Blue Pills work without any problems on 128MHz.

But now I wanted to find out what the real limit is. So I removed the 8MHz crystal and replaced it with one of 12MHz. Again I increased the PLL multiplier until the microcontroller finally gave up. That was at 168MHz ! On 156MHz it still worked well. I left it running at that speed for hours and never saw it crash. In this oscilloscope I settled for 120MHz, a speed that can be selected with a 12MHz crystal and PLL on 10, as well as with an 8 MHz crystal and the PLL on 15. (see SystemClock_Config in main.c)

The ADCs now also work faster, I have them running at 30MHz (instead of 14), they were still working well on 60MHz, STMicroelectronics makes some nice hardware!

STMicroelectronics puts these limits in the datasheet for good reason, they guarantee that the microcontroller works at the specified 72MHz under all conditions.

But as I do not use the microcontroller at -40 Celsius, +85 Celsius, on just 2.0 Volt or 3.6 Volt I think it is safe to overclock it. Do NOT do this when you intent to sell a device with their microcontrollers, you never know where they will be used.

2 People Made This Project!


  • Build a Tool Contest

    Build a Tool Contest
  • Remote Control Contest

    Remote Control Contest
  • Meatless Challenge

    Meatless Challenge



5 months ago

buenas noches gracia por interesarse en mi problema yo compre unas plataformas
chinas el numero es Ch32f103c8t6 con ese me da el menú y lo cambia todo pero no
da el trazo del centro o sea el osciloscopio luego compre 2 stm32f103c8t6 los programe
y se ve que recibe bien el programa pero sale el blanco ni menú ni trazo tengo 4 y ninguno
me funciona con ese programa el st7735-mini-osciloscopio.hex porque los otros archivos
no logro que me generen el .hex lo raro es que me funcionan en otros programas
de osciloscopios y en ese no quiere bueno vale que soy muy persistente
y paciente a la vez llegara el momento gracias de nuevo por su ayuda que estés bien
buenas noches


Reply 5 months ago

I've been reading about the STM32F103 clones: some are marked CF32, others CS32 and there are even microcontrollers that are not clones at all.

I stopped buying any electronic components from China about a year ago. Even a simple 3.3V voltage regulator I received from China was fake, it didn't have overload protection.... boom!
Farnell, Mouser and others may be a bit more expensive but at least you know that you get genuine parts.


Reply 5 months ago

Hi Freddy,
I just made an absolute minimum setup, just the blue-pill and the lcd-screen. Made the connections to the lcd and put 1/3 and 2/3 of the 3.3V on the inputs of the ADCs. After uploading the code it worked first time. I'll upload the HEX-file that I used again to Gitlab, maybe something went wrong there.
Another thing could be that the input voltage on the ADCs of your oscilloscope is higher (or lower) than you expect. What happens when you put no signal at all on PA0 and PA1?
Happy debugging,


5 months ago

buenas noches agradezco mucho su respuesta WILCO yo compre 4 pantallas para ver si era el problema 2 cuadradas y 2 rectangular con st7735 las 4 pero todas me funcionan igual compre ch32f103c8t6 y stm32f103c8t6 en el ch32 me sale el menu
y lo cambia bien pero en los stm32 sale en blanco no funciona del todo pienso que son los stm32 que estoy comprando
pero aquí en Costa rica es muy escaso esta plataforma yo como técnico en electrónica he revisado minuciosamente
para ver si encuentro algo anormal pero esta todo bien colocado y los voltajes perfectos bien filtrado y bien limpio lástima porque me gusto
mucho su proyecto eres muy amable haberme contestado me siento halagado que siempre tengas buena salud bendiciones
soy de Costa Rica salude. Freddy Barboza.


Reply 5 months ago

Hi Freddy,

What do you mean with CH32 ?
Didn't you get a real STM32F103 ?

I know that there are Chinese clones of the STM32F103 made by Giga Devices but they are called GD32F103... I do not know if they are 100% compatible, so if you have one of those microcontrollers it *could* be the problem.

I will build the oscilloscope again on a breadboard to see if I can replicate the effect you see (no line). But it will take some time to build so you may have to wait a while before I have build and tested it.

Succes with the hobby!


5 months ago

Ccargo el progra hex y sale solo el menu la linea del osciloscopio no sale
ayuda ope favor gracisas


Reply 5 months ago

Hi Freddy,

It is hard for me to decide what might be wrong with your device and the fact that I do not have my dual trace oscilloscope anymore makes it even harder. I can only guess at what causes the line to be invisible or not working at all.

I took a good look at the code and I can see nothing that prevents the line to be shown, also I know that others have used the hex-file and got a working device. So my guess is that there is nothing wrong with the hex file.

Now you say that the "menu" does appear, that means that the microcontroller is working well and that everything is connected as it should...

I can only think of one thing, that the color of the line is a color the for some reason does not work on your display. If you have an other display, try that one....

I'm sorry that I cannot help you more than this. Seeing that your language is Spanish means that you are most likely not close to me (the Netherlands in Europe) so it probably isn't possible to help you in person.

Kind regards,


Question 6 months ago on Step 3

Hi, is it possible to reduce the minimum time base below 20uS ?
5uS would be ideal for my application .
If this can be done how would I do it


Answer 6 months ago

First of all, I do not have the oscilloscope anymore so I'm not able to test things. But I think it is possible to get a bit more performance out of the STM32F103.

The first thing I'd try is to simply add a 13th option to the timebase (see stm32f1xx_it.c) and give it a value of 18. So add:
case 13:
LL_TIM_SetPrescaler(TIM3, 0);
LL_TIM_SetAutoReload(TIM3, 18);
to it.
(and make sure that the value of timebase is allowed to go up to 13 of course)
That would make the timebase 5.0667 us/div which is close enough.

Next you might need to change the clock for the ADCs from 30MHz to 60MHz by changing the line LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSRC_PCLK2_DIV_4);
(in the main.c file) to
That did work on the STM32F103 I used but there is no guarantee....

But I'm not sure that the rest of the STM32F103 can keep up with that speed. It may be necessary to go a bit further with over clocking it. As I said in the Instructable, I could make it run reliable at 156 MHz.
If you do that you will have to re-calculate all timings of the oscilloscope because everything is based on a 120 MHz clock.

This all does not change the bandwidth of the oscilloscope of course and remember that even running the microcontroller at 120MHz is already way out of spec.

Good luck.


10 months ago

First of all, thankyou for this great instructable ! In Brazil, its less expensive to make this project then buy any available Kit on Internet And I need a simple oscilloscope to some projects I´m working in so... thankyou for saving me :)
BTW, I just want to ask something : Is possible to use this display :


... instead of the one you use ?

Would the increase in resolution be any problem, or some changes will be needed ?

Thankyou again


Reply 10 months ago

Most likely you can use it, take a look at the connections though. The LCD I used is one with SPI and I know there are others that use I2C. If the LCD you mention is one with I2C you need to change quite a lot in the code.
The increase in resolution means that the microcontroller has more work to do, so it will slow it down somewhat.
Happy building.


11 months ago on Step 11

Something new for me in this instructable was see of STM32 overclocking analisis, one of the way to push to limits MCU (thanks for that). All this result in a T = 20us/div. ( 100KHz). The questions are: This limitation is just based in 1pixel per sample algorithm ? - there is no way to extend bandwith using less samples per division. It's true that this metod decrease resolution, but is a just sacrifice.
Please reply me.


Reply 11 months ago


11 months ago on Step 11

Hi WilkoL
Nice project/instructable, detailed explanation.
I been make a similar work but using a parallel type bus monochrome display with STM F10x MCU. Leaving thats differences the main goals of my project are the same: Try to get simple osc. with basic functions pushing to limits ADC and MCU features.


1 year ago on Step 4

Unable to read schematic in step 4. Same with PDF. Too small and blurry...


Reply 1 year ago

Interesting.... It's blurry on my machine.


Reply 1 year ago

It's really not any better. Everything is blurred.


Question 1 year ago

I currently can't get my hands on a MCP6L92. Would you please tell me if you know of any substitutes?