Transistor Gijutsu, October 2014, Special Features Chapter 9, Software of the Function Generator トランジスタ技術2014年10月号 特集第9章のソフトウェア わがまま波形発生器のソフトウェア
main.cpp
00001 #include "mbed.h" 00002 #include "USBSerial.h" 00003 #include "DDS.h" 00004 00005 00006 USBSerial pc; 00007 00008 00009 // sin()関数で合成された方形波 00010 float square13(float x) 00011 { 00012 return (4*(sin(x) + sin(3*x)/3. + sin(5*x)/5. + sin(7*x)/7. + sin(9*x)/9. + 00013 sin(11*x)/11. + sin(13*x)/13.))/PI; 00014 } 00015 00016 // 円の方程式から作られる半円波形 00017 float circle(float x) 00018 { 00019 return sqrt(1 - (x - PI)*(x - PI)/PI/PI); 00020 } 00021 00022 // 高調波を含んだsin()関数 00023 float sin2(float x) 00024 { 00025 return (sin(x) + sin(5*x)/3)/1.3; 00026 } 00027 00028 // float x を引数としてfloatを返す関数へのポインタの配列 00029 float (*ftbl[])(float x) = {sin, triangle, square, circle, sin2}; 00030 00031 // 簡単な操作説明 00032 void help(void) 00033 { 00034 pc.printf("o1 freq phase level offset func\r\n"); 00035 pc.printf("b1 begin end length DcLevel\r\n"); 00036 pc.printf("o2 freq phase level offset func\r\n"); 00037 pc.printf("b2 begin end length DcLevel\r\n"); 00038 pc.printf("h ... help\r\n"); 00039 } 00040 00041 int main(){ 00042 00043 // インスタンスの生成 00044 DDS dds; 00045 // 出力1の波形設定 00046 dds.osc1(1000, 0, 0.5, 1, sin); 00047 dds.burst1(2, 2, 2, 1); 00048 00049 dds.osc2(1000, 0, 0.5, 2, sin); 00050 dds.burst2(1, 1, 2, 2); 00051 00052 dds.reset(); 00053 dds.start(); 00054 00055 pc.printf("\r\n>"); 00056 while(1){ 00057 switch(pc.getc()){ 00058 case 'h': 00059 help(); 00060 break; 00061 case 'o': 00062 float a, b, c, o; 00063 int n; 00064 if(pc.getc() == '1'){ 00065 pc.printf(" osc1: "); 00066 pc.scanf("%f %f %f %f %d", &a, &b, &c, &o, &n); 00067 dds.osc1(a, b, c, o, ftbl[n]); 00068 }else{ 00069 pc.printf(" osc2: "); 00070 pc.scanf("%f %f %f %f %d", &a, &b, &c, &o, &n); 00071 dds.osc2(a, b, c, o, ftbl[n]); 00072 } 00073 dds.reset(); 00074 break; 00075 case 'b': 00076 int bg, en, ln; 00077 float dc; 00078 if(pc.getc() == '1'){ 00079 pc.printf(" bust1: "); 00080 pc.scanf("%d %d %d %f", &bg, &en, &ln, &dc); 00081 dds.burst1(bg, en, ln, dc); 00082 }else{ 00083 pc.printf(" bust2: "); 00084 pc.scanf("%d %d %d %f", &bg, &en, &ln, &dc); 00085 dds.burst2(bg, en, ln, dc); 00086 } 00087 dds.reset(); 00088 break; 00089 default: 00090 continue; 00091 } 00092 pc.printf("\r\n>"); 00093 } 00094 } 00095
Generated on Wed Jul 13 2022 01:52:22 by 1.7.2