Introduction: DIY Function Generator With STC MCU Easily
This is a Function Generator made with STC MCU. Need only several components and the circuit is simple.
- 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!
- MCU: STC15W4K32S4 x 1 Get it from AliExpress
- Display: LCD1602 x 1 Get it from AliExpress
- Row Pin Female: Get it from AliExpress
- 16-Pin x 1
- 2-Pin x 1
- 10kΩ x 1
- 200kΩ x 1
- 500Ω x 1
- 220nF x 1 Get it from AliExpress
- 10nF x 1
- 47uF x 1
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
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.
- 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)
- 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.
- 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