-
Notifications
You must be signed in to change notification settings - Fork 1
/
xiaolaba_3phasePlotTest.ino
115 lines (99 loc) · 3.53 KB
/
xiaolaba_3phasePlotTest.ino
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
/* Qt serial port plot, test program, test platform, Uno
* 2018-MAR-24, by xiaolaba
* plot 0
* plot 3 phase shift 120 degree
* plot amplitude shift +300
*
*/
//ref : https://gist.github.com/funkfinger/965900
unsigned char sine_8bit [256] = {
/* ripped from http://aquaticus.info/pwm-sine-wave */
0x80, 0x83, 0x86, 0x89, 0x8C, 0x90, 0x93, 0x96,
0x99, 0x9C, 0x9F, 0xA2, 0xA5, 0xA8, 0xAB, 0xAE,
0xB1, 0xB3, 0xB6, 0xB9, 0xBC, 0xBF, 0xC1, 0xC4,
0xC7, 0xC9, 0xCC, 0xCE, 0xD1, 0xD3, 0xD5, 0xD8,
0xDA, 0xDC, 0xDE, 0xE0, 0xE2, 0xE4, 0xE6, 0xE8,
0xEA, 0xEB, 0xED, 0xEF, 0xF0, 0xF1, 0xF3, 0xF4,
0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFA, 0xFB, 0xFC,
0xFD, 0xFD, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFD,
0xFD, 0xFC, 0xFB, 0xFA, 0xFA, 0xF9, 0xF8, 0xF6,
0xF5, 0xF4, 0xF3, 0xF1, 0xF0, 0xEF, 0xED, 0xEB,
0xEA, 0xE8, 0xE6, 0xE4, 0xE2, 0xE0, 0xDE, 0xDC,
0xDA, 0xD8, 0xD5, 0xD3, 0xD1, 0xCE, 0xCC, 0xC9,
0xC7, 0xC4, 0xC1, 0xBF, 0xBC, 0xB9, 0xB6, 0xB3,
0xB1, 0xAE, 0xAB, 0xA8, 0xA5, 0xA2, 0x9F, 0x9C,
0x99, 0x96, 0x93, 0x90, 0x8C, 0x89, 0x86, 0x83,
0x80, 0x7D, 0x7A, 0x77, 0x74, 0x70, 0x6D, 0x6A,
0x67, 0x64, 0x61, 0x5E, 0x5B, 0x58, 0x55, 0x52,
0x4F, 0x4D, 0x4A, 0x47, 0x44, 0x41, 0x3F, 0x3C,
0x39, 0x37, 0x34, 0x32, 0x2F, 0x2D, 0x2B, 0x28,
0x26, 0x24, 0x22, 0x20, 0x1E, 0x1C, 0x1A, 0x18,
0x16, 0x15, 0x13, 0x11, 0x10, 0x0F, 0x0D, 0x0C,
0x0B, 0x0A, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,
0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03,
0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0A,
0x0B, 0x0C, 0x0D, 0x0F, 0x10, 0x11, 0x13, 0x15,
0x16, 0x18, 0x1A, 0x1C, 0x1E, 0x20, 0x22, 0x24,
0x26, 0x28, 0x2B, 0x2D, 0x2F, 0x32, 0x34, 0x37,
0x39, 0x3C, 0x3F, 0x41, 0x44, 0x47, 0x4A, 0x4D,
0x4F, 0x52, 0x55, 0x58, 0x5B, 0x5E, 0x61, 0x64,
0x67, 0x6A, 0x6D, 0x70, 0x74, 0x77, 0x7A, 0x7D
};
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// prints title with ending line break
Serial.println("sine wave, 3 phase / 3 lines, plot test");
}
#define phase0 (256/3*0) // for 0 degree
#define phase1 (256/3*1) // for 120 degree
#define phase2 (256/3*2) // for 240 degree
void loop() {
plot_phase_shift ();
// plot_0 ();
// plot_amplitude_shift();
// plot_0 ();
}
void plot_phase_shift (void) {
//phase shift plot
for(int i=0; i<256; i++)
{
// How to use the application
// see https://os.mbed.com/users/borislav/notebook/serial-port-plotter/
Serial.print("$"); //start of date frame
Serial.print(sine_8bit[ (i < 256-phase0) ? i+ phase0 : i- 256 + phase0 ] , DEC); //read sine table, dump value to serial port
Serial.print(" "); // seperator
Serial.print(sine_8bit[ (i < 256-phase1) ? i+ phase1 : i- 256 + phase1 ] , DEC); //read sine table, dump value to serial port
Serial.print(" "); // seperator
Serial.print(sine_8bit[ (i < 256-phase2) ? i+ phase2 : i- 256 + phase2 ] , DEC); //read sine table, dump value to serial port
Serial.print(";"); // end of data frame
delay(10);
}
}
void plot_0 (void) {
// plot 0
for(int i=0; i<50; i++)
{
Serial.print("$0 0 0;");
delay(10);
}
}
void plot_amplitude_shift (void) {
//amplitude shift plot
for(int i=0; i<256; i++)
{
Serial.print("$");
Serial.print(sine_8bit[i] + 0, DEC);
Serial.print(" ");
Serial.print(sine_8bit[i]+300, DEC);
Serial.print(" ");
Serial.print(sine_8bit[i]+600, DEC);
Serial.print(";");
delay(10);
}
}