Transistor Gijutsu, October 2014, Special Features Chapter 9, Software of the Function Generator トランジスタ技術2014年10月号 特集第9章のソフトウェア わがまま波形発生器のソフトウェア

Dependencies:   USBDevice mbed

Information

tg_201410s8_AD7714 トランジスタ技術 2014年 10月号 第9章のソフトウェア

Program for Section 9 in October. 2014 issue of the Transistor Gijutsu
(Japanese electronics magazine)

概要

このプログラムは、ソフトウエアDDSにより、任意の波形を出力(2ch)します。 特徴は次のとおりです。

  • PWM出力をDAコンバータとして利用します。
  • 周波数や波形、バースト条件などを個別に設定できる独立した出力を2チャネル持っています。
  • 周波数分解能0.023mHz
  • 周波数範囲0.023mHz~10kHz
  • 各チャネルにそれぞれ、波形の先頭で出力されるトリガ出力があります。
  • 出力波形を関数で定義できます。
  • 休止波数、出力波数、を設定することでバースト波形が出力できます。

ファイル

このソフトウエアは、次のファイルから構成されています。

  • DDS.cpp - DDSによる波形発生
  • main.cpp - main()関数

詳細については、10月号の記事および上記ファイル中のコメントを参照してください。

Committer:
Dance
Date:
Fri Aug 29 08:33:17 2014 +0000
Revision:
0:f1ecca559ec3
Transistor Gijutsu, October 2014, Special Features Chapter 9; ????????2014?10??????9????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dance 0:f1ecca559ec3 1 #include "mbed.h"
Dance 0:f1ecca559ec3 2 #include "USBSerial.h"
Dance 0:f1ecca559ec3 3 #include "DDS.h"
Dance 0:f1ecca559ec3 4
Dance 0:f1ecca559ec3 5
Dance 0:f1ecca559ec3 6 USBSerial pc;
Dance 0:f1ecca559ec3 7
Dance 0:f1ecca559ec3 8
Dance 0:f1ecca559ec3 9 // sin()関数で合成された方形波
Dance 0:f1ecca559ec3 10 float square13(float x)
Dance 0:f1ecca559ec3 11 {
Dance 0:f1ecca559ec3 12 return (4*(sin(x) + sin(3*x)/3. + sin(5*x)/5. + sin(7*x)/7. + sin(9*x)/9. +
Dance 0:f1ecca559ec3 13 sin(11*x)/11. + sin(13*x)/13.))/PI;
Dance 0:f1ecca559ec3 14 }
Dance 0:f1ecca559ec3 15
Dance 0:f1ecca559ec3 16 // 円の方程式から作られる半円波形
Dance 0:f1ecca559ec3 17 float circle(float x)
Dance 0:f1ecca559ec3 18 {
Dance 0:f1ecca559ec3 19 return sqrt(1 - (x - PI)*(x - PI)/PI/PI);
Dance 0:f1ecca559ec3 20 }
Dance 0:f1ecca559ec3 21
Dance 0:f1ecca559ec3 22 // 高調波を含んだsin()関数
Dance 0:f1ecca559ec3 23 float sin2(float x)
Dance 0:f1ecca559ec3 24 {
Dance 0:f1ecca559ec3 25 return (sin(x) + sin(5*x)/3)/1.3;
Dance 0:f1ecca559ec3 26 }
Dance 0:f1ecca559ec3 27
Dance 0:f1ecca559ec3 28 // float x を引数としてfloatを返す関数へのポインタの配列
Dance 0:f1ecca559ec3 29 float (*ftbl[])(float x) = {sin, triangle, square, circle, sin2};
Dance 0:f1ecca559ec3 30
Dance 0:f1ecca559ec3 31 // 簡単な操作説明
Dance 0:f1ecca559ec3 32 void help(void)
Dance 0:f1ecca559ec3 33 {
Dance 0:f1ecca559ec3 34 pc.printf("o1 freq phase level offset func\r\n");
Dance 0:f1ecca559ec3 35 pc.printf("b1 begin end length DcLevel\r\n");
Dance 0:f1ecca559ec3 36 pc.printf("o2 freq phase level offset func\r\n");
Dance 0:f1ecca559ec3 37 pc.printf("b2 begin end length DcLevel\r\n");
Dance 0:f1ecca559ec3 38 pc.printf("h ... help\r\n");
Dance 0:f1ecca559ec3 39 }
Dance 0:f1ecca559ec3 40
Dance 0:f1ecca559ec3 41 int main(){
Dance 0:f1ecca559ec3 42
Dance 0:f1ecca559ec3 43 // インスタンスの生成
Dance 0:f1ecca559ec3 44 DDS dds;
Dance 0:f1ecca559ec3 45 // 出力1の波形設定
Dance 0:f1ecca559ec3 46 dds.osc1(1000, 0, 0.5, 1, sin);
Dance 0:f1ecca559ec3 47 dds.burst1(2, 2, 2, 1);
Dance 0:f1ecca559ec3 48
Dance 0:f1ecca559ec3 49 dds.osc2(1000, 0, 0.5, 2, sin);
Dance 0:f1ecca559ec3 50 dds.burst2(1, 1, 2, 2);
Dance 0:f1ecca559ec3 51
Dance 0:f1ecca559ec3 52 dds.reset();
Dance 0:f1ecca559ec3 53 dds.start();
Dance 0:f1ecca559ec3 54
Dance 0:f1ecca559ec3 55 pc.printf("\r\n>");
Dance 0:f1ecca559ec3 56 while(1){
Dance 0:f1ecca559ec3 57 switch(pc.getc()){
Dance 0:f1ecca559ec3 58 case 'h':
Dance 0:f1ecca559ec3 59 help();
Dance 0:f1ecca559ec3 60 break;
Dance 0:f1ecca559ec3 61 case 'o':
Dance 0:f1ecca559ec3 62 float a, b, c, o;
Dance 0:f1ecca559ec3 63 int n;
Dance 0:f1ecca559ec3 64 if(pc.getc() == '1'){
Dance 0:f1ecca559ec3 65 pc.printf(" osc1: ");
Dance 0:f1ecca559ec3 66 pc.scanf("%f %f %f %f %d", &a, &b, &c, &o, &n);
Dance 0:f1ecca559ec3 67 dds.osc1(a, b, c, o, ftbl[n]);
Dance 0:f1ecca559ec3 68 }else{
Dance 0:f1ecca559ec3 69 pc.printf(" osc2: ");
Dance 0:f1ecca559ec3 70 pc.scanf("%f %f %f %f %d", &a, &b, &c, &o, &n);
Dance 0:f1ecca559ec3 71 dds.osc2(a, b, c, o, ftbl[n]);
Dance 0:f1ecca559ec3 72 }
Dance 0:f1ecca559ec3 73 dds.reset();
Dance 0:f1ecca559ec3 74 break;
Dance 0:f1ecca559ec3 75 case 'b':
Dance 0:f1ecca559ec3 76 int bg, en, ln;
Dance 0:f1ecca559ec3 77 float dc;
Dance 0:f1ecca559ec3 78 if(pc.getc() == '1'){
Dance 0:f1ecca559ec3 79 pc.printf(" bust1: ");
Dance 0:f1ecca559ec3 80 pc.scanf("%d %d %d %f", &bg, &en, &ln, &dc);
Dance 0:f1ecca559ec3 81 dds.burst1(bg, en, ln, dc);
Dance 0:f1ecca559ec3 82 }else{
Dance 0:f1ecca559ec3 83 pc.printf(" bust2: ");
Dance 0:f1ecca559ec3 84 pc.scanf("%d %d %d %f", &bg, &en, &ln, &dc);
Dance 0:f1ecca559ec3 85 dds.burst2(bg, en, ln, dc);
Dance 0:f1ecca559ec3 86 }
Dance 0:f1ecca559ec3 87 dds.reset();
Dance 0:f1ecca559ec3 88 break;
Dance 0:f1ecca559ec3 89 default:
Dance 0:f1ecca559ec3 90 continue;
Dance 0:f1ecca559ec3 91 }
Dance 0:f1ecca559ec3 92 pc.printf("\r\n>");
Dance 0:f1ecca559ec3 93 }
Dance 0:f1ecca559ec3 94 }
Dance 0:f1ecca559ec3 95