<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://pc5214.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Diandian</id>
	<title>PC5214 wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://pc5214.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Diandian"/>
	<link rel="alternate" type="text/html" href="https://pc5214.org/index.php/Special:Contributions/Diandian"/>
	<updated>2026-04-20T07:44:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3661</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3661"/>
		<updated>2022-04-30T14:54:12Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Future improvement can be done */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
The complete code is [[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
The main function is shown below:&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
Here, we did not use a PCB but a cirucit board is to facilitate the adjustment of the circuit and the addition of components.&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.7 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.8 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
[[File:adjustment.jpg|thumb|center|450px|Fig.9 a: Shorting P1.0 &amp;amp; P1.1 to ground; b: Shorting P3.2 to ground]]&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.10 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3659</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3659"/>
		<updated>2022-04-30T14:53:58Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 4:Programming and downloading the code to microcontroller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
The complete code is [[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
The main function is shown below:&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
Here, we did not use a PCB but a cirucit board is to facilitate the adjustment of the circuit and the addition of components.&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.7 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.8 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
[[File:adjustment.jpg|thumb|center|450px|Fig.9 a: Shorting P1.0 &amp;amp; P1.1 to ground; b: Shorting P3.2 to ground]]&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3656</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3656"/>
		<updated>2022-04-30T14:53:09Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 5:Test and measurement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
The complete code is [[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
The main function is shown below:&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
Here, we did not use a PCB but a cirucit board is to facilitate the adjustment of the circuit and the addition of components.&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
[[File:adjustment.jpg|thumb|center|450px|Fig.8 a: Shorting P1.0 &amp;amp; P1.1 to ground; b: Shorting P3.2 to ground]]&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=File:Adjustment.jpg&amp;diff=3653</id>
		<title>File:Adjustment.jpg</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=File:Adjustment.jpg&amp;diff=3653"/>
		<updated>2022-04-30T14:51:45Z</updated>

		<summary type="html">&lt;p&gt;Diandian: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3652</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3652"/>
		<updated>2022-04-30T14:51:26Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 4:Programming and downloading the code to microcontroller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
The complete code is [[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
The main function is shown below:&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
Here, we did not use a PCB but a cirucit board is to facilitate the adjustment of the circuit and the addition of components.&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
[[File:adjustment.jpg|thumb|center|450px|Fig.8 a: Shorting P1.0 &amp;amp; P1.1 to ground; b: Shorting P3.2 to ground]]&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3633</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3633"/>
		<updated>2022-04-30T14:38:17Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
The complete code is [[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
The main function is shown below:&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
Here, we did not use a PCB but a cirucit board is to facilitate the adjustment of the circuit and the addition of components.&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3630</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3630"/>
		<updated>2022-04-30T14:35:16Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
[[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
The main function is shown below:&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
Here, we did not use a PCB but a cirucit board is to facilitate the adjustment of the circuit and the addition of components.&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3626</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3626"/>
		<updated>2022-04-30T14:33:11Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
[[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
Here, we did not use a PCB but a cirucit board is to facilitate the adjustment of the circuit and the addition of components.&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3623</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3623"/>
		<updated>2022-04-30T14:32:15Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
[[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
Here, we did not use a PCB but a cirucit board is to facilitate the adjustment of the circuit and the addition of components.&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3622</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3622"/>
		<updated>2022-04-30T14:32:02Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
[[File:main_code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=File:Main_code.doc&amp;diff=3618</id>
		<title>File:Main code.doc</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=File:Main_code.doc&amp;diff=3618"/>
		<updated>2022-04-30T14:31:15Z</updated>

		<summary type="html">&lt;p&gt;Diandian: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3615</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3615"/>
		<updated>2022-04-30T14:28:26Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
[[File:code.doc|left]]&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3613</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3613"/>
		<updated>2022-04-30T14:28:12Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
[[File:code.doc|center]]&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=Main_Page&amp;diff=3589</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=Main_Page&amp;diff=3589"/>
		<updated>2022-04-30T14:09:24Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* A Digital Oscilloscope Based on MCU */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;strong&amp;gt;MediaWiki has been installed.&amp;lt;/strong&amp;gt;&lt;br /&gt;
Welcome to the main page for the PC5214 graduate module AY2122, Sem2&amp;lt;/strong&amp;gt;.&lt;br /&gt;
Here, we leave project descriptions, literature references, and other collateral information. You will need to create an account in class to obtain write access.&lt;br /&gt;
&lt;br /&gt;
Actual lecture locations will be placed here until we have reached a stable state. If you are interested and have not been able to register, please send me an email (if you have not done so already) to [mailto:phyck@nus.edu.sg phyck@nus.edu.sg].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;Deadline for all the wiki entries will be 30 April 2022, 23:59! Please ensure that you hare happy with your entries by that time!&amp;lt;/span&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Cheers, Christian&lt;br /&gt;
&lt;br /&gt;
This page is currently set up.&lt;br /&gt;
&lt;br /&gt;
==Lab spaces==&lt;br /&gt;
* &#039;&#039;&#039;S11-02-04&#039;&#039;&#039; (next to physics dept resource room). This is where most optics-related projects should go.&lt;br /&gt;
* &#039;&#039;&#039;S12 level 4&#039;&#039;&#039;, &amp;quot;year 1 teaching lab&amp;quot;, back room, &amp;quot;vanderGraff lab&amp;quot;. This is perhaps were non-optics related projects would fit.&lt;br /&gt;
* &#039;&#039;&#039;S13-01-??&#039;&#039;&#039; (blue door: former accoustics lab). Not sure yet who could go there, but it is a really really quiet place!&lt;br /&gt;
* anything else you have access to&lt;br /&gt;
&lt;br /&gt;
==Projects==&lt;br /&gt;
Please leave a a link to your project page (or pages) here, and leave a short description what this is about. Write the &#039;&#039;&#039;stuff you need&#039;&#039;&#039; under the description too.&lt;br /&gt;
&lt;br /&gt;
===[[Project 1 (example)]]===&lt;br /&gt;
Keep a very brief description of a project or even a suggestion here, and perhaps the names of the team members, or who to contact if there is interest to join.&lt;br /&gt;
&lt;br /&gt;
===[[Confocal Microscopy]]===&lt;br /&gt;
Team Members: Wang Tingyu, Xue Rui, Yang Hengxing&lt;br /&gt;
&lt;br /&gt;
A Confocal Microscopy or Confocal Laser Scanning Microscopy (CLSM) uses pinhole to block out all out of focus light to enhance optical resolution, very different from traditional wide-field fluorescence microscopes. To offset the block of out of focus lights, the light intensity is detected by a photomultiplier tube or avalanche photodiode, which transforms the light signal into an electrical one. We will try to build a Setup like this to enhance optical resolution and maybe get profile information about the sample.&lt;br /&gt;
&lt;br /&gt;
===[[Resonance frequency measurement using a interferometric method]]===&lt;br /&gt;
&lt;br /&gt;
Members: [[User:Nakarin|Nakarin Jayjong]], [[User:Aucca|Joel Auccapuclla]], [[User:Xiaoyu|Xiaoyu Nie]], [[User:Haotian|Haotian Song]].&lt;br /&gt;
&lt;br /&gt;
In this project, the resonance frequency of the vibrating system namely the vibration transducer is measured using a Michelson interferometer.&lt;br /&gt;
&lt;br /&gt;
===[[Homodyne detection]]===&lt;br /&gt;
Proposed By: [[User:Johnkhootf|John Khoo]]&lt;br /&gt;
&lt;br /&gt;
Team Members: [[User:Johnkhootf|John Khoo]], [[User:Xie_Chengkun|Xie Chengkun]]&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Homodyne_detection &#039;&#039;Optical&#039;&#039; homodyne detection] is a method for detecting messages transmitted in optical signals, where a frequency or phase modulated signal is compared to what is misleadingly called the &amp;quot;local oscillator&amp;quot; (LO) signal, which is generated from the same source but not modulated with the message. In order to probe quantum effects, it is important to bring the noise of the detector down to the [https://en.wikipedia.org/wiki/Shot_noise &#039;&#039;shot-noise limit&#039;&#039;], where the only fluctuations observed arise from the discrete nature of photons, which can be theoretically modelled as the vacuum-state fluctuations of the quantised electromagnetic field. This project&#039;s first objective is to build a homodyne detector from scratch.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Stuff we need&#039;&#039;&#039;: Acousto-optical modulator, electro-optical modulator, transformer to control EOM, photodiodes, current-to-voltage converter (I&#039;m not sure what this is - can we just use a resistor connected to the ground and measure the voltage?), Raspberry Pi (I hope the ADC is good enough for this), mirrors and beamsplitters&lt;br /&gt;
&lt;br /&gt;
===[[Laser Microphone]]===&lt;br /&gt;
Team Members: [[User:Nicholas cjl|Nicholas Chong Jia Le]], [[User:Marcuslow|Marcus Low Zuo Wu]]&lt;br /&gt;
&lt;br /&gt;
A laser spot illuminating a vibrating surface should move along with it, and tracking the motion of the spot should theoretically allow us to retrieve some of the information regarding the vibrations of the surface. If a loud enough sound causes the surface to vibrate, this should theoretically be enough for the transmission of audio information through visual means. The signal obtained will then be put through a few different digital signal processing techniques in an attempt to retrieve a (good enough) copy of the original audio.&lt;br /&gt;
&lt;br /&gt;
===[[Argon gas discharge lamp]]===&lt;br /&gt;
Proposed By: Park Kun Hee&lt;br /&gt;
&lt;br /&gt;
Team Members: Park Kun Hee, Yang Jincheng, Qin Jingwen&lt;br /&gt;
&lt;br /&gt;
By applying a sufficiently high DC voltage across a gas, the gas atoms/molecules are ionised by the strong electric field.&lt;br /&gt;
In this project, we construct an Argon-based gas discharge lamp, with adjustable pressure and voltage.&lt;br /&gt;
The breakdown voltage of Argon gas with respect to pressure changes is observed, and compared with [https://en.wikipedia.org/wiki/Paschen%27s_law Paschen&#039;s law].&lt;br /&gt;
We also observe changes in the spectroscopic properties of the plasma with varying pressure.&lt;br /&gt;
&lt;br /&gt;
===[[Characterization of Single Photon Counters]]===&lt;br /&gt;
Proposed By: Yeo Zhen Yuan&lt;br /&gt;
&lt;br /&gt;
The project is to characterize an Avalanche PhotoDiode (APD) and compare its efficiency with commercial counterparts like [https://www.digikey.com/en/products/detail/excelitas-technologies/SPCM-AQRH-10-FC/6235280 this device]. It works based on the photoelectric effect to turn incident photon into photoelectron. This photoelectron is then accelerated in an electric field to produce cascading electrons and this &amp;quot;electron avalanche&amp;quot; is detected as a spike in the current. Analog signals will need to be processed via custom electronics and ultimately provide a digital readout. Current commercial detectors boast 50% Photon Detector Efficiency (PDE) at room temperature and that will be our goal. They typically cost $2000-$5000 which seems over-priced and ready for disruption. Liquid nitrogen temperatures may be needed to see how large a PDE we can get.&lt;br /&gt;
&lt;br /&gt;
What is SPCM good for? Copied from the datasheet/brochure: LIDAR, Quantum Cryptography, Photon correlation spectroscopy, Astronomical observation, Optical range finding, Adaptive optics, Ultra-sensitive fluorescence, Particle sizing, Microscopy. So maybe this would become a toy/tool for next year&#039;s students.&lt;br /&gt;
&lt;br /&gt;
[NEW CAPABILITY]&lt;br /&gt;
&lt;br /&gt;
High throughput Oscilloscope data collection. ~700 &amp;quot;screenshots&amp;quot; per minute. Demonstration on APD, 10K screenshots of 2 Channel Digital Oscilloscope [https://github.com/zhenyuan992/OpenWave-1KB/raw/88a85a7f18741b370563b03d87a53f913b714a4c/src/results03_01_apdvoltage.png].&lt;br /&gt;
&lt;br /&gt;
Semi-seamless data collection [https://www.tek.com/en/support/faqs/can-i-use-my-oscilloscope-do-data-logging].&lt;br /&gt;
&lt;br /&gt;
===[[Kerr Microscope]]===&lt;br /&gt;
Proposed By: Sim May Inn (write up by Joel Yeo)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Team members: Gan Jun Herng, Joel Yeo, Sim May Inn&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Project Location: S11-02-04&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Imaging a sample can be done in many ways, depending on the light-matter interaction we are interested in observing. The magneto-optic Kerr effect describes the change in polarization and intensity of incident light when it impinges on the surface of a magnetic material. The resultant reflected light can then form an image through focusing optics which provides high contrast between areas of different magnetization.&lt;br /&gt;
&lt;br /&gt;
In this project, we will be aiming to build a basic Kerr microscope using off-the-shelf polarizers, objectives, detectors and laser source. An example of a magnetic sample is the magnetic tape from an old school cassette tape. To increase the field of view, we also plan to incorporate automatic raster scanning of the sample through means of an Arduino-controlled sample stage.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Items needed (as of 28 Feb 2022):&#039;&#039;&#039;&lt;br /&gt;
* Light source (visibile wavelength): &amp;lt;s&amp;gt; Laser, LED &amp;lt;/s&amp;gt;, laser diode&lt;br /&gt;
* &amp;lt;s&amp;gt; Linear polarizer (sheet) x 2Camera (CCD/CMOS) &amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt; Non-polarizing beam splitter &amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt; Camera (CCD/CMOS) &amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt; Pinhole/aperture &amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt; Magnetic samples for Kerr microscopy (eg. Magnetic film, magnets, ferromagnetic materials) &amp;lt;/s&amp;gt;&lt;br /&gt;
* Arduino&lt;br /&gt;
* Microscope stage&lt;br /&gt;
* Piezoelectrics (?) for moving stage&lt;br /&gt;
&lt;br /&gt;
===[[Electron Gun]]===&lt;br /&gt;
Team Members: Aliki Sofia Rotelli, Lai Tian Hao, Lim En Liang Irvin, Tan Chuan Jie &lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to design and build an electron gun from the initial concept in order to create a detectable electron beam through the use of a phosphor-coated screen. Additionally, the beam current will be examined in order to better define the devices&#039; capabilities. Mass spectrometry, x-ray production for linear accelerators, and electron-beam lithography are just a few of the applications for electron gun technology.&lt;br /&gt;
&lt;br /&gt;
===[[Smoke detection in air]]===&lt;br /&gt;
Team Members: Cheng De Hao, Huang Hai Tao, Wang Zheng Yu &lt;br /&gt;
&lt;br /&gt;
Using detector to detect the scattering light and amplify the signal by using the lock-in amplifier.&lt;br /&gt;
&lt;br /&gt;
===[[Anti-glare LCD]]===&lt;br /&gt;
Team members: Zhang Yuanyuan, Ming Xiaohan, Han Shixin&lt;br /&gt;
&lt;br /&gt;
As s bad lighting phenomenon, glare phonomenon brings inconvenience to all aspects of human life, especially people&#039;s access to information on instruments. In order to suppress glare effectively, anti-glare film is put into research. The common anti-glare film in the market is an optical film using the principle of optical scattering, but it can not adapt to the change of light environment in time, which has some limitations in practical application. In this study, a two-dimensional barcode micro-region orientation structure, based on the characteristics of liquid crystal, namely a random grating structure, was designed by simulation in the lab and using MATLAB software, and its optional parameters were searched.&lt;br /&gt;
&lt;br /&gt;
===[[Custom atomic beam source]]===&lt;br /&gt;
Team Members: Lu Tiangao, Li Putian&lt;br /&gt;
&lt;br /&gt;
===[[Schlieren Imaging]]===&lt;br /&gt;
Team members: Zhang Xingjian, Du Jinyi&lt;br /&gt;
&lt;br /&gt;
We built a Schlieren imaging setup and saw the airflow generated by the lighter, the heat of the hand, and the blow. Other than that, we also make a high-frequency blinking light source to &amp;quot;stop&amp;quot; the 40 kHz ultrasound wave generated by an ultrasonic speaker and captured it by the Schlieren imaging setup.&lt;br /&gt;
&lt;br /&gt;
===[[Contactless Conductivity Measurement]]===&lt;br /&gt;
&lt;br /&gt;
Team members: Chen Guohao, Jiang Luwen&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to measure the conductivity of materials without having to make electrical contact with them. Specifically, we make use of the eddy-current induced in the materials to calculate the conductivity.&lt;br /&gt;
&lt;br /&gt;
===[[Quantum Random Number Generator]]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Proposed by: Zhang Munan&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Team members: Wang Yang, Xiao Yucan, Zhang Munan&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Venue: S14-03-04&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Random numbers are a fundamental resource in science and engineering with important applications in simulation and cryptography. The inherent randomness at the core of quantum mechanics makes quantum systems a perfect source of entropy. Quantum random number generation is one of the most mature quantum technologies with many alternative generation methods. The purpose of our project is to build a simple optics-based QRNG. We will also collect the random number generated by our device and use some methods to check the randomness.&lt;br /&gt;
&lt;br /&gt;
===[[Orbits of the Galilean Moons]]===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Team Members: [[User:Matthew|Matthew Wee]]&lt;br /&gt;
&lt;br /&gt;
Galileo Galilei’s discovery of celestial bodies that orbit something other than the Earth marked the beginning of the end of the geocentric model of the universe. In this project, we will perform the same observations on those moons as Galileo did 400 years ago.&lt;br /&gt;
&lt;br /&gt;
===[[A digital oscilloscope Based on MCU]]===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Team Members: Zhang Chengyue, Yang Ningli, Guo Diandian, Chen Jiayu&lt;br /&gt;
&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage sampling circuit, clock system, power supply and management module and so on. The software module mainly includes A/D sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, the measured range is 0-30V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
===[[Test]]===&lt;br /&gt;
Keep a very brief description of a project or even a suggestion here, and perhaps the names of the team members, or who to contact if there is interest to join.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
===[[Recorded sessions]]===&lt;br /&gt;
Some of the sessions will be recorded and uploaded to youtube. Find a description on the [[Recorded sessions]] page.&lt;br /&gt;
&lt;br /&gt;
===Devices and material===&lt;br /&gt;
Apart form all the stuff in the teaching lab, we have a few resources you may want to consider for your project&lt;br /&gt;
*...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Books:&#039;&#039;&#039;&lt;br /&gt;
* P.R. Bevington, D.K. Robinson: Data Reduction and Error Analysis for the Physical Sciences, 3rd edition. McGrawHill, ISBN0-07-119926-8. A very good book containing all the questions you never allowed yourself to ask about error treatment, statistics, fitting of data to models etc.&lt;br /&gt;
* Horrowitz/Hill: The Art of Electronics&lt;br /&gt;
* C.H. Moore, C.C. Davis, M.A. Coplan: Building Scientific Apparatus. 2nd or higher edition. Perseus Books, ISBN0-201-13189-7. A very comprehensive book about many dirty details in experimental physics, and ways to get simple problems solved. Appears a bit dated, but is a good start for many experimental projects up to this day!&lt;br /&gt;
* Christopher C. Davis: Laser and Electro-optics. Useful as a general introduction to many contemporary aspects you come across when working with lasers, with a reasonable introduction of the theory. Very practical for optics.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Software:&#039;&#039;&#039;&lt;br /&gt;
Some of the more common data processing tools used in experimental physics:&lt;br /&gt;
* [http://www.gnuplot.info/ &#039;&#039;&#039;Gnuplot&#039;&#039;&#039;]: A free and very mature data display tool that works on just about any platform used that produces excellent publication-grade eps and pdf figures. Can be also used in scripts. Open source and completely free.&lt;br /&gt;
* Various &#039;&#039;&#039;Python&#039;&#039;&#039; extensions. [http://www.python.org/ Python] is a very powerful free programming language that runs on just about any computer platform. It is open source and completely free.&lt;br /&gt;
* &#039;&#039;&#039;Matlab&#039;&#039;&#039;: Very common, good toolset also for formal mathematics, good graphics. Expensive. We may have a site license, but I am not sure how painful it is for us to get a license for this course. Ask me if interested.&lt;br /&gt;
* &#039;&#039;&#039;Mathematica&#039;&#039;&#039;: More common among theroetical physicists, very good in formal maths, now with better numerics. Graphs are ok but can be a pain to make looking good. As with Matlab, we do have a campus license but an increasingly painful licensing ritual. Ask me if interested or follow the instruction to install the software in your desktop.&lt;br /&gt;
* &#039;&#039;&#039;Origin&#039;&#039;&#039;: Very widespread data processing software with a complete graphical user interface, integrates well into a Windows environment. Most likely available in your research labs, not sure if NUS has a site license.&lt;br /&gt;
* &#039;&#039;&#039;Labview&#039;&#039;&#039;: Many of you may have seen this in your labs, but I am not too familiar with it, and chances are it is too resource-hungry to run on the machines we have there. It keeps its promise of a fast learning curve if you want to do simple things but it can get a REAL pain if you want to do subtle things, or want to do things fast, or want to debug code. Expensive and resource-hungry, but comes with good integration of also expensive hardware. May not be worth it if you know any programming language.&lt;br /&gt;
* [https://www.circuitlab.com/ &#039;&#039;&#039;Circuit Lab&#039;&#039;&#039;]: a convenient software to design and simulate electrical circuits directly at your browser. I think Flash is required. It works well in Chrome.&lt;br /&gt;
&lt;br /&gt;
===[[Acronym database]]===&lt;br /&gt;
This is an attempt to clarify the countless acronyms we use in our sub-communities (follow headline link)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===[[Gnuplot tricks]]===&lt;br /&gt;
Follow the headline link for some of the random questions that came up with gnuplot.&lt;br /&gt;
&lt;br /&gt;
== Previous PC5214 wikis ==&lt;br /&gt;
* [http://pc5214.org/AY1819S2 AY2018/19 Sem2]&lt;br /&gt;
* [http://pc5214.org/AY1415S1 AY2014/15 Sem1]&lt;br /&gt;
* [http://pc5214.org/AY1314S1 AY2013/14 Sem1]&lt;br /&gt;
* [http://pc5214.org/AY1213S1 AY2012/13 Sem1]&lt;br /&gt;
* [http://pc5214.org/AY1112S1 AY2011/12 Sem1]&lt;br /&gt;
* [http://pc5214.org/AY1011S1 AY2010/11 Sem1]&lt;br /&gt;
&lt;br /&gt;
== Some wiki reference materials==&lt;br /&gt;
Consult the [//meta.wikimedia.org/wiki/Help:Contents User&#039;s Guide] for information on using the wiki software. Other sources:&lt;br /&gt;
&lt;br /&gt;
* [//www.mediawiki.org/wiki/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [[Writing mathematical expressions]]&lt;br /&gt;
* [[Uploading images]]&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=Main_Page&amp;diff=3588</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=Main_Page&amp;diff=3588"/>
		<updated>2022-04-30T14:08:56Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* A digital oscilloscope Based on MCU */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;strong&amp;gt;MediaWiki has been installed.&amp;lt;/strong&amp;gt;&lt;br /&gt;
Welcome to the main page for the PC5214 graduate module AY2122, Sem2&amp;lt;/strong&amp;gt;.&lt;br /&gt;
Here, we leave project descriptions, literature references, and other collateral information. You will need to create an account in class to obtain write access.&lt;br /&gt;
&lt;br /&gt;
Actual lecture locations will be placed here until we have reached a stable state. If you are interested and have not been able to register, please send me an email (if you have not done so already) to [mailto:phyck@nus.edu.sg phyck@nus.edu.sg].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;Deadline for all the wiki entries will be 30 April 2022, 23:59! Please ensure that you hare happy with your entries by that time!&amp;lt;/span&amp;gt;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Cheers, Christian&lt;br /&gt;
&lt;br /&gt;
This page is currently set up.&lt;br /&gt;
&lt;br /&gt;
==Lab spaces==&lt;br /&gt;
* &#039;&#039;&#039;S11-02-04&#039;&#039;&#039; (next to physics dept resource room). This is where most optics-related projects should go.&lt;br /&gt;
* &#039;&#039;&#039;S12 level 4&#039;&#039;&#039;, &amp;quot;year 1 teaching lab&amp;quot;, back room, &amp;quot;vanderGraff lab&amp;quot;. This is perhaps were non-optics related projects would fit.&lt;br /&gt;
* &#039;&#039;&#039;S13-01-??&#039;&#039;&#039; (blue door: former accoustics lab). Not sure yet who could go there, but it is a really really quiet place!&lt;br /&gt;
* anything else you have access to&lt;br /&gt;
&lt;br /&gt;
==Projects==&lt;br /&gt;
Please leave a a link to your project page (or pages) here, and leave a short description what this is about. Write the &#039;&#039;&#039;stuff you need&#039;&#039;&#039; under the description too.&lt;br /&gt;
&lt;br /&gt;
===[[Project 1 (example)]]===&lt;br /&gt;
Keep a very brief description of a project or even a suggestion here, and perhaps the names of the team members, or who to contact if there is interest to join.&lt;br /&gt;
&lt;br /&gt;
===[[Confocal Microscopy]]===&lt;br /&gt;
Team Members: Wang Tingyu, Xue Rui, Yang Hengxing&lt;br /&gt;
&lt;br /&gt;
A Confocal Microscopy or Confocal Laser Scanning Microscopy (CLSM) uses pinhole to block out all out of focus light to enhance optical resolution, very different from traditional wide-field fluorescence microscopes. To offset the block of out of focus lights, the light intensity is detected by a photomultiplier tube or avalanche photodiode, which transforms the light signal into an electrical one. We will try to build a Setup like this to enhance optical resolution and maybe get profile information about the sample.&lt;br /&gt;
&lt;br /&gt;
===[[Resonance frequency measurement using a interferometric method]]===&lt;br /&gt;
&lt;br /&gt;
Members: [[User:Nakarin|Nakarin Jayjong]], [[User:Aucca|Joel Auccapuclla]], [[User:Xiaoyu|Xiaoyu Nie]], [[User:Haotian|Haotian Song]].&lt;br /&gt;
&lt;br /&gt;
In this project, the resonance frequency of the vibrating system namely the vibration transducer is measured using a Michelson interferometer.&lt;br /&gt;
&lt;br /&gt;
===[[Homodyne detection]]===&lt;br /&gt;
Proposed By: [[User:Johnkhootf|John Khoo]]&lt;br /&gt;
&lt;br /&gt;
Team Members: [[User:Johnkhootf|John Khoo]], [[User:Xie_Chengkun|Xie Chengkun]]&lt;br /&gt;
&lt;br /&gt;
[https://en.wikipedia.org/wiki/Homodyne_detection &#039;&#039;Optical&#039;&#039; homodyne detection] is a method for detecting messages transmitted in optical signals, where a frequency or phase modulated signal is compared to what is misleadingly called the &amp;quot;local oscillator&amp;quot; (LO) signal, which is generated from the same source but not modulated with the message. In order to probe quantum effects, it is important to bring the noise of the detector down to the [https://en.wikipedia.org/wiki/Shot_noise &#039;&#039;shot-noise limit&#039;&#039;], where the only fluctuations observed arise from the discrete nature of photons, which can be theoretically modelled as the vacuum-state fluctuations of the quantised electromagnetic field. This project&#039;s first objective is to build a homodyne detector from scratch.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Stuff we need&#039;&#039;&#039;: Acousto-optical modulator, electro-optical modulator, transformer to control EOM, photodiodes, current-to-voltage converter (I&#039;m not sure what this is - can we just use a resistor connected to the ground and measure the voltage?), Raspberry Pi (I hope the ADC is good enough for this), mirrors and beamsplitters&lt;br /&gt;
&lt;br /&gt;
===[[Laser Microphone]]===&lt;br /&gt;
Team Members: [[User:Nicholas cjl|Nicholas Chong Jia Le]], [[User:Marcuslow|Marcus Low Zuo Wu]]&lt;br /&gt;
&lt;br /&gt;
A laser spot illuminating a vibrating surface should move along with it, and tracking the motion of the spot should theoretically allow us to retrieve some of the information regarding the vibrations of the surface. If a loud enough sound causes the surface to vibrate, this should theoretically be enough for the transmission of audio information through visual means. The signal obtained will then be put through a few different digital signal processing techniques in an attempt to retrieve a (good enough) copy of the original audio.&lt;br /&gt;
&lt;br /&gt;
===[[Argon gas discharge lamp]]===&lt;br /&gt;
Proposed By: Park Kun Hee&lt;br /&gt;
&lt;br /&gt;
Team Members: Park Kun Hee, Yang Jincheng, Qin Jingwen&lt;br /&gt;
&lt;br /&gt;
By applying a sufficiently high DC voltage across a gas, the gas atoms/molecules are ionised by the strong electric field.&lt;br /&gt;
In this project, we construct an Argon-based gas discharge lamp, with adjustable pressure and voltage.&lt;br /&gt;
The breakdown voltage of Argon gas with respect to pressure changes is observed, and compared with [https://en.wikipedia.org/wiki/Paschen%27s_law Paschen&#039;s law].&lt;br /&gt;
We also observe changes in the spectroscopic properties of the plasma with varying pressure.&lt;br /&gt;
&lt;br /&gt;
===[[Characterization of Single Photon Counters]]===&lt;br /&gt;
Proposed By: Yeo Zhen Yuan&lt;br /&gt;
&lt;br /&gt;
The project is to characterize an Avalanche PhotoDiode (APD) and compare its efficiency with commercial counterparts like [https://www.digikey.com/en/products/detail/excelitas-technologies/SPCM-AQRH-10-FC/6235280 this device]. It works based on the photoelectric effect to turn incident photon into photoelectron. This photoelectron is then accelerated in an electric field to produce cascading electrons and this &amp;quot;electron avalanche&amp;quot; is detected as a spike in the current. Analog signals will need to be processed via custom electronics and ultimately provide a digital readout. Current commercial detectors boast 50% Photon Detector Efficiency (PDE) at room temperature and that will be our goal. They typically cost $2000-$5000 which seems over-priced and ready for disruption. Liquid nitrogen temperatures may be needed to see how large a PDE we can get.&lt;br /&gt;
&lt;br /&gt;
What is SPCM good for? Copied from the datasheet/brochure: LIDAR, Quantum Cryptography, Photon correlation spectroscopy, Astronomical observation, Optical range finding, Adaptive optics, Ultra-sensitive fluorescence, Particle sizing, Microscopy. So maybe this would become a toy/tool for next year&#039;s students.&lt;br /&gt;
&lt;br /&gt;
[NEW CAPABILITY]&lt;br /&gt;
&lt;br /&gt;
High throughput Oscilloscope data collection. ~700 &amp;quot;screenshots&amp;quot; per minute. Demonstration on APD, 10K screenshots of 2 Channel Digital Oscilloscope [https://github.com/zhenyuan992/OpenWave-1KB/raw/88a85a7f18741b370563b03d87a53f913b714a4c/src/results03_01_apdvoltage.png].&lt;br /&gt;
&lt;br /&gt;
Semi-seamless data collection [https://www.tek.com/en/support/faqs/can-i-use-my-oscilloscope-do-data-logging].&lt;br /&gt;
&lt;br /&gt;
===[[Kerr Microscope]]===&lt;br /&gt;
Proposed By: Sim May Inn (write up by Joel Yeo)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Team members: Gan Jun Herng, Joel Yeo, Sim May Inn&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Project Location: S11-02-04&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Imaging a sample can be done in many ways, depending on the light-matter interaction we are interested in observing. The magneto-optic Kerr effect describes the change in polarization and intensity of incident light when it impinges on the surface of a magnetic material. The resultant reflected light can then form an image through focusing optics which provides high contrast between areas of different magnetization.&lt;br /&gt;
&lt;br /&gt;
In this project, we will be aiming to build a basic Kerr microscope using off-the-shelf polarizers, objectives, detectors and laser source. An example of a magnetic sample is the magnetic tape from an old school cassette tape. To increase the field of view, we also plan to incorporate automatic raster scanning of the sample through means of an Arduino-controlled sample stage.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Items needed (as of 28 Feb 2022):&#039;&#039;&#039;&lt;br /&gt;
* Light source (visibile wavelength): &amp;lt;s&amp;gt; Laser, LED &amp;lt;/s&amp;gt;, laser diode&lt;br /&gt;
* &amp;lt;s&amp;gt; Linear polarizer (sheet) x 2Camera (CCD/CMOS) &amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt; Non-polarizing beam splitter &amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt; Camera (CCD/CMOS) &amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt; Pinhole/aperture &amp;lt;/s&amp;gt;&lt;br /&gt;
* &amp;lt;s&amp;gt; Magnetic samples for Kerr microscopy (eg. Magnetic film, magnets, ferromagnetic materials) &amp;lt;/s&amp;gt;&lt;br /&gt;
* Arduino&lt;br /&gt;
* Microscope stage&lt;br /&gt;
* Piezoelectrics (?) for moving stage&lt;br /&gt;
&lt;br /&gt;
===[[Electron Gun]]===&lt;br /&gt;
Team Members: Aliki Sofia Rotelli, Lai Tian Hao, Lim En Liang Irvin, Tan Chuan Jie &lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to design and build an electron gun from the initial concept in order to create a detectable electron beam through the use of a phosphor-coated screen. Additionally, the beam current will be examined in order to better define the devices&#039; capabilities. Mass spectrometry, x-ray production for linear accelerators, and electron-beam lithography are just a few of the applications for electron gun technology.&lt;br /&gt;
&lt;br /&gt;
===[[Smoke detection in air]]===&lt;br /&gt;
Team Members: Cheng De Hao, Huang Hai Tao, Wang Zheng Yu &lt;br /&gt;
&lt;br /&gt;
Using detector to detect the scattering light and amplify the signal by using the lock-in amplifier.&lt;br /&gt;
&lt;br /&gt;
===[[Anti-glare LCD]]===&lt;br /&gt;
Team members: Zhang Yuanyuan, Ming Xiaohan, Han Shixin&lt;br /&gt;
&lt;br /&gt;
As s bad lighting phenomenon, glare phonomenon brings inconvenience to all aspects of human life, especially people&#039;s access to information on instruments. In order to suppress glare effectively, anti-glare film is put into research. The common anti-glare film in the market is an optical film using the principle of optical scattering, but it can not adapt to the change of light environment in time, which has some limitations in practical application. In this study, a two-dimensional barcode micro-region orientation structure, based on the characteristics of liquid crystal, namely a random grating structure, was designed by simulation in the lab and using MATLAB software, and its optional parameters were searched.&lt;br /&gt;
&lt;br /&gt;
===[[Custom atomic beam source]]===&lt;br /&gt;
Team Members: Lu Tiangao, Li Putian&lt;br /&gt;
&lt;br /&gt;
===[[Schlieren Imaging]]===&lt;br /&gt;
Team members: Zhang Xingjian, Du Jinyi&lt;br /&gt;
&lt;br /&gt;
We built a Schlieren imaging setup and saw the airflow generated by the lighter, the heat of the hand, and the blow. Other than that, we also make a high-frequency blinking light source to &amp;quot;stop&amp;quot; the 40 kHz ultrasound wave generated by an ultrasonic speaker and captured it by the Schlieren imaging setup.&lt;br /&gt;
&lt;br /&gt;
===[[Contactless Conductivity Measurement]]===&lt;br /&gt;
&lt;br /&gt;
Team members: Chen Guohao, Jiang Luwen&lt;br /&gt;
&lt;br /&gt;
The purpose of this project is to measure the conductivity of materials without having to make electrical contact with them. Specifically, we make use of the eddy-current induced in the materials to calculate the conductivity.&lt;br /&gt;
&lt;br /&gt;
===[[Quantum Random Number Generator]]===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Proposed by: Zhang Munan&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Team members: Wang Yang, Xiao Yucan, Zhang Munan&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Venue: S14-03-04&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Random numbers are a fundamental resource in science and engineering with important applications in simulation and cryptography. The inherent randomness at the core of quantum mechanics makes quantum systems a perfect source of entropy. Quantum random number generation is one of the most mature quantum technologies with many alternative generation methods. The purpose of our project is to build a simple optics-based QRNG. We will also collect the random number generated by our device and use some methods to check the randomness.&lt;br /&gt;
&lt;br /&gt;
===[[Orbits of the Galilean Moons]]===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Team Members: [[User:Matthew|Matthew Wee]]&lt;br /&gt;
&lt;br /&gt;
Galileo Galilei’s discovery of celestial bodies that orbit something other than the Earth marked the beginning of the end of the geocentric model of the universe. In this project, we will perform the same observations on those moons as Galileo did 400 years ago.&lt;br /&gt;
&lt;br /&gt;
===[[A Digital Oscilloscope Based on MCU]]===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Team Members: Zhang Chengyue, Yang Ningli, Guo Diandian, Chen Jiayu&lt;br /&gt;
&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage sampling circuit, clock system, power supply and management module and so on. The software module mainly includes A/D sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, the measured range is 0-30V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
===[[Test]]===&lt;br /&gt;
Keep a very brief description of a project or even a suggestion here, and perhaps the names of the team members, or who to contact if there is interest to join.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
===[[Recorded sessions]]===&lt;br /&gt;
Some of the sessions will be recorded and uploaded to youtube. Find a description on the [[Recorded sessions]] page.&lt;br /&gt;
&lt;br /&gt;
===Devices and material===&lt;br /&gt;
Apart form all the stuff in the teaching lab, we have a few resources you may want to consider for your project&lt;br /&gt;
*...&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Books:&#039;&#039;&#039;&lt;br /&gt;
* P.R. Bevington, D.K. Robinson: Data Reduction and Error Analysis for the Physical Sciences, 3rd edition. McGrawHill, ISBN0-07-119926-8. A very good book containing all the questions you never allowed yourself to ask about error treatment, statistics, fitting of data to models etc.&lt;br /&gt;
* Horrowitz/Hill: The Art of Electronics&lt;br /&gt;
* C.H. Moore, C.C. Davis, M.A. Coplan: Building Scientific Apparatus. 2nd or higher edition. Perseus Books, ISBN0-201-13189-7. A very comprehensive book about many dirty details in experimental physics, and ways to get simple problems solved. Appears a bit dated, but is a good start for many experimental projects up to this day!&lt;br /&gt;
* Christopher C. Davis: Laser and Electro-optics. Useful as a general introduction to many contemporary aspects you come across when working with lasers, with a reasonable introduction of the theory. Very practical for optics.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Software:&#039;&#039;&#039;&lt;br /&gt;
Some of the more common data processing tools used in experimental physics:&lt;br /&gt;
* [http://www.gnuplot.info/ &#039;&#039;&#039;Gnuplot&#039;&#039;&#039;]: A free and very mature data display tool that works on just about any platform used that produces excellent publication-grade eps and pdf figures. Can be also used in scripts. Open source and completely free.&lt;br /&gt;
* Various &#039;&#039;&#039;Python&#039;&#039;&#039; extensions. [http://www.python.org/ Python] is a very powerful free programming language that runs on just about any computer platform. It is open source and completely free.&lt;br /&gt;
* &#039;&#039;&#039;Matlab&#039;&#039;&#039;: Very common, good toolset also for formal mathematics, good graphics. Expensive. We may have a site license, but I am not sure how painful it is for us to get a license for this course. Ask me if interested.&lt;br /&gt;
* &#039;&#039;&#039;Mathematica&#039;&#039;&#039;: More common among theroetical physicists, very good in formal maths, now with better numerics. Graphs are ok but can be a pain to make looking good. As with Matlab, we do have a campus license but an increasingly painful licensing ritual. Ask me if interested or follow the instruction to install the software in your desktop.&lt;br /&gt;
* &#039;&#039;&#039;Origin&#039;&#039;&#039;: Very widespread data processing software with a complete graphical user interface, integrates well into a Windows environment. Most likely available in your research labs, not sure if NUS has a site license.&lt;br /&gt;
* &#039;&#039;&#039;Labview&#039;&#039;&#039;: Many of you may have seen this in your labs, but I am not too familiar with it, and chances are it is too resource-hungry to run on the machines we have there. It keeps its promise of a fast learning curve if you want to do simple things but it can get a REAL pain if you want to do subtle things, or want to do things fast, or want to debug code. Expensive and resource-hungry, but comes with good integration of also expensive hardware. May not be worth it if you know any programming language.&lt;br /&gt;
* [https://www.circuitlab.com/ &#039;&#039;&#039;Circuit Lab&#039;&#039;&#039;]: a convenient software to design and simulate electrical circuits directly at your browser. I think Flash is required. It works well in Chrome.&lt;br /&gt;
&lt;br /&gt;
===[[Acronym database]]===&lt;br /&gt;
This is an attempt to clarify the countless acronyms we use in our sub-communities (follow headline link)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===[[Gnuplot tricks]]===&lt;br /&gt;
Follow the headline link for some of the random questions that came up with gnuplot.&lt;br /&gt;
&lt;br /&gt;
== Previous PC5214 wikis ==&lt;br /&gt;
* [http://pc5214.org/AY1819S2 AY2018/19 Sem2]&lt;br /&gt;
* [http://pc5214.org/AY1415S1 AY2014/15 Sem1]&lt;br /&gt;
* [http://pc5214.org/AY1314S1 AY2013/14 Sem1]&lt;br /&gt;
* [http://pc5214.org/AY1213S1 AY2012/13 Sem1]&lt;br /&gt;
* [http://pc5214.org/AY1112S1 AY2011/12 Sem1]&lt;br /&gt;
* [http://pc5214.org/AY1011S1 AY2010/11 Sem1]&lt;br /&gt;
&lt;br /&gt;
== Some wiki reference materials==&lt;br /&gt;
Consult the [//meta.wikimedia.org/wiki/Help:Contents User&#039;s Guide] for information on using the wiki software. Other sources:&lt;br /&gt;
&lt;br /&gt;
* [//www.mediawiki.org/wiki/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [[Writing mathematical expressions]]&lt;br /&gt;
* [[Uploading images]]&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3583</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3583"/>
		<updated>2022-04-30T14:07:55Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
[[File:|center]]&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3581</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3581"/>
		<updated>2022-04-30T14:07:21Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3573</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3573"/>
		<updated>2022-04-30T13:59:40Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
The code was written in C. Use Keil software to edit and compile.&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3566</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3566"/>
		<updated>2022-04-30T13:46:36Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Future improvement can be done */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3564</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3564"/>
		<updated>2022-04-30T13:46:14Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Reference */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3563</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3563"/>
		<updated>2022-04-30T13:44:54Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Discussion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
https://datasheetspdf.com/pdf-file/1305880/STCMCU/STC8A8K64S4A12/1&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3552</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3552"/>
		<updated>2022-04-30T13:33:33Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Future improvement can be done */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3549</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3549"/>
		<updated>2022-04-30T13:32:50Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Future improvement can be done */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a simple digital oscilloscope. We learned how to design a MCU circuit board. We did everything from reading and interpreting datasheets to trouble programming errors. By successfully completing these tasks and producing the functional circuit board digital oscilloscope, we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3540</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3540"/>
		<updated>2022-04-30T13:28:59Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Hardware circuit module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
Each component has its own function and connection:&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we refer to the pin definition table in the Microcontroller datasheet which shows all of the various functions available for each pin, and we confirm that every functions required for our project.&lt;br /&gt;
&lt;br /&gt;
b. Booster: Power module with Li-ion battery charging management and booster function. Bat+&amp;amp;Bat- port connect to the battery and switch. The Vout+&amp;amp;Vout- Port can output an adjustable voltage by rotating the potentiometer.&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add two resistor in series as voltage dividing for voltage sampling of battery, which serve to convert an input voltage signal ranging from 0V to +27V to a scaled signal ranging from 0 to +5V.This is done to protect the microcontroller which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3537</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3537"/>
		<updated>2022-04-30T13:27:28Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The main program sets the initial state of the port, the encoder interrupt mode and the timer, and implements the functions by calling other functions.&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3515</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3515"/>
		<updated>2022-04-30T13:12:52Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value &lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3507</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3507"/>
		<updated>2022-04-30T13:06:58Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3505</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3505"/>
		<updated>2022-04-30T13:06:25Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {            runWhenInSettrings();        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {            runWhenADCInterrupt();        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {            runWhenADCComplete();        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3504</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3504"/>
		<updated>2022-04-30T13:05:24Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Clear TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenInSettrings();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCInterrupt();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCComplete();&lt;br /&gt;
        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3500</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3500"/>
		<updated>2022-04-30T13:04:17Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Cleat TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenInSettrings();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCInterrupt();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCComplete();&lt;br /&gt;
        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit; b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3499</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3499"/>
		<updated>2022-04-30T13:03:18Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Cleat TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenInSettrings();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCInterrupt();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCComplete();&lt;br /&gt;
        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；                 b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3498</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3498"/>
		<updated>2022-04-30T13:03:03Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Cleat TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenInSettrings();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCInterrupt();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCComplete();&lt;br /&gt;
        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；      b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 power module setting]]&lt;br /&gt;
&lt;br /&gt;
Then we connect battery to power management module, adjust the potentiometer to change output voltage and make the output voltage to be about +5V(Figure.6).&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3497</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3497"/>
		<updated>2022-04-30T13:02:08Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Cleat TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenInSettrings();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCInterrupt();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCComplete();&lt;br /&gt;
        }&lt;br /&gt;
    }}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；    b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 Booster setting]]&lt;br /&gt;
&lt;br /&gt;
Then the booster were set to give an output voltage of +5V.&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3495</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3495"/>
		<updated>2022-04-30T13:01:51Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main(){&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Cleat TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenInSettrings();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCInterrupt();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCComplete();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；    b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 Booster setting]]&lt;br /&gt;
&lt;br /&gt;
Then the booster were set to give an output voltage of +5V.&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3493</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3493"/>
		<updated>2022-04-30T13:01:10Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 *void main()&lt;br /&gt;
{&lt;br /&gt;
    /* Set ADC port P0.4, P0.6 as high-impedance */&lt;br /&gt;
    P0M1 |= 0x50;&lt;br /&gt;
    P0M0 &amp;amp;= ~0x50;&lt;br /&gt;
&lt;br /&gt;
    /* Set indicator port P1.1 as push-pull output */&lt;br /&gt;
    P0M1 &amp;amp;= ~0x02;&lt;br /&gt;
    P0M0 |= 0x02;&lt;br /&gt;
&lt;br /&gt;
    /* Set Encoder port P3.2, P3.3, P3.4 as quasi bidirectional */&lt;br /&gt;
    P3M1 &amp;amp;= ~0x1C;&lt;br /&gt;
    P3M0 &amp;amp;= ~0x1C;&lt;br /&gt;
&lt;br /&gt;
    /* Set OLED port P2.3, P2.4, P2.5, P2.6 as quasi bidirectional */&lt;br /&gt;
    P2M1 &amp;amp;= ~0xF8;&lt;br /&gt;
    P2M0 &amp;amp;= ~0xF8;&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for rotating of Encoder */&lt;br /&gt;
    IT0 = 0; //Rising edge triggered for external interrupt 0&lt;br /&gt;
    PX0 = 1; //High priority for external interrupt 0. Used to judge when pressing and rotating at the same time&lt;br /&gt;
    EX0 = 1; //Enable external interrupt 0&lt;br /&gt;
&lt;br /&gt;
    /* Interrupt for clicking of Encoder */&lt;br /&gt;
    IT1 = 1; //Falling edge triggered for external interrupt 1&lt;br /&gt;
    PX1 = 0; //Low priority for external interrupt 1. &lt;br /&gt;
    EX1 = 1; //Enable external interrupt 1&lt;br /&gt;
&lt;br /&gt;
    /* Timer 0, for updating voltage of battery */&lt;br /&gt;
    AUXR &amp;amp;= 0x7F; //12T mode for timer&lt;br /&gt;
    TMOD &amp;amp;= 0xF0; //Set mode for timer&lt;br /&gt;
    TL0 = 0x46;   //Set the timing initial value //27MHz£¬25ms&lt;br /&gt;
    TH0 = 0x24;   //Set the timing initial value&lt;br /&gt;
    TF0 = 0;      //Cleat TF0&lt;br /&gt;
    ET0 = 1;      //Enable timer 0 interrupt&lt;br /&gt;
&lt;br /&gt;
    /* Enable global interrupt */&lt;br /&gt;
    EA = 1;&lt;br /&gt;
&lt;br /&gt;
    //UartInit();&lt;br /&gt;
&lt;br /&gt;
    Read_Options();&lt;br /&gt;
    init();&lt;br /&gt;
    OLED_Init();&lt;br /&gt;
    OLED_SetFontWidth(6);&lt;br /&gt;
    PlotChart();&lt;br /&gt;
    OLED_Display();&lt;br /&gt;
&lt;br /&gt;
    while (1)&lt;br /&gt;
    {&lt;br /&gt;
        P_Ready = 0;&lt;br /&gt;
&lt;br /&gt;
        /* Sampling*/&lt;br /&gt;
        GetWaveData();&lt;br /&gt;
&lt;br /&gt;
        /* Enter Settings Interface */&lt;br /&gt;
        if (InSettings)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenInSettrings();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Interrupt */&lt;br /&gt;
        else if (ADCInterrupt)&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCInterrupt();&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* ADC Sampling Complete */&lt;br /&gt;
        else&lt;br /&gt;
        {&lt;br /&gt;
            runWhenADCComplete();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；    b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 Booster setting]]&lt;br /&gt;
&lt;br /&gt;
Then the booster were set to give an output voltage of +5V.&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3481</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3481"/>
		<updated>2022-04-30T12:53:47Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Software program module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
 * Here is an Arduino sketch to read the output voltage of the photodiode detectors. &lt;br /&gt;
   The output pin of the circuit is connected to analog pin 0 of the Arduino. &lt;br /&gt;
   The data are read every 0.025 second in this example. &lt;br /&gt;
   However, you can change the sampling rate by simply changing the argument of the delay() statement. *&lt;br /&gt;
   &lt;br /&gt;
   #define inPin0 0&lt;br /&gt;
   void setup(void) {&lt;br /&gt;
     Serial.begin(9600);&lt;br /&gt;
     Serial.println();&lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
  void loop(void) {&lt;br /&gt;
  float pinRead0 = analogRead(inPin0);&lt;br /&gt;
  Serial.println(pinRead0);&lt;br /&gt;
  /* the minimum delay allowed is about 20, correspond&lt;br /&gt;
  is about 20ms */}&lt;br /&gt;
  delay(25);    &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；    b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 Booster setting]]&lt;br /&gt;
&lt;br /&gt;
Then the booster were set to give an output voltage of +5V.&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3462</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3462"/>
		<updated>2022-04-30T11:26:52Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；    b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|450px|Fig.6 Booster setting]]&lt;br /&gt;
&lt;br /&gt;
Then the booster were set to give an output voltage of +5V.&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3461</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3461"/>
		<updated>2022-04-30T11:26:35Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；    b: Front of the actual circuit]]&lt;br /&gt;
[[File:微信图片 20220430190245.jpg|thumb|center|750px|Fig.6 Booster setting]]&lt;br /&gt;
&lt;br /&gt;
Then the booster were set to give an output voltage of +5V.&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=File:%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20220430190245.jpg&amp;diff=3458</id>
		<title>File:微信图片 20220430190245.jpg</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=File:%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20220430190245.jpg&amp;diff=3458"/>
		<updated>2022-04-30T11:22:40Z</updated>

		<summary type="html">&lt;p&gt;Diandian: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3457</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3457"/>
		<updated>2022-04-30T11:22:21Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic. The actual circuit we got finally is shown in figure 5.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；    b: Front of the actual circuit]]&lt;br /&gt;
&lt;br /&gt;
Then the booster were set to give an output voltage of +5V.&lt;br /&gt;
&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3453</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3453"/>
		<updated>2022-04-30T11:15:44Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit；    b: Front of the actual circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3452</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3452"/>
		<updated>2022-04-30T11:15:18Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|750px|Fig.5 a: Back of the actual circuit； b: Front of the actual circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3451</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3451"/>
		<updated>2022-04-30T11:14:15Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|650px|Fig.5 Actual soldered circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3450</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3450"/>
		<updated>2022-04-30T11:14:06Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 3:Circuit soldering */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|550px|Fig.5 Actual soldered circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=File:Actual_soldered_circuit.jpg&amp;diff=3448</id>
		<title>File:Actual soldered circuit.jpg</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=File:Actual_soldered_circuit.jpg&amp;diff=3448"/>
		<updated>2022-04-30T11:13:12Z</updated>

		<summary type="html">&lt;p&gt;Diandian: Diandian uploaded a new version of File:Actual soldered circuit.jpg&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3445</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3445"/>
		<updated>2022-04-30T11:06:00Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Hardware circuit module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
All of the key components of entire circuit is shown as below:&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|350px|Fig.5 Actual soldered circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3441</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3441"/>
		<updated>2022-04-30T11:02:24Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Design idea */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. We selected this microcontroller because it offers moderate performance. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
The Hardware circuit is mainly divided into following parts and respective function are listed as follows：&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|350px|Fig.5 Actual soldered circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3439</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3439"/>
		<updated>2022-04-30T10:58:11Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Hardware circuit module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. It is a new generation of microcontroller with wide voltage range, high speed, high reliability, low power and super strong anti-interference. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
The Hardware circuit is mainly divided into following parts and respective function are listed as follows：&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: It is the most important part of entire circuit. Before designing the circuit, we went through microcontroller manual carefully and figured out pinouts and pin&lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display:In order to clearly displaying and drawing waveform in the screen, the SSD display should connect to ADC analog input channel(Pin38&amp;amp;39),Enhanced PWM output channel(Pin37)and PCA capture input and pulse output channel(Pin35&amp;amp;36)in the STC microcontroller.&lt;br /&gt;
&lt;br /&gt;
h. Socket strip: When a USB to TTL downloader connect to it, we can download the code to Microcontroller.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor):Add a resistor as voltage dividing for voltage sampling of battery. which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|350px|Fig.5 Actual soldered circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3430</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3430"/>
		<updated>2022-04-30T10:50:33Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 4:Programming and downloading the code to microcontroller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. It is a new generation of microcontroller with wide voltage range, high speed, high reliability, low power and super strong anti-interference. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
The Hardware circuit is mainly divided into following parts and respective function are listed as follows：&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: &lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display: &lt;br /&gt;
&lt;br /&gt;
h.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor): which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|350px|Fig.5 Actual soldered circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB as shown in figure 7. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
	<entry>
		<id>https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3429</id>
		<title>A digital oscilloscope Based on MCU</title>
		<link rel="alternate" type="text/html" href="https://pc5214.org/index.php?title=A_digital_oscilloscope_Based_on_MCU&amp;diff=3429"/>
		<updated>2022-04-30T10:49:37Z</updated>

		<summary type="html">&lt;p&gt;Diandian: /* Step 4:Programming and downloading the code to microcontroller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
We design a digital oscilloscope with STC8A8K chip as the control core, which mainly consists of two modules: hardware circuit and software program. The hardware module mainly includes OLED screen, voltage divider circuit, filter circuit, clock system, power supply and management module and so on. The software module mainly includes ADC sampling, OLED display, interrupt timing and some necessary data processing. its measurable bandwidth is 0-3000Hz, and measured range is 0-27V. After many tests and comparisons, the design achieves the amplification and reduction of waveform and the measurement of different frequency waveform in the experimental process, so as to achieve the desired goal.&lt;br /&gt;
&lt;br /&gt;
== Methodology ==&lt;br /&gt;
=== Design idea===&lt;br /&gt;
The overall circuit is shown in Figure.1. The core component of this circuit is STC8A8K64S4A12 chip, which is single clock/machine cycle microcontroller produced by STC Co. Ltd. It is a new generation of microcontroller with wide voltage range, high speed, high reliability, low power and super strong anti-interference. Rich digital peripherals and analog peripherals are provided in this microcontroller, including 4 serial ports, 5 timers, 4 sets of PCA, 8 groups of enhanced PWM and I2C, SPI, 16 channels 12 bit ADC and comparator, which can meet almost all the needs of users when designing a product.&lt;br /&gt;
&lt;br /&gt;
For this project, we use the serial port control send and receive a string of characters to/from an encoder, which can ensure serial data transmission between encoder and microcontroller. Also, the enhanced PMW current can light up the OLED, and the display driver IC and display peripheral supporting IC work together on the OLED display and determine its current display state. &lt;br /&gt;
&lt;br /&gt;
In a digital oscilloscope, the analog signal is at the input, after amplification and preliminary filtering, goes to an analog-to-digital converter (ADC) with an external clock. Analog-to-digital conversion takes place by means of sampling.The samples are taken at specific rates and the amplitude of each sample is measured and stored. Intuitively, we know that the accuracy of the digital signal at the output depends upon the number of samples that are taken.Inside this STC microcontroller there is a decent ADC which fulfill the requirements of high sampling rate. Using program control, the function of running and stopping ADC sampling and analysing completed sampling data in buffer, displaying and clearing waveform all can be realized.&lt;br /&gt;
&lt;br /&gt;
Furthermore, A 3.7V Li-ion battery supply power to the entire circuit, but we want the operating voltage of microcontroller and SSD display is maintained at 5.0V.To increase the voltage, we connect the Li-ion battery and a booster in series to get a higher output voltage. The physical circuit of booster is shown in Figure.2.&lt;br /&gt;
 &lt;br /&gt;
This digital oscilloscope was able to convert the analog input voltage to a digital voltage, write the digital data to the memory, read the digital data from the memory, convert the digital data to analog data, and display the analog data. The signal was returned via a STC microcontroller and displayed on the SSD OLED.&lt;br /&gt;
&lt;br /&gt;
[[File:Circuit block diagram.png|thumb|center|350px|Fig.1 Circuit block diagram]]&lt;br /&gt;
[[File:Adjustable Lithium Battery Charging Discharge Integrated Module.jpeg|thumb|center|250px|Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module]]&lt;br /&gt;
&lt;br /&gt;
===Hardware circuit module===&lt;br /&gt;
The Hardware circuit is mainly divided into following parts and respective function are listed as follows：&lt;br /&gt;
&lt;br /&gt;
[[File:Schematic diagram.jpeg|thumb|center|650px|Fig.3 Schematic diagram]]&lt;br /&gt;
&lt;br /&gt;
a. Microcontroller: &lt;br /&gt;
&lt;br /&gt;
b. Booster: Bat-Port input , Bat+port can output 5.0V to charger 3.7V Li-ion battery. The V+Port can output an adjustable voltage&lt;br /&gt;
&lt;br /&gt;
c. Encoder(EC11): These device can generate electrical signal based on the movement of encoder, and we connect its terminal to serial port(P32,P33,P34)of microcontroller. With program control, microcontroller will receive and analyse signal sent from encoder, then we can achieve some basic operation of oscilloscope. &lt;br /&gt;
All operations are completed by the EC11 Encoder. The input include single click, double click, long press, rotate and rotate while pressing.The details are below:&lt;br /&gt;
*Single Click Encoder: Run/Stop sampling&lt;br /&gt;
*Double Click Encoder: Enter Wave Scroll Mode/Parameter Mode&lt;br /&gt;
*Long Press Encoder: Enter Settings Interface&lt;br /&gt;
*Rotate Encoder: Adjust parameters/Scroll waveform horizontally (only available when sampling stopped)&lt;br /&gt;
*Rotate Encoder While Pressing: Switch between options/Scroll waveform vertically (only available when sampling stopped)&lt;br /&gt;
*Switch Auto and Manual Range: Rotate Encoder clockwise continuous to enter auto range. Rotate Encoder anticlockwise to enter manual range.&lt;br /&gt;
&lt;br /&gt;
d. Bypass capacitors(an electrolytic capacitor 47uF &amp;amp; a ceramic capacitor 10nF):These two paralleling capacitors is at the power pin of microcontroller unit. The propose of this part is to keep the input voltage more stable and filter out the voltage spikes. So it can protect the microcontroller unit when the power on. They can also filter out the low and high frequency noise respectively.&lt;br /&gt;
 &lt;br /&gt;
e. Terminal(2 pin): It is an input of digital oscilloscope.&lt;br /&gt;
&lt;br /&gt;
f. Signal light(indicator): Generally, the indicator on means the sampling is running. The more important use is in Single and Normal Trigger Mode, before get into the trigger stage, pre-sampling is required. The indicator will not on during pre-sampling stage. We should not input signal until the indicator comes on. The longer time scale selected, the longer waiting time of pre-sampling.&lt;br /&gt;
&lt;br /&gt;
g. SSD display: &lt;br /&gt;
&lt;br /&gt;
h.&lt;br /&gt;
&lt;br /&gt;
i. Voltage divider circuit(a 1W 11k resistor &amp;amp; a 1/4w 2.2k resistor): which serve to convert an input voltage signal ranging from 0V to +30V to a scaled signal ranging from 0 to +5V.This is done to protect the ADC which requires a unipolar voltage input with a maximum of +5V volts.&lt;br /&gt;
&lt;br /&gt;
===Software program module===&lt;br /&gt;
MAIN.C&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The rest of the program is more or less cosmetics, a grid of horizontal and vertical lines is displayed, the current values for sensitivity and timebase. The zero volt line is shown brighter that all others and it moves with the offset. A small line is shown where the current trigger level is. What at the moment is active on the rotary encoder, timebase, offset or trigger level, is shown in yellow.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
===Step 1:Preparation ===&lt;br /&gt;
In the project, we will make a simple oscilloscope. STC8A8K64S4A12 chip has fast calculation speed, comes with ADC module and has large RAM space for sampling and OLED screen cache. In addition, AGND, AVREF, AVCC pins can improve the accuracy of sampling. So, STC8A8K64S4A12 chip was decided to be our important microcontroller module. The design idea of the circuit diagram has been clarified in previous. &lt;br /&gt;
&lt;br /&gt;
Material List:&lt;br /&gt;
* MCU: STC8A8K64S4A12(core component)&lt;br /&gt;
* Display: SSD OLED with 7-Pin SPI Interface  &lt;br /&gt;
* Resistor:1W 11k&amp;amp;1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k&lt;br /&gt;
* Capacitor:47uF, 0.01uF(for wave filtering)&lt;br /&gt;
* EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED&lt;br /&gt;
* IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)&lt;br /&gt;
* 3.7V Lithium-ion Battery(power source) &lt;br /&gt;
* 5V Booster Module(power module with Li-ion charging management and boost function)&lt;br /&gt;
* USB-TTL Downloader(for downloading program to MCU)&lt;br /&gt;
* Circuit Board&lt;br /&gt;
&lt;br /&gt;
===Step 2:PCB board design and layout===&lt;br /&gt;
PCB was deawn according to the schematic using Altium Designer. Package specifications were based on the package library provided by the software offical and other few drawn by ourselves.&lt;br /&gt;
[[File:PCB design (Double-side circuit).jpg|thumb|center|450px|Fig.4 PCB design (Double-side circuit)]]&lt;br /&gt;
&lt;br /&gt;
===Step 3:Circuit soldering===&lt;br /&gt;
The circuit was welted using a 350 degree soldering iron and solder according to the circuit schematic.&lt;br /&gt;
&lt;br /&gt;
[[File:Actual soldered circuit.jpg|thumb|center|350px|Fig.5 Actual soldered circuit]]&lt;br /&gt;
Each interface was tested for ohms and the pin contact was good and in line with the theoretical values. Therefore, the circuit was found to be well built.&lt;br /&gt;
&lt;br /&gt;
===Step 4:Programming and downloading the code to microcontroller ===&lt;br /&gt;
To program the microcontrollers made by ST Microelectronics you need a tool called STC-ISP(Figure.6).&lt;br /&gt;
[[File:stcisp.jpg|thumb|center|450px|Fig.6 Interface of STC-ISP for program downloading]] &lt;br /&gt;
&lt;br /&gt;
[[File:usbcode.jpg|thumb|center|450px|Fig.7 Usb serial port for communication]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Connect the TXD and RXD terminals of the MCU and complete the program download by connecting to the computer via USB. The code is written in C and converted to .hex and .bin files for writing to the chip. Once the program file and EEPROM file are configured, the program can be downloaded. For the STC we use, a cold boot is required to download the program using the boot sector.&lt;br /&gt;
&lt;br /&gt;
During the actual operation, unexpectedly, our program could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
After testing, the circuit is normal, the power supply is normal, and the cold start error is suspected. However, the problem persisted after shorting P1.0 and P1.1 to ground. After checking the manual again and grounding P3.2, the program still could not be downloaded.&lt;br /&gt;
&lt;br /&gt;
===Step 5:Test and measurement===&lt;br /&gt;
&lt;br /&gt;
== Discussion ==&lt;br /&gt;
In this experiment, although there were no problems with the experimental steps, problems arose during the writing downloading phase. The main reason for choosing this chip was its ADC function and online burning function. After checking, we found that many engineers had encountered many problems during the writing downloading process. &lt;br /&gt;
&lt;br /&gt;
The first situation is the failure of writing downloading through the USB to serial port. The reason for this is that for some chips, a dedicated chip USB to serial port is required. The second situation is that sometimes some chips in the same batch can be programmed online, while others cannot. It may be that there are minor package differences that cause problems with this writing downloading process.&lt;br /&gt;
&lt;br /&gt;
There are also problems with jumping when using the chip, and sometimes the light flickers. Using direct battery power did not improve the problem, so we also ruled out a DC-DC effect. We suspected that there might also be a problem with the chip itself. We also found that this jumping problem is related to the quality of each microcontroller.&lt;br /&gt;
&lt;br /&gt;
== Future improvement can be done  ==&lt;br /&gt;
* One of the biggest design problem of this oscilloscope is the inability to measure negative voltages. Since the oscilloscope measures voltages in the range 0 V to 27 V, a shift can be made using an isotropic adder. Choose suitable resistors and capacitors in the schematic and add the adder to input part. The calculation formula is as follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math display=&#039;block&#039;&amp;gt;&lt;br /&gt;
  \begin{align}&lt;br /&gt;
      V_{out} = \frac{V_{in}+5V}{2}*\frac{R_4+R_3}{R_4}.&lt;br /&gt;
  \end{align}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Amplification circuit for improvement.png|thumb|center|350px|Fig.8 Amplification circuit for improvement]]&lt;br /&gt;
&lt;br /&gt;
* Use a higher performance microcontroller, such as the STM32, and reduce the problems with writing downloading and jumping.&lt;br /&gt;
* Consider accelerating the external ADC to increase the speed and add a cache mechanism.&lt;br /&gt;
* Use a colour screen or two OLEDs, one for waveform display and one for parameter display.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Throughout the project, we learned a lot more than just how to build a breadboard digital oscilloscope. We learned how to design a breadboard digital oscilloscope. We did everything from reading and interpreting data sheets to trouble programming errors. By successfully completing these tasks and producing the functional breadboard digital oscilloscope we were able to demonstrate fundamental levels of understanding in basic electronic techniques, digital electronics, data acquisition, and data analysis.&lt;/div&gt;</summary>
		<author><name>Diandian</name></author>
	</entry>
</feed>