Skip to content

Commit 4a17c8f

Browse files
committed
完善波形发生器波形预览
1 parent 75b9937 commit 4a17c8f

File tree

3 files changed

+111
-27
lines changed

3 files changed

+111
-27
lines changed

src/App.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<template>
22
<div class="container" style="justify-content:normal;">
3-
43
<el-row>
54
<!-- 左半屏幕 -->
65
<el-col :span="12">
@@ -25,7 +24,6 @@
2524

2625
</el-col>
2726
</el-row>
28-
2927
</div>
3028
</template>
3129
<style>

src/components/WaveGen.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
} from 'element-plus'
5252
5353
import { reactive } from 'vue'
54+
import { number } from "echarts/core";
5455
5556
defineProps<{ msg: string }>();
5657
@@ -94,6 +95,11 @@ const biasChange = (value: number) => {
9495
<script lang="ts">
9596
export default {
9697
name: "WaveGen",
98+
waveType: String,
99+
freq: number,
100+
duty: number,
101+
uMaxValue: number,
102+
biasVoltage: number,
97103
props1: {
98104
msg: String
99105
}
@@ -108,11 +114,12 @@ export default {
108114
font-size: 2em;
109115
}
110116
111-
.el-input-number {
117+
.el-input-number {
112118
width: 100%;
113119
min-width: 200px;
114120
}
115-
.el-select{
121+
122+
.el-select {
116123
width: 100%;
117124
min-width: 200px;
118125
}

src/components/WaveGenChart.vue

Lines changed: 102 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import { LineChart, LineSeriesOption } from 'echarts/charts';
1919
import { UniversalTransition } from 'echarts/features';
2020
import { CanvasRenderer } from 'echarts/renderers';
2121
import { onMounted } from 'vue';
22+
import WaveGenData from './WaveGen.vue'
23+
import { EChartsType } from 'echarts/core';
24+
import WaveGenVue from './WaveGen.vue';
2225
2326
echarts.use([
2427
ToolboxComponent,
@@ -60,19 +63,7 @@ const props = defineProps({
6063
});
6164
6265
var option: EChartsOption;
63-
64-
function func(x: number) {
65-
x /= 10;
66-
return Math.sin(x) * 3.3;
67-
}
68-
69-
function generateData() {
70-
let data = [];
71-
for (let i = 0; i <= 300; i += 1) {
72-
data.push([i, func(i)]);
73-
}
74-
return data;
75-
}
66+
var myChart: EChartsType;
7667
7768
option = {
7869
animation: false,
@@ -106,7 +97,7 @@ option = {
10697
}
10798
},
10899
xAxis: {
109-
name: 'x',
100+
name: '波形索引',
110101
min: 0,
111102
max: 256,
112103
minorTick: {
@@ -117,9 +108,9 @@ option = {
117108
}
118109
},
119110
yAxis: {
120-
name: 'y',
121-
min: -5,
122-
max: 5,
111+
name: '输出电压/V',
112+
min: -0.2,
113+
max: 3.5,
123114
minorTick: {
124115
show: true
125116
},
@@ -133,31 +124,118 @@ option = {
133124
type: 'inside',
134125
filterMode: 'filter',
135126
xAxisIndex: [0],
136-
startValue: -20,
137-
endValue: 20
127+
startValue: 0,
128+
endValue: 300
138129
},
139130
{
140131
show: true,
141132
type: 'inside',
133+
disabled: true,
134+
zoomLock: true,
142135
filterMode: 'empty',
143136
yAxisIndex: [0],
144-
startValue: -20,
145-
endValue: 20
137+
startValue: -1,
138+
endValue: 5
146139
}
147140
],
148141
series: [
149142
{
150143
type: 'line',
151144
showSymbol: false,
152145
clip: true,
153-
data: generateData()
146+
data: []
154147
}
155148
]
156149
};
157150
151+
// 绘制预览波形相关变量及函数
152+
var start = true;
153+
let uMaxValue = 3.3; //峰峰值
154+
let offSetValue = 1.65; //偏置电压
155+
let duty = 50; //占空比%(方波)
156+
let wave = 1; //波形种类
157+
let samplePerCycle = 256;
158+
//定义板载8位DAC输出的对应值
159+
var waveTab1 = new Array();
160+
var waveTab = new Array();
161+
162+
163+
function wave_gen(index: number) {
164+
if (index == 1) {
165+
var sineValue = 0.0;
166+
for (var i = 0; i < samplePerCycle; i++) {
167+
sineValue = Math.sin(((2 * Math.PI) / samplePerCycle) * i) * (uMaxValue / 2) + offSetValue;
168+
waveTab1[i] = (((sineValue * 255 / 3.3)));
169+
}
170+
console.log("波形表重设成功,当前为正弦波\n");
171+
}
172+
else if (index == 2) {
173+
var x = samplePerCycle * (duty / 100.0);
174+
var x1 = x;
175+
for (var i = 0; i < samplePerCycle; i++) {
176+
if (i < x) {
177+
waveTab1[i] = (255 * (uMaxValue / 2 + offSetValue) / 3.3);
178+
}
179+
else {
180+
waveTab1[i] = (255 * (-(uMaxValue / 2) + offSetValue) / 3.3);
181+
}
182+
}
183+
console.log("波形表重设成功,当前为方波,占空比:" + duty + "\n");
184+
}
185+
else if (index == 3) //锯齿波
186+
{
187+
for (var i = -127; i < 128; i++) {
188+
waveTab1[i + 127] = ((i + (offSetValue * 255 / 3.3)) * (uMaxValue / 3.3));
189+
190+
}
191+
console.log("波形表重设成功,当前为锯齿波\n");
192+
}
193+
for (var i = 0; i < samplePerCycle; i++) {
194+
if (waveTab1[i] > 255) {
195+
waveTab1[i] = 255;
196+
}
197+
if (waveTab1[i] < 0) {
198+
waveTab1[i] = 0;
199+
}
200+
waveTab[i] = waveTab1[i] * 3.3 / 255;
201+
202+
}
203+
console.log(waveTab);
204+
}
205+
206+
function generateData() {
207+
let data = [];
208+
for (let i = 0; i <= 256; i++) {
209+
data.push([i, waveTab[i]]);
210+
}
211+
return data;
212+
}
213+
214+
function refreshData() {
215+
wave = parseInt(WaveGenData.waveType);
216+
offSetValue = WaveGenData.biasVoltage;
217+
duty = WaveGenData.duty;
218+
uMaxValue = WaveGenData.uMaxValue;
219+
wave_gen(wave);
220+
//刷新数据
221+
if (start === true) {
222+
myChart.setOption({
223+
series: [
224+
{
225+
data: generateData()
226+
}
227+
]
228+
});
229+
}
230+
}
231+
232+
233+
158234
onMounted(() => {
235+
wave_gen(1);
159236
var chartDom = document.getElementById(props.container) as HTMLElement
160-
var myChart = echarts.init(chartDom);
237+
myChart = echarts.init(chartDom);
238+
option.series[0].data = generateData(); // 搞不明白为啥报错,但能用
161239
option && myChart.setOption(option);
162240
})
163241
@@ -181,6 +259,7 @@ export default {
181259
182260
</script>
183261

262+
184263
<style>
185264
.WaveGenChart {
186265
margin: 0 auto;

0 commit comments

Comments
 (0)