OpenVINOTM,给你看得见的未来!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » 基于AD9833制作的信号发生器

共5条 1/1 1 跳转至

基于AD9833制作的信号发生器

工程师
2021-01-10 21:35:41    评分

本信号发生器采用STM32F103C8T6作为主控,AD9833作为DDS信号发生器,代码可直接烧录!本信号发生器实现了方波、正弦波、三角波的输出与频率、幅度按键调控,另外实现了STM32定时器产生一路方波,占空比可调.

1610285699247052.png

PCB底板如下:

image.png

源码如下:

#include "stm32f10x.h"
#include "led.h"
#include "ad9833.h"
#include "systemconfig.h"
#include "key.h"
#include "oled.h"
#include "bsp_i2c_gpio.h"
#include "delay.h"
#include "usart.h"
#include "timer.h"
void Delay(u32 count)
{
   u32 i=0;
   for(;i<count;i++);
}
int main(void)
{        
         u8 i;
        uint16_t pwm = 400;
        LED_Init();        
        delay_init();
        OLED_Init();                                         /* OLED初始化 */
        uart_init(115200);
        SystemConfiguration();                    //系统初始化
        TIM3_PWM_Init(899,0);         //不分频。PWM频率=72000000/900=80Khz
        AD9833_Init_GPIO(); //AD9833 GPIO 初始化
//AD9833_WaveSeting(8000000.5,0,TRI_WAVE,0 );//1.0005KHz,频率寄存器0,三角波输出 ,初相位0
/*AD9833_WaveSeting(5000,0,SQU_WAVE,90);        //5KHz,                频率寄存器0,方波输出         ,初相位90 */
/*AD9833_WaveSeting(100000,0,SIN_WAVE,0 );//100KHz,        频率寄存器0,正弦波输出 ,初相位0 */
        AD9833_WaveSeting(10000,0,SIN_WAVE,0 );
        AD9833_AmpSet(100); //设置幅值,幅值最大 255
        
        u16 f=1000;
        u16 l=100;
        u8 flag;u8 flag1;
        u8 t = '0';
        u16 b;
        u16 m=0;
        u16 a=0;
        while(1)
        {
                TIM_SetCompare2(TIM3,pwm);
                OLED_Clear();
                OLED_DisplayUpdate();
                t = KEY_Scan();        //得到键值
                switch(t)                //波形检测
                {
                        case '1':t='0';SystemConfiguration();                AD9833_WaveSeting(f,0,TRI_WAVE,0 );break;//说明PB4接收到低电平,第一行第一列对应第一个按键
                        case '5':t='0';SystemConfiguration();                AD9833_WaveSeting(f,0,SQU_WAVE,90);break; 
                        case '9':t='0';SystemConfiguration();                AD9833_WaveSeting(f,0,SIN_WAVE,0 );break;
                        case '2':t='0';f--;SystemConfiguration();                AD9833_WaveSeting(f,0,SIN_WAVE,0 );break;
                        case '3':t='0';f=f-10;SystemConfiguration();                AD9833_WaveSeting(f,0,SIN_WAVE,0 );break;
                        case '4':t='0';f=f-100;SystemConfiguration();                AD9833_WaveSeting(f,0,SQU_WAVE,0 );break;
                        case '6':t='0';f++;SystemConfiguration();                AD9833_WaveSeting(f,0,SIN_WAVE,0 );break;
                        case '7':t='0';f=f+10;SystemConfiguration();                AD9833_WaveSeting(f,0,SIN_WAVE,0 );break;
                        case '8':t='0';f=f+100;SystemConfiguration();                AD9833_WaveSeting(f,0,SIN_WAVE,0 );break;
                        case 'f':t='0';pwm=pwm-10;        break;        
                        case 'g':t='0';pwm=pwm+10;        break;
                        default:break;                                                
                }
        }
}
//                switch(t)                
//                {
//                        case 'g':
//                        {
//                                a=0;
//                                b=0;
//                                delay_ms(1000);           //延时
//                                flag = KEY_Scan();
//                                while(flag!='d')
//                                {
//                                        if(flag!='0'&&flag!=flag1)
//                                        {
//                                        flag=flag1;
//                                        switch(flag)
//                                        {
//                                                m++;
//                                                case '4': b=1;break;        
//                                                case '3': b=2;break;        
//                                                case '2': b=3;break;        
//                                                case '8': b=4;break;        
//                                                case '7': b=5;break;        
//                                                case '6': b=6;break;        
//                                                case 'c': b=7;break;        
//                                                case 'b': b=8;break;        
//                                                case 'a': b=9;break;        
//                                                case 'e': b=0;break;        
//                                                default:break;                                                
//                                        }
//                                        }
//                                        for(u16 n=0;n<m;n++)
//                                        {
//                                                a=a+10*b;
//                                        }                                
//                                flag1 = KEY_Scan();
//                                }
//                                f=a;                        
//                        }                
//                        case 'f':
//                        {        
//                                a=0;
//                                b=0;
//                                delay_ms(1000);           //延时
//                                flag = KEY_Scan();
//                                while(flag!='d')
//                                {
//                                        if(flag!='0')
//                                        {
//                                        switch(flag)
//                                        {
//                                                m++;
//                                                case '4': b=1;break;        
//                                                case '3': b=2;break;        
//                                                case '2': b=3;break;        
//                                                case '8': b=4;break;        
//                                                case '7': b=5;break;        
//                                                case '6': b=6;break;        
//                                                case 'c': b=7;break;        
//                                                case 'b': b=8;break;        
//                                                case 'a': b=9;break;        
//                                                case 'e': b=0;break;        
//                                                default:break;                                                
//                                        }
//                                        }
//                                        for(u16 n=0;n<m;n++)
//                                        {
//                                                a=a+10*b;
//                                        }                                
//                                flag = KEY_Scan();
//                                }
//                                l=a;                        
//                        }        
//                        default:break;        
//                }
                        //显示2个数字
//x,y :起点坐标         
//len :数字的位数
//size:字体大小
//mode:模式        0,填充模式;1,叠加模式
//num:数值(0~4294967295);                           
//        OLED_ShowNum(48,3,f,10,6);
//        OLED_ShowNum(0,4,l,10,6);
//        }



关键词: AD9833     信号发生器     STM32F103C8T    

工程师
2021-01-10 21:54:06    评分
2楼

软硬件资料挺全的!cool!


工程师
2021-01-10 21:57:09    评分
3楼

这个DIY不错,能产生方波、正弦波、三角波的输出与频率、幅度可调!


工程师
2021-01-10 22:00:55    评分
4楼

正好可以参考一下源码! tks!


高工
2021-01-16 23:59:45    评分
5楼

学到了


共5条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]