論理合成します。
制約ファイルです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
## Clock signal set_property PACKAGE_PIN W5 [get_ports MCLK] set_property IOSTANDARD LVCMOS33 [get_ports MCLK] create_clock -period 10.000 -name sys_clk_pin -waveform {0.000 5.000} -add [get_ports MCLK] ##Buttons set_property PACKAGE_PIN U18 [get_ports MRST] set_property IOSTANDARD LVCMOS33 [get_ports MRST] ##Pmod Header JB ##Sch name = JB1 set_property PACKAGE_PIN A14 [get_ports STB] set_property IOSTANDARD LVCMOS33 [get_ports STB] ##Sch name = JB2 set_property PACKAGE_PIN A16 [get_ports {ADC_DATA[0]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[0]}] ##Sch name = JB3 set_property PACKAGE_PIN B15 [get_ports {ADC_DATA[2]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[2]}] ##Sch name = JB4 set_property PACKAGE_PIN B16 [get_ports {ADC_DATA[4]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[4]}] ##Sch name = JB7 #set_property PACKAGE_PIN A15 [get_ports {JB[1]}] #set_property IOSTANDARD LVCMOS33 [get_ports {JB[1]}] ##Sch name = JB8 set_property PACKAGE_PIN A17 [get_ports {ADC_DATA[1]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[1]}] ##Sch name = JB9 set_property PACKAGE_PIN C15 [get_ports {ADC_DATA[3]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[3]}] ##Sch name = JB10 set_property PACKAGE_PIN C16 [get_ports {ADC_DATA[5]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[5]}] ##Pmod Header JC ##Sch name = JC1 set_property PACKAGE_PIN K17 [get_ports {ADC_DATA[6]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[6]}] ##Sch name = JC2 set_property PACKAGE_PIN M18 [get_ports {ADC_DATA[8]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[8]}] ##Sch name = JC3 #set_property PACKAGE_PIN N17 [get_ports {JC[2]}] #set_property IOSTANDARD LVCMOS33 [get_ports {JC[2]}] ##Sch name = JC4 #set_property PACKAGE_PIN P18 [get_ports {JC[3]}] #set_property IOSTANDARD LVCMOS33 [get_ports {JC[3]}] ##Sch name = JC7 set_property PACKAGE_PIN L17 [get_ports {ADC_DATA[7]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[7]}] ##Sch name = JC8 set_property PACKAGE_PIN M19 [get_ports {ADC_DATA[9]}] set_property IOSTANDARD LVCMOS33 [get_ports {ADC_DATA[9]}] ##Sch name = JC9 #set_property PACKAGE_PIN P17 [get_ports {JC[6]}] #set_property IOSTANDARD LVCMOS33 [get_ports {JC[6]}] ##Sch name = JC10 #set_property PACKAGE_PIN R18 [get_ports {JC[7]}] #set_property IOSTANDARD LVCMOS33 [get_ports {JC[7]}] ##USB-RS232 Interface set_property PACKAGE_PIN B18 [get_ports RXD] set_property IOSTANDARD LVCMOS33 [get_ports RXD] set_property PACKAGE_PIN A18 [get_ports TXD] set_property IOSTANDARD LVCMOS33 [get_ports TXD] |
論理合成、配置配線すると、warningがたくさん出ますが、実害がなければそのまま放置しています。 あくまで遊びでやってますので、その辺は緩く..
C#でPC側のプログラムを作ります。
serialPortとtimerコンポーネントを使いました。 timerは、データが512バイト溜ったかどうかポーリングしています。
基本的には、UARTで行った方法と同じです。 DrawGraphクラスで、取得したデータをpaintBoxに表示しています。
ソースコードです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CS_SPANA { public partial class Form1 : Form { private delegate void Delegate_RcvDataToDataBuffer(byte[] data); int glcnt; byte[] databuffer = new byte[512]; short[] adcdata = new short[256]; DrawGraph dg1; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { byte[] data = { 1, 0 }; serialPort1.Write(data, 0, 2); glcnt = 0; timer1.Start(); } private void Form1_Load(object sender, EventArgs e) { try { serialPort1.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } dg1 = new DrawGraph(pictureBox1); } private void Form1_FormClosed(object sender, FormClosedEventArgs e) { serialPort1.Close(); } private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) { if (serialPort1.IsOpen == false) { return; } try { int rbyte = serialPort1.BytesToRead; byte[] buffer = new byte[rbyte]; serialPort1.Read(buffer, 0, rbyte); //! 受信したデータをDrawBufferに書き込む. Invoke(new Delegate_RcvDataToDataBuffer(RcvDataToDataBuffer), new Object[] { buffer }); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void RcvDataToDataBuffer(byte[] data) { for (int i = 0; i < data.Length; i++) { databuffer[glcnt] = data[i]; glcnt++; } } private void timer1_Tick(object sender, EventArgs e) { if (glcnt == 511) { for (int i = 0; i < databuffer.Length / 2; i++) { adcdata[i] = BitConverter.ToInt16(databuffer, i * 2); } glcnt = 0; pictureBox1.Refresh(); } } private void pictureBox1_Paint(object sender, PaintEventArgs e) { dg1.DrawAxis(e.Graphics); if (adcdata.Length != 0) dg1.DrawData(e.Graphics, adcdata); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; using System.Windows.Forms; using System.Drawing.Drawing2D; using System.Numerics; namespace CS_SPANA { class DrawGraph { private PictureBox picturebox_; private float x0_; //x軸原点 private float y0_; //y軸原点 private float y1_; //y軸1に対するピクセル値 private float width_; private Font myfont_ = new Font("MS UI Gothic", 10); private SolidBrush mysolidbrush_ = new SolidBrush(Color.Black); private const float x_offset = 10.0F; private const float y_offset = 10.0F; //コンストラクタ public DrawGraph(PictureBox myPictureBox) { picturebox_ = myPictureBox; x0_ = picturebox_.Left; y0_ = picturebox_.ClientSize.Height - 1; y1_ = y0_ /(float)(1.2* 1024); width_ = picturebox_.ClientSize.Width - 1; } public void DrawAxis(Graphics gr) { DrawVerticalLines(gr, Pens.Black); DrawHolizontalLines(gr, Pens.Black); } private void DrawHolizontalLines(Graphics gr, Pen mypen) { float yn = y0_ / 10; for (int i = 0; i <= y0_; i += 1) gr.DrawLine(mypen, 0, y0_ - yn * i, width_, y0_ - yn * i); } private void DrawVerticalLines(Graphics gr, Pen mypen) { float xn = width_ / 10; for (int i = 0; i <= (int)width_; i += 1) gr.DrawLine(mypen, xn * i, 0, xn * i, y0_); } public void DrawData(Graphics gr, short[] gdata) { Pen mypen = new Pen(Color.Red); PointF ioldPoint = new PointF(0, (float)(y0_ + y1_ * gdata[0] - y0_/2)); // PointF qoldPoint = new PointF(0, (float)(y0_ + y1_ * gdata[1] - y0_ / 2)); float tick = width_ / gdata.Length; for (int i = 1; i < gdata.Length; i++) { mypen.Color = Color.Red; PointF inewPoint = new PointF(i * tick, (float)(y0_ + y1_ * gdata[i]-y0_/2)); gr.DrawLine(mypen, ioldPoint, inewPoint); ioldPoint = inewPoint; /* mypen.Color = Color.Green; PointF qnewPoint = new PointF(i * tick, (float)(y0_ + y1_ * gdata[i+1] - y0_ / 2)); gr.DrawLine(mypen, qoldPoint, qnewPoint); qoldPoint = qnewPoint; */ } } } } |
いろいろ使いまわしているコードなので、余計なものも入っています。
1MHzの信号を入力した時の波形です。 あまりきれいな波形ではありませんが、信号源が適当なので、まあ、こんなもんでしょう。
信号がキャプチャできました。