MSP430 MCU Simulation Example 19-D/A Conversion Sine Wave Generator Based on Proteus
[Copy link]
This content is originally created by EEWORLD forum user tiankai001. If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source 1. Task requirementsUse MSP30F247 microcontroller as a controller to achieve sinusoidal wave signal output, with a maximum value of positive and negative 5V and a frequency of 50Hz.. 2. Hardware circuitThe hardware circuit is shown in the figure below. The output maximum value is positive and negative 5V sinusoidal signal. The operational amplifier circuit adopts a two-stage design. The second stage is the addition circuit, which can realize bipolar output. 3. Programming//main.c #include "msp430f247.h" #include "stdlib.h" #include "string.h" /************************************************Software delay, clocked at 1M**********************/ #define CPU_F1 ((double)1000000) #define delay_us1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000000.0)) #define delay_ms1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000.0)) /****************************************************************************/ /******************************************Software delay, main frequency 1M************************/ #define CPU_F8 ((double)8000000) #define delay_us8M(x) __delay_cycles((long)(CPU_F8*(double)x/1000000.0)) #define delay_ms8M(x) __delay_cycles((long)(CPU_F8*(double)x/1000.0))/****************************************************************************///128 point output sine wave sample value char data_Sin[128]={128,134,140,147,153,159,165,171,177,182,188,193,199,204,209,213,218,222,226,230,234,237,240,243,245,248,250,251,253,254,254,2 55, 255,255,254,254,253,251,250,248,245,243,240,237,234,230,226,222,[/a lign] 218,213,209,204,199,193,188,182,177,171,165,159,153,147,140,134, [ align=left]128,122,116,109,103,97,91,85,79,74,68,63,57,52,47,43,38,34,30,26, [align =left]22,19,16,13,11,8,6,5,3,2,2,1,1,1,2,2,3,5,6,8,11,13,16,19,22,26,30,
[align=lef t]34,38,43,47,52,57,63,68,74,79,85,91,97,103,109,116,122};/********************************************************Function name: Main functionFunction function:D/A converter application 2: sine wave generator Input parameters: None Output parameters: None Description: Author: Lao Ma Shi Tu Microcontroller Date: January 10, 2018 ****************************************************** / main() { unsigned int i; WDTCTL = WDTPW + WDTHOLD;//Turn off watchdogP4DIR=0xff; while(1) { for(i=0;i<128;i++) { P4OUT=data_Sin; delay_us1M(156); } } } IV. Program DescriptionThe general method for a single-chip microcomputer to generate a sine wave signal is: first establish a sine wave data table, and the single-chip microcomputer obtains a sine wave signal through the D/A output in a table lookup manner. The D/A converter used in the example is 8-bit, so the sine wave data table has a maximum of 256 values. Generally, the single-chip microcomputer outputs 64 points or 128 points. The sine wave waveform obtained after the D/A circuit is relatively perfect. . V. Simulation results and analysis After drawing the circuit diagram in proteus, double-click the single-chip microcomputer to load the executable file into the single-chip microcomputer, click Run, and observe the waveform of the virtual oscilloscope. As shown in the figure below.
|