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 #ifndef DDS_h
Dance 0:f1ecca559ec3 2 #define DDS_h
Dance 0:f1ecca559ec3 3
Dance 0:f1ecca559ec3 4 #define PACCLEN (4294967296.0) // 位相積算レジスタの最大値 2^23
Dance 0:f1ecca559ec3 5 #define PI (3.1415926535897932385) // 円周率
Dance 0:f1ecca559ec3 6
Dance 0:f1ecca559ec3 7 // 出力電圧の設定
Dance 0:f1ecca559ec3 8 #define VCC (3.27) // 電源電圧、実測
Dance 0:f1ecca559ec3 9 #define BUFMAG (2.0) // 出力バッファの増幅率
Dance 0:f1ecca559ec3 10 #define WFMAG (1.0/(VCC*BUFMAG)) // PWM値算出のための係数
Dance 0:f1ecca559ec3 11
Dance 0:f1ecca559ec3 12 class DDS {
Dance 0:f1ecca559ec3 13 private:
Dance 0:f1ecca559ec3 14 static const int MAINCLK = 48000000; // CPUのシステムクロック値
Dance 0:f1ecca559ec3 15 static const int DDSCLK = 100000; // DDSの基準クロック値
Dance 0:f1ecca559ec3 16 static const int TBLSIZEBITS = 10; // 波形配列の長さを決めるビット数
Dance 0:f1ecca559ec3 17 static const int WFVGND = 0; // バースト波形の無信号状態の出力値
Dance 0:f1ecca559ec3 18 // 以下は上の値から設定されるので変更不可
Dance 0:f1ecca559ec3 19 static const int TBLSIZE = 1 << TBLSIZEBITS;// 波形配列の長さ
Dance 0:f1ecca559ec3 20 static const int WFRES = 32 - TBLSIZEBITS; // 位相積算レジスタを波形配列の引数に変換するためのビットシフト値
Dance 0:f1ecca559ec3 21 static const int WFVSPN = MAINCLK / DDSCLK; // PWMの最大値
Dance 0:f1ecca559ec3 22
Dance 0:f1ecca559ec3 23 static int16_t waveForm1[];
Dance 0:f1ecca559ec3 24 static int16_t waveForm2[];
Dance 0:f1ecca559ec3 25
Dance 0:f1ecca559ec3 26 static unsigned int phaseAcc1;
Dance 0:f1ecca559ec3 27 static unsigned int phaseInc1;
Dance 0:f1ecca559ec3 28 static unsigned int phaseShift1;
Dance 0:f1ecca559ec3 29 static int bstBgn1;
Dance 0:f1ecca559ec3 30 static int bstEnd1;
Dance 0:f1ecca559ec3 31 static int bstLen1;
Dance 0:f1ecca559ec3 32 static int bstDcL1;
Dance 0:f1ecca559ec3 33 static int wc1;
Dance 0:f1ecca559ec3 34 static int lp1;
Dance 0:f1ecca559ec3 35
Dance 0:f1ecca559ec3 36 static unsigned int phaseAcc2;
Dance 0:f1ecca559ec3 37 static unsigned int phaseInc2;
Dance 0:f1ecca559ec3 38 static unsigned int phaseShift2;
Dance 0:f1ecca559ec3 39 static int bstBgn2;
Dance 0:f1ecca559ec3 40 static int bstEnd2;
Dance 0:f1ecca559ec3 41 static int bstLen2;
Dance 0:f1ecca559ec3 42 static int bstDcL2;
Dance 0:f1ecca559ec3 43 static int wc2;
Dance 0:f1ecca559ec3 44 static int lp2;
Dance 0:f1ecca559ec3 45
Dance 0:f1ecca559ec3 46 void fillTable(int16_t wftbl[], float level, float ofst, float (*waveform)(float x));
Dance 0:f1ecca559ec3 47
Dance 0:f1ecca559ec3 48 public:
Dance 0:f1ecca559ec3 49 static int trigger1;
Dance 0:f1ecca559ec3 50 static int trigger2;
Dance 0:f1ecca559ec3 51
Dance 0:f1ecca559ec3 52 DDS();
Dance 0:f1ecca559ec3 53 static void start(void);
Dance 0:f1ecca559ec3 54 static void stop(void);
Dance 0:f1ecca559ec3 55 static void reset(void);
Dance 0:f1ecca559ec3 56 int getPhase(void){
Dance 0:f1ecca559ec3 57 return phaseAcc1;
Dance 0:f1ecca559ec3 58 };
Dance 0:f1ecca559ec3 59 static inline int getNextPw1(void);
Dance 0:f1ecca559ec3 60 static inline int getNextPw2(void);
Dance 0:f1ecca559ec3 61 void osc1(float freq, float phase, float level, float ofst, float (*waveform)(float x));
Dance 0:f1ecca559ec3 62 void osc1(float freq, float phase);
Dance 0:f1ecca559ec3 63 void osc2(float freq, float phase, float level, float ofst, float (*waveform)(float x));
Dance 0:f1ecca559ec3 64 void osc2(float freq, float phase);
Dance 0:f1ecca559ec3 65 void burst1(int begin, int end, int length, float dcLevel);
Dance 0:f1ecca559ec3 66 void burst2(int begin, int end, int length, float dcLevel);
Dance 0:f1ecca559ec3 67 };
Dance 0:f1ecca559ec3 68
Dance 0:f1ecca559ec3 69 float triangle(float x);
Dance 0:f1ecca559ec3 70 float square(float x);
Dance 0:f1ecca559ec3 71
Dance 0:f1ecca559ec3 72
Dance 0:f1ecca559ec3 73
Dance 0:f1ecca559ec3 74 #endif