-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
129 lines (110 loc) · 4.73 KB
/
main.cc
File metadata and controls
129 lines (110 loc) · 4.73 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "WF_SDK/WF_SDK.h"
#include "digilent/waveforms/dwf.h"
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <unistd.h> // for sleep function
using namespace wf;
Device::Data *device_data;
/* ----------------------------------------------------- */
bool or_func(int iAddress);
void configure_rom(int chan, bool (*func)(int));
int main(void)
{
device_data = device.open();
// Set up power supply
FDwfAnalogIOReset(device_data->handle);
FDwfAnalogIOChannelNodeSet(device_data->handle, 0, 0, 1); // turn on ps
FDwfAnalogIOChannelNodeSet(device_data->handle, 0, 1, 3.3); // set ps voltage to 5 volts
FDwfAnalogIOEnableSet(device_data->handle, true); // master enable
sleep(1); // wait a second for the power supply voltage to come up (possibly unnecessary)
FDwfAnalogOutReset(device_data->handle, 1);
// PPS
std::vector<std::double_t> data = {0};
data.resize(10000);
data[9] = 1;
FDwfAnalogOutNodeEnableSet(device_data->handle, 0, AnalogOutNodeCarrier, true);
FDwfAnalogOutNodeFunctionSet(device_data->handle, 0, AnalogOutNodeCarrier, funcCustom);
FDwfAnalogOutNodeFrequencySet(device_data->handle, 0, AnalogOutNodeCarrier, 1000.0);
FDwfAnalogOutNodeAmplitudeSet(device_data->handle, 0, AnalogOutNodeCarrier, 3.3);
FDwfAnalogOutNodeOffsetSet(device_data->handle, 0, AnalogOutNodeCarrier, 0.0);
FDwfAnalogOutNodePhaseSet(device_data->handle, 0, AnalogOutNodeCarrier, 0.0);
FDwfAnalogOutNodeDataSet(device_data->handle, 0, AnalogOutNodeCarrier, data.data(), data.size());
FDwfAnalogOutModeSet(device_data->handle, 0, DwfAnalogOutModeVoltage);
FDwfAnalogOutIdleSet(device_data->handle, 0, DwfAnalogOutIdleOffset);
FDwfAnalogOutRunSet(device_data->handle, 0, 0.001);
FDwfAnalogOutWaitSet(device_data->handle, 0, 0.0);
FDwfAnalogOutRepeatSet(device_data->handle, 0, 0);
FDwfAnalogOutTriggerSourceSet(device_data->handle, 0, trigsrcExternal1); // check later
FDwfAnalogOutTriggerSlopeSet(device_data->handle, 0, DwfTriggerSlopeRise);
FDwfAnalogOutRepeatTriggerSet(device_data->handle, 0, true);
FDwfAnalogOutConfigure(device_data->handle, 0, true);
// PAT
FDwfAnalogOutNodeEnableSet(device_data->handle, 1, AnalogOutNodeCarrier, true);
FDwfAnalogOutNodeFunctionSet(device_data->handle, 1, AnalogOutNodeCarrier, funcCustom);
FDwfAnalogOutNodeFrequencySet(device_data->handle, 1, AnalogOutNodeCarrier, 1000.0);
FDwfAnalogOutNodeAmplitudeSet(device_data->handle, 1, AnalogOutNodeCarrier, 3.3);
FDwfAnalogOutNodeOffsetSet(device_data->handle, 1, AnalogOutNodeCarrier, 0.0);
FDwfAnalogOutNodePhaseSet(device_data->handle, 1, AnalogOutNodeCarrier, 0.0);
FDwfAnalogOutNodeDataSet(device_data->handle, 1, AnalogOutNodeCarrier, data.data(), data.size());
FDwfAnalogOutModeSet(device_data->handle, 1, DwfAnalogOutModeVoltage);
FDwfAnalogOutIdleSet(device_data->handle, 1, DwfAnalogOutIdleOffset);
FDwfAnalogOutRunSet(device_data->handle, 1, 0.01);
FDwfAnalogOutWaitSet(device_data->handle, 1, 0.0);
FDwfAnalogOutRepeatSet(device_data->handle, 1, 0);
FDwfAnalogOutTriggerSourceSet(device_data->handle, 1, trigsrcPC);
FDwfAnalogOutTriggerSlopeSet(device_data->handle, 1, DwfTriggerSlopeRise);
FDwfAnalogOutRepeatTriggerSet(device_data->handle, 1, true);
FDwfAnalogOutConfigure(device_data->handle, 1, true);
// OR
configure_rom(15, or_func);
FDwfDigitalOutConfigure(device_data->handle, 1);
// exit when q is pressed
std::cout << "Press 't' to trigger and 'q' to quit" << std::endl;
std::string input;
while (true)
{
std::getline(std::cin, input);
if (input == "t")
{
FDwfDeviceTriggerPC(device_data->handle);
}
else if (input == "q")
{
break;
}
}
device.close(device_data);
return 0;
}
void configure_rom(int chan, bool (*func)(int))
{
unsigned int customSize = 0;
FDwfDigitalOutDataInfo(device_data->handle, chan, &customSize);
std::cout << "Custom size: " << customSize
<< " Address space: " << (int)log2(customSize) << std::endl;
int bufferSizeBytes = customSize / 8;
std::vector<uint8_t> rgbSamples(bufferSizeBytes, 0);
for (unsigned int iAddress = 0; iAddress < customSize; ++iAddress)
{
if (func(iAddress))
{
rgbSamples[iAddress / 8] |= (1 << (iAddress % 8));
}
}
for (int i = 0; i < 3; ++i)
{
FDwfDigitalOutEnableSet(device_data->handle, 0, 0);
}
FDwfDigitalOutEnableSet(device_data->handle, chan, 1); // enable output
FDwfDigitalOutTypeSet(device_data->handle, chan, DwfDigitalOutTypeROM);
FDwfDigitalOutDividerSet(device_data->handle, chan, 1); // set minimum delay
FDwfDigitalOutDataSet(device_data->handle, chan, rgbSamples.data(), customSize);
}
bool or_func(int iAddress)
{
int fDio2 = (iAddress >> 2) & 1;
int fDio1 = (iAddress >> 1) & 1;
return (fDio2 == 1 || fDio1 == 1);
}