[ Main Page ]

Arduino based Function Generator

Arduino based Function Generator

聴覚実験用にトーンバーストを出力する機器が必要になり、予算がなかったため急遽開発したものであるが、その後、 L6470(ステッピングモーターコントローラ)の制御やSDカードの再生機能も追加した。DACには、比較的入手容易なMicrochipのSPI DAC (MCP4922)を 使用し、後段には多段のLCフィルタをアンチエイリアシングフィルタとして配置し、出力を可変できるようにPGA2311も載せた。 アナログ電源はDCDCコンバータを使用して、USBのみの給電で基本まかなえるようにした。

概要

Arduino
水晶発振子は20MHzに変更。詳細はoptiboot@20MHzを参照。
DAC
Microchip MCP4922
PGA
TI PGA2311
コマンド
シリアルポートからコマンドを入力。コマンドプロセッサでは、13文字までしか受け付けないようにしてある。 それ以上入力すると始めから入力し直しになる。TeraTerm等を使うと良い。ProcessingでのGUIも製作した。
Sampling Rate
100kHzまたは125kHz。
SDカード再生
モノラル、最高でFs=20kHz。事前に再生速度に合わせたレートでの16bit Little Endianのバイナリに変換しておく必要がある。
トリガ
入力端子はダイオードによる簡易保護のみで直結のためノイズや過電圧には注意が必要。

Download

KiCadで製作した基板、Arduinoプログラム本体、ProcessingによるGUIがある。FatFsは、ソフトウエアモードでのSPIピン指定のため、 オリジナルのバージョンでは動作せず、置き換える必要があるので注意。

GUI

Arduino based Function Generator

ABR、VsEP用のGUIがある。SELECT COM PORTでポートを選び、リレーが鳴ることでGUIと接続されたことが確認出来るようにしてある。 古いマシンでWindowsXPを使う場合は、SP3でJava 7を入れた状態でprocessing-2.1.1でしか動作しないので注意する。

バージョン

SD カード再生機能やモータドライバコントローラを持つファームウエア(WDOSC 60p1 以降)と、 ABR 波形生成機能のみの初期ファームウエア(WDOSC 22p1)がある。DAC のトリガはいずれもハードウエア機能によるが、 試作機と基板で端子が異なるため、ファームウエアのバージョンにより、ショートするピンの位置が異なる。 試作機に関しては、プログラマブルアッテネータ(PGA2311)の SPI端子及び L/R が異なるため、 別のバージョン (WDOSC 23p0LB) を用意した。半固定抵抗で、LPF 以降のゲインは4Vpp(± 10%;4kHz) になるように調整すると良い。

ArduFgx@SF.NET
最新バージョンのアーカイブはしていないので、gitからどうぞ。

使用例

発振モードでは、大きく分けて連続出力(発振)モードと、内部トリガ間欠出力モード、外部トリガ間欠出力モードがある。 始めの状態では、連続出力モードで、stで開始、tpで停止である。トリガモードでも、stで開始させないとトリガされない。 コマンドパラメータは=数字で先に引数を入力してからコマンドを入れる。

リセット

$ reset
. reset

<< Programmable Triggered Function Generator >>
Version: 60p1 Build: Aug 12 2017, 20:26:45
setup(): Initializing...

$
    

60dBアッテネータのスイッチのon/off

<< Programmable Triggered Function Generator >>
Version: 60p1 Build: Aug 12 2017, 20:26:45
setup(): Initializing...

$ mo
. mo
*** -60dB att -> ON.  ***
$ mf
. mf
*** -60dB att -> OFF. ***
$
    

連続出力モード 4kHz

<< Programmable Triggered Function Generator >>
Version: 60p1 Build: Aug 12 2017, 20:26:45
setup(): Initializing...

$ status
. status
 [ Current Status ]
 Trigger Mode     : Continuous
 Wave Type        : Sine Wave
 Polarity         : Single Mode
 Time Period      : 10us
 Sampling Rate    : 100kHz
 Tone Frequency   : 1kHz
 Flat duration    : 10ms
 Internal Trigger : 100ms
 PGA Gain [dB]    : 0, 0
$ =4
. =4
Parameter = 4
$ freq
. freq
Frequency = 4kHz (@Fs=100kHz), Updating table ... [Flat][Rise][Fall] done.
 Sampling Rate    : 100kHz
 Tone Frequency   : 4kHz
$ status
. status
 [ Current Status ]
 Trigger Mode     : Continuous
 Wave Type        : Sine Wave
 Polarity         : Single Mode
 Time Period      : 10us
 Sampling Rate    : 100kHz
 Tone Frequency   : 4kHz
 Flat duration    : 10ms
 Internal Trigger : 100ms
 PGA Gain [dB]    : 0, 0
$ st
. st
Trigger : Started.
$
    

外部トリガ間欠出力モード 8kHz rise/fall 1ms flat 3ms

聴覚実験、ABRのために出力毎に位相を反転させるモード。Fs=100kHz。usでサンプリングレートを指定するが、Hzでなくてサンプル毎の間隔[us]*2で指定。 サンプリングレートは他のパラメータより先に指定しないと、テーブルの波形が更新されないので注意。

alt
trigext
=20
us
=8
freq
=3
fl
start
    

外部トリガ間欠出力モード トリガ毎反転 31.25kHz rise/fall 1ms flat 2.4ms

Fs=125kHz。

alt
trigext
=16
us
=25
freq
=3
fl
start
    

内部トリガ間欠出力モード

内部トリガはms単位で指定。

<< Programmable Triggered Function Generator >>
Version: 60p1 Build: Aug 12 2017, 20:26:45
setup(): Initializing...

$ =1000
. =1000
Parameter = 1000
$ trig
. trig
Internal Trigger = 1000ms
$ tint
. tint
*** Trigger Mode -> Internal. ***
$ ss
. ss
 [ Current Status ]
 Trigger Mode     : Internal Trigger
 Wave Type        : Sine Wave
 Polarity         : Single Mode
 Time Period      : 10us
 Sampling Rate    : 100kHz
 Tone Frequency   : 1kHz
 Flat duration    : 10ms
 Internal Trigger : 1000ms
 PGA Gain [dB]    : 0, 0
$ st
. st
Trigger : Started.
$
    

PGA2311のゲイン変更

<< Programmable Triggered Function Generator >>
Version: 60p1 Build: Aug 12 2017, 20:26:45
setup(): Initializing...

$ ss
. ss
 [ Current Status ]
 Trigger Mode     : Continuous
 Wave Type        : Sine Wave
 Polarity         : Single Mode
 Time Period      : 10us
 Sampling Rate    : 100kHz
 Tone Frequency   : 1kHz
 Flat duration    : 10ms
 Internal Trigger : 100ms
 PGA Gain [dB]    : 0, 0
$ =-10
. =-10
Parameter = -10
$ g1
. g1
 PGA Raw Value    : 172, 192
 PGA Gain [dB]    : -10, 0
$ g2
. g2
 PGA Raw Value    : 172, 172
 PGA Gain [dB]    : -10, -10
$ ss
. ss
 [ Current Status ]
 Trigger Mode     : Continuous
 Wave Type        : Sine Wave
 Polarity         : Single Mode
 Time Period      : 10us
 Sampling Rate    : 100kHz
 Tone Frequency   : 1kHz
 Flat duration    : 10ms
 Internal Trigger : 100ms
 PGA Gain [dB]    : -10, -10
$
    

出力サンプル

Tone burst 1k rise/fall 1ms flat 10ms

Arduino based Function Generator Tone Burst

Bipolar pulse

Arduino based Function Generator Bipolar pulse

Single pulse

Arduino based Function Generator Single pulse

Stimulation pulse for vibration excitor

信号開始のトリガはEXT1に出力しているが、ランプ後の刺激時にEXT2から別のトリガを出すようにしているので、 実際の刺激実験のトリガはEXT2を使う。ランプでは殆ど刺激されないので、EXT1でトリガをとって加算平均をとっても脳波には何も出ない。

vp1

Arduino based Function Generator

vp2

Arduino based Function Generator

If you were a Unix programmer you either programmed in C or shell. And there
really wasn't much in between. There were these little languages that we used
on top of shell, but that was the big divide. The big revelation that hatched
Perl, as it were, was that this opened up into a two-dimensional space. And C
was good at something I like to call manipulexity, that is the manipulation of
complex things. While shell was good at something else which I call
whipuptitude, the aptitude for whipping things up.

So Perl was hatched. As a small egg. That was Perl 1. And it was designed from
the very beginning to evolve. The fact that we put sigils in front of the
variables meant that the namespaces were protected from new keywords. And that
was intentional, so we could evolve the language fairly rapidly without
impacting.

And it evolved... And it evolved... And finally we got to Perl 5. And... So...
Perhaps the Perl 6 slogan should be "All Your Paradigms Are Belong To Us".
We'll get to that.

    -- Larry Wall
    -- Present Continuous, Future Perfect ( http://www.perl.org.il/presentations/larry-wall-present-continuous-future-perfect/transcript.html )

Work consists of whatever a body is obliged to do.
Play consists of whatever a body is not obliged to do.
		-- Mark Twain


Powered by UNIX fortune(6)
[ Main Page ]