A digital oscilloscope Based on MCU

From PC5214 wiki
Jump to navigation Jump to search

Introduction

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.

Methodology

Design idea

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.

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.

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.The STC microcontroller provide high-accuracy and high-speed ADC which fulfill the requirements of high sampling rate.Using program control, the function of ... can be realized.

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.

Fig.1 Circuit block diagram
Fig.2 Adjustable Lithium Battery Charging Discharge Integrated Module

Hardware circuit module

The Hardware circuit is mainly divided into following parts and respective function are listed as follows:

Fig.2 Schematic diagram

A. Decoupling capacitors(a electrolytic capacitor 47uF & a ceramic capacitor 10nF):These two 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.

B. Voltage divider circuit(a 1W 11k resistor & a 1/4w 2.2k resistor):

Software program module

void runWhenADCInterrupt() { ADCInterrupt = 0;

   P_Ready = 0;
/* ADC Sampling Running */
   if (ADCRunning)
      {EX0 = 0;
       if (WaveUpdate)
       {
           WaveUpdate = 0;
           ClearDisplay = 1;                  
           /* Clear waveform in buffer*/
           if (ClearWave)
           {
               ClearWave = 0;
               memset(ADCbuf, 0x00, SAMPLE_NUM * 2);
               WaveFreq = 0;
               TriFail = 0;
               VMax = 0;
               VMin = 0;
               PlotChart();
           }
     /* Display waveform in buffer*/
           else
           {
               AnalyseData();
               PlotChart();
               PlotWave();
           }
       }
       else
       {
           ClearDisplay = 0;
           PlotChart();
       }
       OLED_Display();
        /* Not to enable external interrupt 0(Encoder Rotation) when both of ADCRunning and WaveScroll set. */
       if (!WaveScroll)
       {
           IE0 = 0;
           EX0 = 1;
       }
   }
    /* ADC Sampling Stopped */
   else
   {
       while (!ADCRunning && !InSettings)
       {
           if (DisplayUpdate)
           {
               EX0 = 0;
               DisplayUpdate = 0;
               if (WaveUpdate)
               {
                   WaveUpdate = 0;
                    /* Analyse completed sampling data in buffer */
                   AnalyseData();
                   ClearDisplay = 1;
                    /* Clear display and draw waveform */
                   if (ScaleH == ScaleH_tmp)
                   {
                        /* Since the sampling points limitation, scaling waveform along horizontal is not support.
                           Show waveform only when time scale is same as that when sampling completed */
                       PlotChart();
                       PlotWave();
                   }
                    /* Clear display and no waveform */
                   else
                   {
                       WaveFreq = 0; //Clear WaveFreq. When the interface is drawn, the screen will display xxHZ
                       PlotChart();
                   }
               }
                /* Update parameters on display only, keep waveform */
               else
               {
                   ClearDisplay = 0;
                   PlotChart();
               }
               OLED_Display();
               IE0 = 0;
               EX0 = 1;
           }
       }
   }

}

Experimental setup

Step 1:Preparation

Material List:

  • MCU: STC8A8K64S4A12(core component)
  • Display: SSD OLED with 7-Pin SPI Interface
  • Resistor:1W 11k&1/4W 2.2k(for voltage division), 1/4W 11k(for current limiting) ,5k
  • Capacitor:47uF, 0.01uF(for wave filtering)
  • EC11 Encoder(for controlling of oscilloscope),Toggle Switch(for power switch),2-Pin Terminal(for input of oscilloscope),LED
  • IC Socket 40-Pin,Row Pin(for installation of OLED display and programming the MCU)
  • 3.7V Li-ion Battery(power source)
  • 5V Booster Module(power module with Li-ion charging management and boost function)
  • USB-TTL Downloader(for downloading program to MCU)
  • Circuit Board

Step 2:PCB board design and layout

Step 3:PCB board wetting

Step 4:Programming and downloading the code to microcontroller

Step 5:Test and measurement