Introduction: DIY Function Generator With STC MCU Easily

About: Awesome Electronics Tutorials, Projects and How To´s

This is a Function Generator made with STC MCU. Need only several components and the circuit is simple.

Specification

  • Output: Single Channel
  • Square Waveform Frequency: 1Hz~2MHz
  • Sine Waveform Frequency: 1Hz~10kHz
  • Amplitude: VCC, about 5V
  • Load ability: Not available
  • MCU: STC15W4K32S4 @24MHz
  • Display: LCD1602
  • Controller: EC11 Encoder


Step 1: Watch the Video!

In this video, I will show you how to DIY this Function Generator step by step.

Step 2: Prepare Your Parts!

Parts List

Step 3: Scheme and Circuit!

Please refer to the circuit and the step in video, you could arrange the components on circuit board easily.

Step 4: Download the Code!

Download the package below. There are source code and compiled hex file.

If you do not want to read the codes, just burn the .hex file into the MCU. Use a USB to TTL downloader and STC-ISP software to download the code to MCU. Connect TXD, RXD and GND.

Download STC-ISP software here: http://www.stcmicro.com/rjxz.html

If the interface of STC-ISP is Chinese, you could click upper left icon to change the language to English. For the detail configuration of STC-ISP please refer to the video in Step 1.

The codes were written in C. Use Keil software to edit and compile it.

Step 5: Success!

You could use this DIY Function Generator to output Square waveform or Sine waveform signal.

Interface:

  • Bottom left shows the type of waveform(Square/Sine) and output status(ON/OFF)
  • F: Frequency
  • D: Duty of Square Waveform
  • CD: Clock Division Coefficient (For information only)
  • P: PWM frequency for generating Sine Waveform (For information only)
  • Pt: Number of points for generating Sine Waveform (For information only)

Operations:

  • Single Click Encoder: Switch Frequency and Duty in Square Waveform Interface
  • Double Click Encoder: Start/Stop Signal Output
  • Long Press Encoder: Switch between Square Waveform/Sine Waveform/Voltage Information
  • Rotate Encoder: Adjust Parameters

Step 6: Tips

The output signal do not have load ability. If you want to drive other component, please be advised that using an operational amplifier to enhance the load ability.

Step 7: Future Plan

I plan to make another Function Generator with STM32.

Expecting it

  • Could generate Triangle and Saw waveform additionally.
  • The frequency of Sine waveform could be higher than 10kHz.

If you have advices or requirements about this project, please kindly tell me.

Hope you like it.

Feel free to check out my YouTube Channel: https://www.youtube.com/c/CreativeLau