/
main.c
232 lines (180 loc) · 23.2 KB
/
main.c
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/* Defines the base address of the memories and peripherals */
#include "inc/hw_memmap.h"
/* Defines the common types and macros */
#include "inc/hw_types.h"
#include "inc/hw_timer.h"
#include "inc/hw_ints.h"
/* Defines and Macros for GPIO API */
#include "driverlib/gpio.h"
/* Prototypes for the system control driver */
#include "driverlib/sysctl.h"
/* ADC headers for using the ADC driver functions. */
#include "driverlib/adc.h"
/* Defines and Macros for the UART. */
#include "driverlib/uart.h"
/* Prototypes for the NVIC Interrupt Controller Driver. */
#include "driverlib/interrupt.h"
/* Prototypes for the UART console functions. */
#include "utils/uartstdio.h"
#include "IQmath/IQmathLib.h"
#include "driverlib/timer.h"
#define N 514
void InitConsole(void)
{
/* Enable GPIO port A which is used for UART0 pins.*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
/* Make the UART pins be peripheral controlled.*/
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
/* Initialize the UART for console I/O.*/
UARTStdioInit(0);
}
//100hz-850hz
const float b1[652]={-0.000021,-0.000023,-0.000025,-0.000027,-0.000029,-0.000031,-0.000034,-0.000036,-0.000038,-0.000041,-0.000043,-0.000045,-0.000047,-0.000049,-0.000051,-0.000052,-0.000054,-0.000055,-0.000056,-0.000057,-0.000058,-0.000058,-0.000058,-0.000058,-0.000057,-0.000056,-0.000055,-0.000053,-0.000051,-0.000049,-0.000046,-0.000043,-0.000039,-0.000036,-0.000031,-0.000027,-0.000022,-0.000016,-0.000011,-0.000005,0.000001,0.000008,0.000014,0.000021,0.000028,0.000035,0.000042,0.000049,0.000055,0.000062,0.000069,0.000075,0.000082,0.000088,0.000093,0.000098,0.000103,0.000107,0.000111,0.000114,0.000117,0.000119,0.000120,0.000121,0.000121,0.000120,0.000119,0.000116,0.000113,0.000110,0.000105,0.000100,0.000094,0.000088,0.000081,0.000073,0.000065,0.000057,0.000048,0.000039,0.000029,0.000020,0.000010,0.000001,-0.000009,-0.000018,-0.000026,-0.000034,-0.000042,-0.000049,-0.000054,-0.000059,-0.000063,-0.000066,-0.000067,-0.000067,-0.000066,-0.000062,-0.000057,-0.000051,-0.000042,-0.000032,-0.000019,-0.000004,0.000012,0.000031,0.000052,0.000075,0.000100,0.000128,0.000157,0.000188,0.000222,0.000257,0.000294,0.000332,0.000372,0.000413,0.000456,0.000499,0.000544,0.000588,0.000634,0.000679,0.000725,0.000770,0.000815,0.000859,0.000901,0.000943,0.000983,0.001021,0.001057,0.001091,0.001122,0.001150,0.001176,0.001198,0.001216,0.001231,0.001241,0.001248,0.001251,0.001249,0.001242,0.001231,0.001216,0.001195,0.001170,0.001141,0.001106,0.001067,0.001024,0.000976,0.000924,0.000868,0.000808,0.000745,0.000678,0.000608,0.000536,0.000461,0.000384,0.000305,0.000225,0.000144,0.000063,-0.000019,-0.000100,-0.000180,-0.000258,-0.000335,-0.000410,-0.000482,-0.000551,-0.000616,-0.000678,-0.000735,-0.000787,-0.000834,-0.000875,-0.000911,-0.000941,-0.000964,-0.000981,-0.000991,-0.000995,-0.000991,-0.000981,-0.000963,-0.000939,-0.000908,-0.000871,-0.000826,-0.000776,-0.000720,-0.000659,-0.000592,-0.000521,-0.000445,-0.000366,-0.000284,-0.000199,-0.000113,-0.000025,0.000062,0.000150,0.000236,0.000320,0.000401,0.000478,0.000551,0.000618,0.000679,0.000733,0.000779,0.000816,0.000844,0.000861,0.000867,0.000862,0.000844,0.000813,0.000768,0.000710,0.000636,0.000548,0.000445,0.000326,0.000192,0.000042,-0.000124,-0.000305,-0.000501,-0.000712,-0.000939,-0.001179,-0.001433,-0.001700,-0.001979,-0.002270,-0.002571,-0.002882,-0.003201,-0.003528,-0.003860,-0.004198,-0.004539,-0.004881,-0.005225,-0.005567,-0.005906,-0.006242,-0.006571,-0.006893,-0.007205,-0.007507,-0.007796,-0.008070,-0.008329,-0.008569,-0.008791,-0.008992,-0.009170,-0.009325,-0.009454,-0.009557,-0.009632,-0.009679,-0.009695,-0.009680,-0.009634,-0.009555,-0.009444,-0.009298,-0.009119,-0.008906,-0.008658,-0.008377,-0.008061,-0.007712,-0.007330,-0.006915,-0.006469,-0.005992,-0.005485,-0.004950,-0.004387,-0.003799,-0.003186,-0.002552,-0.001896,-0.001222,-0.000531,0.000175,0.000892,0.001620,0.002356,0.003097,0.003841,0.004586,0.005328,0.006066,0.006797,0.007518,0.008227,0.008921,0.009597,0.010255,0.010890,0.011501,0.012086,0.012642,0.013167,0.013660,0.014118,0.014541,0.014926,0.015271,0.015577,0.015841,0.016062,0.016240,0.016374,0.016464,0.016509,0.016509,0.016464,0.016374,0.016240,0.016062,0.015841,0.015577,0.015271,0.014926,0.014541,0.014118,0.013660,0.013167,0.012642,0.012086,0.011501,0.010890,0.010255,0.009597,0.008921,0.008227,0.007518,0.006797,0.006066,0.005328,0.004586,0.003841,0.003097,0.002356,0.001620,0.000892,0.000175,-0.000531,-0.001222,-0.001896,-0.002552,-0.003186,-0.003799,-0.004387,-0.004950,-0.005485,-0.005992,-0.006469,-0.006915,-0.007330,-0.007712,-0.008061,-0.008377,-0.008658,-0.008906,-0.009119,-0.009298,-0.009444,-0.009555,-0.009634,-0.009680,-0.009695,-0.009679,-0.009632,-0.009557,-0.009454,-0.009325,-0.009170,-0.008992,-0.008791,-0.008569,-0.008329,-0.008070,-0.007796,-0.007507,-0.007205,-0.006893,-0.006571,-0.006242,-0.005906,-0.005567,-0.005225,-0.004881,-0.004539,-0.004198,-0.003860,-0.003528,-0.003201,-0.002882,-0.002571,-0.002270,-0.001979,-0.001700,-0.001433,-0.001179,-0.000939,-0.000712,-0.000501,-0.000305,-0.000124,0.000042,0.000192,0.000326,0.000445,0.000548,0.000636,0.000710,0.000768,0.000813,0.000844,0.000862,0.000867,0.000861,0.000844,0.000816,0.000779,0.000733,0.000679,0.000618,0.000551,0.000478,0.000401,0.000320,0.000236,0.000150,0.000062,-0.000025,-0.000113,-0.000199,-0.000284,-0.000366,-0.000445,-0.000521,-0.000592,-0.000659,-0.000720,-0.000776,-0.000826,-0.000871,-0.000908,-0.000939,-0.000963,-0.000981,-0.000991,-0.000995,-0.000991,-0.000981,-0.000964,-0.000941,-0.000911,-0.000875,-0.000834,-0.000787,-0.000735,-0.000678,-0.000616,-0.000551,-0.000482,-0.000410,-0.000335,-0.000258,-0.000180,-0.000100,-0.000019,0.000063,0.000144,0.000225,0.000305,0.000384,0.000461,0.000536,0.000608,0.000678,0.000745,0.000808,0.000868,0.000924,0.000976,0.001024,0.001067,0.001106,0.001141,0.001170,0.001195,0.001216,0.001231,0.001242,0.001249,0.001251,0.001248,0.001241,0.001231,0.001216,0.001198,0.001176,0.001150,0.001122,0.001091,0.001057,0.001021,0.000983,0.000943,0.000901,0.000859,0.000815,0.000770,0.000725,0.000679,0.000634,0.000588,0.000544,0.000499,0.000456,0.000413,0.000372,0.000332,0.000294,0.000257,0.000222,0.000188,0.000157,0.000128,0.000100,0.000075,0.000052,0.000031,0.000012,-0.000004,-0.000019,-0.000032,-0.000042,-0.000051,-0.000057,-0.000062,-0.000066,-0.000067,-0.000067,-0.000066,-0.000063,-0.000059,-0.000054,-0.000049,-0.000042,-0.000034,-0.000026,-0.000018,-0.000009,0.000001,0.000010,0.000020,0.000029,0.000039,0.000048,0.000057,0.000065,0.000073,0.000081,0.000088,0.000094,0.000100,0.000105,0.000110,0.000113,0.000116,0.000119,0.000120,0.000121,0.000121,0.000120,0.000119,0.000117,0.000114,0.000111,0.000107,0.000103,0.000098,0.000093,0.000088,0.000082,0.000075,0.000069,0.000062,0.000055,0.000049,0.000042,0.000035,0.000028,0.000021,0.000014,0.000008,0.000001,-0.000005,-0.000011,-0.000016,-0.000022,-0.000027,-0.000031,-0.000036,-0.000039,-0.000043,-0.000046,-0.000049,-0.000051,-0.000053,-0.000055,-0.000056,-0.000057,-0.000058,-0.000058,-0.000058,-0.000058,-0.000057,-0.000056,-0.000055,-0.000054,-0.000052,-0.000051,-0.000049,-0.000047,-0.000045,-0.000043,-0.000041,-0.000038,-0.000036,-0.000034,-0.000031,-0.000029,-0.000027,-0.000025,-0.000023,-0.000021};
_iq17 l1,l2,l3,m,n1,n2,n3;
//850-2.4k
const float b2[652]={-0.000004,-0.000001,0.000002,0.000006,0.000011,0.000017,0.000023,0.000029,0.000034,0.000040,0.000044,0.000047,0.000048,0.000048,0.000046,0.000042,0.000036,0.000028,0.000019,0.000010,-0.000001,-0.000011,-0.000020,-0.000028,-0.000035,-0.000039,-0.000042,-0.000042,-0.000039,-0.000035,-0.000029,-0.000021,-0.000013,-0.000006,0.000001,0.000006,0.000008,0.000007,0.000003,-0.000005,-0.000016,-0.000031,-0.000049,-0.000068,-0.000088,-0.000109,-0.000128,-0.000144,-0.000156,-0.000163,-0.000164,-0.000158,-0.000146,-0.000127,-0.000102,-0.000071,-0.000037,0.000001,0.000039,0.000076,0.000111,0.000142,0.000166,0.000184,0.000194,0.000195,0.000189,0.000175,0.000155,0.000130,0.000103,0.000075,0.000049,0.000026,0.000010,0.000001,0.000001,0.000011,0.000029,0.000057,0.000092,0.000133,0.000176,0.000219,0.000260,0.000294,0.000318,0.000331,0.000330,0.000313,0.000279,0.000230,0.000166,0.000089,0.000002,-0.000091,-0.000186,-0.000279,-0.000366,-0.000441,-0.000502,-0.000545,-0.000568,-0.000571,-0.000553,-0.000516,-0.000462,-0.000395,-0.000319,-0.000239,-0.000161,-0.000088,-0.000027,0.000019,0.000047,0.000054,0.000041,0.000007,-0.000044,-0.000108,-0.000182,-0.000259,-0.000333,-0.000397,-0.000445,-0.000471,-0.000470,-0.000439,-0.000377,-0.000283,-0.000159,-0.000009,0.000160,0.000343,0.000530,0.000713,0.000882,0.001029,0.001147,0.001228,0.001268,0.001265,0.001218,0.001129,0.001003,0.000846,0.000667,0.000476,0.000283,0.000098,-0.000067,-0.000206,-0.000309,-0.000373,-0.000394,-0.000374,-0.000315,-0.000223,-0.000108,0.000022,0.000154,0.000275,0.000374,0.000440,0.000462,0.000434,0.000351,0.000213,0.000021,-0.000219,-0.000495,-0.000798,-0.001111,-0.001419,-0.001706,-0.001954,-0.002150,-0.002279,-0.002334,-0.002307,-0.002198,-0.002008,-0.001747,-0.001423,-0.001054,-0.000655,-0.000246,0.000152,0.000520,0.000841,0.001099,0.001283,0.001387,0.001408,0.001350,0.001221,0.001035,0.000809,0.000562,0.000317,0.000095,-0.000081,-0.000194,-0.000229,-0.000174,-0.000026,0.000214,0.000539,0.000934,0.001380,0.001854,0.002328,0.002774,0.003162,0.003465,0.003660,0.003728,0.003655,0.003437,0.003076,0.002582,0.001972,0.001272,0.000511,-0.000277,-0.001055,-0.001788,-0.002441,-0.002984,-0.003393,-0.003651,-0.003751,-0.003693,-0.003489,-0.003157,-0.002726,-0.002229,-0.001703,-0.001191,-0.000730,-0.000358,-0.000108,-0.000002,-0.000057,-0.000276,-0.000652,-0.001167,-0.001793,-0.002491,-0.003216,-0.003917,-0.004543,-0.005043,-0.005369,-0.005483,-0.005356,-0.004969,-0.004320,-0.003419,-0.002293,-0.000981,0.000466,0.001986,0.003514,0.004978,0.006310,0.007446,0.008332,0.008924,0.009195,0.009135,0.008752,0.008072,0.007140,0.006014,0.004765,0.003472,0.002220,0.001091,0.000160,-0.000508,-0.000864,-0.000876,-0.000539,0.000134,0.001100,0.002299,0.003645,0.005039,0.006369,0.007515,0.008361,0.008795,0.008721,0.008063,0.006771,0.004824,0.002239,-0.000936,-0.004616,-0.008682,-0.012988,-0.017363,-0.021618,-0.025558,-0.028987,-0.031716,-0.033579,-0.034435,-0.034177,-0.032743,-0.030114,-0.026320,-0.021442,-0.015608,-0.008989,-0.001793,0.005741,0.013354,0.020778,0.027746,0.034002,0.039314,0.043485,0.046356,0.047819,0.047819,0.046356,0.043485,0.039314,0.034002,0.027746,0.020778,0.013354,0.005741,-0.001793,-0.008989,-0.015608,-0.021442,-0.026320,-0.030114,-0.032743,-0.034177,-0.034435,-0.033579,-0.031716,-0.028987,-0.025558,-0.021618,-0.017363,-0.012988,-0.008682,-0.004616,-0.000936,0.002239,0.004824,0.006771,0.008063,0.008721,0.008795,0.008361,0.007515,0.006369,0.005039,0.003645,0.002299,0.001100,0.000134,-0.000539,-0.000876,-0.000864,-0.000508,0.000160,0.001091,0.002220,0.003472,0.004765,0.006014,0.007140,0.008072,0.008752,0.009135,0.009195,0.008924,0.008332,0.007446,0.006310,0.004978,0.003514,0.001986,0.000466,-0.000981,-0.002293,-0.003419,-0.004320,-0.004969,-0.005356,-0.005483,-0.005369,-0.005043,-0.004543,-0.003917,-0.003216,-0.002491,-0.001793,-0.001167,-0.000652,-0.000276,-0.000057,-0.000002,-0.000108,-0.000358,-0.000730,-0.001191,-0.001703,-0.002229,-0.002726,-0.003157,-0.003489,-0.003693,-0.003751,-0.003651,-0.003393,-0.002984,-0.002441,-0.001788,-0.001055,-0.000277,0.000511,0.001272,0.001972,0.002582,0.003076,0.003437,0.003655,0.003728,0.003660,0.003465,0.003162,0.002774,0.002328,0.001854,0.001380,0.000934,0.000539,0.000214,-0.000026,-0.000174,-0.000229,-0.000194,-0.000081,0.000095,0.000317,0.000562,0.000809,0.001035,0.001221,0.001350,0.001408,0.001387,0.001283,0.001099,0.000841,0.000520,0.000152,-0.000246,-0.000655,-0.001054,-0.001423,-0.001747,-0.002008,-0.002198,-0.002307,-0.002334,-0.002279,-0.002150,-0.001954,-0.001706,-0.001419,-0.001111,-0.000798,-0.000495,-0.000219,0.000021,0.000213,0.000351,0.000434,0.000462,0.000440,0.000374,0.000275,0.000154,0.000022,-0.000108,-0.000223,-0.000315,-0.000374,-0.000394,-0.000373,-0.000309,-0.000206,-0.000067,0.000098,0.000283,0.000476,0.000667,0.000846,0.001003,0.001129,0.001218,0.001265,0.001268,0.001228,0.001147,0.001029,0.000882,0.000713,0.000530,0.000343,0.000160,-0.000009,-0.000159,-0.000283,-0.000377,-0.000439,-0.000470,-0.000471,-0.000445,-0.000397,-0.000333,-0.000259,-0.000182,-0.000108,-0.000044,0.000007,0.000041,0.000054,0.000047,0.000019,-0.000027,-0.000088,-0.000161,-0.000239,-0.000319,-0.000395,-0.000462,-0.000516,-0.000553,-0.000571,-0.000568,-0.000545,-0.000502,-0.000441,-0.000366,-0.000279,-0.000186,-0.000091,0.000002,0.000089,0.000166,0.000230,0.000279,0.000313,0.000330,0.000331,0.000318,0.000294,0.000260,0.000219,0.000176,0.000133,0.000092,0.000057,0.000029,0.000011,0.000001,0.000001,0.000010,0.000026,0.000049,0.000075,0.000103,0.000130,0.000155,0.000175,0.000189,0.000195,0.000194,0.000184,0.000166,0.000142,0.000111,0.000076,0.000039,0.000001,-0.000037,-0.000071,-0.000102,-0.000127,-0.000146,-0.000158,-0.000164,-0.000163,-0.000156,-0.000144,-0.000128,-0.000109,-0.000088,-0.000068,-0.000049,-0.000031,-0.000016,-0.000005,0.000003,0.000007,0.000008,0.000006,0.000001,-0.000006,-0.000013,-0.000021,-0.000029,-0.000035,-0.000039,-0.000042,-0.000042,-0.000039,-0.000035,-0.000028,-0.000020,-0.000011,-0.000001,0.000010,0.000019,0.000028,0.000036,0.000042,0.000046,0.000048,0.000048,0.000047,0.000044,0.000040,0.000034,0.000029,0.000023,0.000017,0.000011,0.000006,0.000002,-0.000001,-0.000004};
//2.4k-5k
const float b3[652]={0.000000,0.000001,0.000012,0.000023,0.000023,0.000008,-0.000012,-0.000024,-0.000018,-0.000004,0.000005,-0.000005,-0.000029,-0.000050,-0.000049,-0.000027,0.000000,0.000010,-0.000004,-0.000028,-0.000034,-0.000011,0.000032,0.000063,0.000062,0.000032,0.000004,0.000005,0.000040,0.000080,0.000088,0.000050,-0.000008,-0.000045,-0.000036,0.000004,0.000030,0.000008,-0.000058,-0.000121,-0.000133,-0.000085,-0.000019,0.000008,-0.000025,-0.000088,-0.000115,-0.000070,0.000029,0.000112,0.000123,0.000065,0.000000,-0.000001,0.000078,0.000178,0.000216,0.000154,0.000034,-0.000052,-0.000041,0.000042,0.000108,0.000073,-0.000062,-0.000207,-0.000258,-0.000185,-0.000059,0.000001,-0.000064,-0.000199,-0.000281,-0.000218,-0.000036,0.000138,0.000183,0.000087,-0.000039,-0.000052,0.000094,0.000305,0.000418,0.000342,0.000138,-0.000027,-0.000021,0.000134,0.000277,0.000246,0.000015,-0.000267,-0.000402,-0.000311,-0.000103,0.000011,-0.000097,-0.000356,-0.000550,-0.000497,-0.000211,0.000100,0.000210,0.000066,-0.000158,-0.000209,0.000026,0.000412,0.000670,0.000612,0.000308,0.000029,0.000022,0.000289,0.000576,0.000590,0.000249,-0.000233,-0.000516,-0.000427,-0.000108,0.000096,-0.000063,-0.000513,-0.000911,-0.000927,-0.000533,-0.000035,0.000178,-0.000028,-0.000412,-0.000556,-0.000227,0.000409,0.000909,0.000929,0.000516,0.000081,0.000047,0.000479,0.001012,0.001156,0.000715,-0.000027,-0.000536,-0.000476,-0.000007,0.000347,0.000147,-0.000570,-0.001300,-0.001488,-0.001007,-0.000275,0.000089,-0.000201,-0.000839,-0.001178,-0.000784,0.000172,0.001036,0.001218,0.000696,0.000046,-0.000046,0.000614,0.001539,0.001957,0.001472,0.000418,-0.000406,-0.000409,0.000272,0.000882,0.000689,-0.000367,-0.001592,-0.002105,-0.001588,-0.000574,0.000000,-0.000401,-0.001433,-0.002139,-0.001771,-0.000443,0.000927,0.001383,0.000749,-0.000208,-0.000426,0.000523,0.002033,0.002946,0.002533,0.001133,-0.000109,-0.000213,0.000782,0.001830,0.001763,0.000316,-0.001604,-0.002652,-0.002185,-0.000825,0.000055,-0.000483,-0.002109,-0.003464,-0.003302,-0.001581,0.000461,0.001333,0.000567,-0.000862,-0.001354,-0.000074,0.002281,0.004018,0.003872,0.002102,0.000300,0.000042,0.001518,0.003321,0.003628,0.001780,-0.001092,-0.002976,-0.002675,-0.000850,0.000522,-0.000157,-0.002681,-0.005142,-0.005520,-0.003422,-0.000475,0.001020,0.000061,-0.002163,-0.003244,-0.001639,0.001938,0.005029,0.005477,0.003286,0.000660,0.000143,0.002396,0.005548,0.006729,0.004533,0.000304,-0.002916,-0.002947,-0.000370,0.001913,0.001158,-0.002789,-0.007224,-0.008790,-0.006352,-0.002044,0.000476,-0.000841,-0.004590,-0.007008,-0.005181,0.000345,0.005861,0.007544,0.004739,0.000619,-0.000466,0.003218,0.009118,0.012392,0.010006,0.003467,-0.002275,-0.002966,0.001224,0.005666,0.005144,-0.001549,-0.010267,-0.014772,-0.012015,-0.004924,-0.000132,-0.002329,-0.009983,-0.016265,-0.014699,-0.004903,0.006622,0.011658,0.007323,-0.001071,-0.004152,0.003453,0.017912,0.028640,0.026932,0.013764,-0.000183,-0.003051,0.007728,0.022017,0.024417,0.007330,-0.021086,-0.041726,-0.039723,-0.018372,0.000423,-0.008154,-0.050361,-0.103308,-0.125660,-0.084812,0.017463,0.139825,0.222524,0.222524,0.139825,0.017463,-0.084812,-0.125660,-0.103308,-0.050361,-0.008154,0.000423,-0.018372,-0.039723,-0.041726,-0.021086,0.007330,0.024417,0.022017,0.007728,-0.003051,-0.000183,0.013764,0.026932,0.028640,0.017912,0.003453,-0.004152,-0.001071,0.007323,0.011658,0.006622,-0.004903,-0.014699,-0.016265,-0.009983,-0.002329,-0.000132,-0.004924,-0.012015,-0.014772,-0.010267,-0.001549,0.005144,0.005666,0.001224,-0.002966,-0.002275,0.003467,0.010006,0.012392,0.009118,0.003218,-0.000466,0.000619,0.004739,0.007544,0.005861,0.000345,-0.005181,-0.007008,-0.004590,-0.000841,0.000476,-0.002044,-0.006352,-0.008790,-0.007224,-0.002789,0.001158,0.001913,-0.000370,-0.002947,-0.002916,0.000304,0.004533,0.006729,0.005548,0.002396,0.000143,0.000660,0.003286,0.005477,0.005029,0.001938,-0.001639,-0.003244,-0.002163,0.000061,0.001020,-0.000475,-0.003422,-0.005520,-0.005142,-0.002681,-0.000157,0.000522,-0.000850,-0.002675,-0.002976,-0.001092,0.001780,0.003628,0.003321,0.001518,0.000042,0.000300,0.002102,0.003872,0.004018,0.002281,-0.000074,-0.001354,-0.000862,0.000567,0.001333,0.000461,-0.001581,-0.003302,-0.003464,-0.002109,-0.000483,0.000055,-0.000825,-0.002185,-0.002652,-0.001604,0.000316,0.001763,0.001830,0.000782,-0.000213,-0.000109,0.001133,0.002533,0.002946,0.002033,0.000523,-0.000426,-0.000208,0.000749,0.001383,0.000927,-0.000443,-0.001771,-0.002139,-0.001433,-0.000401,0.000000,-0.000574,-0.001588,-0.002105,-0.001592,-0.000367,0.000689,0.000882,0.000272,-0.000409,-0.000406,0.000418,0.001472,0.001957,0.001539,0.000614,-0.000046,0.000046,0.000696,0.001218,0.001036,0.000172,-0.000784,-0.001178,-0.000839,-0.000201,0.000089,-0.000275,-0.001007,-0.001488,-0.001300,-0.000570,0.000147,0.000347,-0.000007,-0.000476,-0.000536,-0.000027,0.000715,0.001156,0.001012,0.000479,0.000047,0.000081,0.000516,0.000929,0.000909,0.000409,-0.000227,-0.000556,-0.000412,-0.000028,0.000178,-0.000035,-0.000533,-0.000927,-0.000911,-0.000513,-0.000063,0.000096,-0.000108,-0.000427,-0.000516,-0.000233,0.000249,0.000590,0.000576,0.000289,0.000022,0.000029,0.000308,0.000612,0.000670,0.000412,0.000026,-0.000209,-0.000158,0.000066,0.000210,0.000100,-0.000211,-0.000497,-0.000550,-0.000356,-0.000097,0.000011,-0.000103,-0.000311,-0.000402,-0.000267,0.000015,0.000246,0.000277,0.000134,-0.000021,-0.000027,0.000138,0.000342,0.000418,0.000305,0.000094,-0.000052,-0.000039,0.000087,0.000183,0.000138,-0.000036,-0.000218,-0.000281,-0.000199,-0.000064,0.000001,-0.000059,-0.000185,-0.000258,-0.000207,-0.000062,0.000073,0.000108,0.000042,-0.000041,-0.000052,0.000034,0.000154,0.000216,0.000178,0.000078,-0.000001,0.000000,0.000065,0.000123,0.000112,0.000029,-0.000070,-0.000115,-0.000088,-0.000025,0.000008,-0.000019,-0.000085,-0.000133,-0.000121,-0.000058,0.000008,0.000030,0.000004,-0.000036,-0.000045,-0.000008,0.000050,0.000088,0.000080,0.000040,0.000005,0.000004,0.000032,0.000062,0.000063,0.000032,-0.000011,-0.000034,-0.000028,-0.000004,0.000010,0.000000,-0.000027,-0.000049,-0.000050,-0.000029,-0.000005,0.000005,-0.000004,-0.000018,-0.000024,-0.000012,0.000008,0.000023,0.000023,0.000012,0.000001,0.000000};
long i;
long x[652];
unsigned long r1,r2,r3,r01,r02,r03;
void pwm1(unsigned long val1)
{
/*if(val1 <= 1)
{
val1=0;
}
else
val1=val1-1;
*/
TimerMatchSet(TIMER0_BASE, TIMER_A, TimerLoadGet(TIMER0_BASE, TIMER_A)*val1/256);
TimerEnable(TIMER0_BASE, TIMER_A);
}
void pwm2(unsigned long val2)
{
TimerMatchSet(TIMER1_BASE, TIMER_A, TimerLoadGet(TIMER0_BASE, TIMER_A)*val2/256);
TimerEnable(TIMER1_BASE, TIMER_A);
}
void pwm3(unsigned long val3)
{
TimerMatchSet(TIMER2_BASE, TIMER_B, TimerLoadGet(TIMER0_BASE, TIMER_A)*val3/256);
TimerEnable(TIMER2_BASE, TIMER_B);
}
int main(void)
{
/* FIFO Buffer */
unsigned long temp[1];
/*Set the clocking to directly run from the crystal at 8MHz*/
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
/*Enable ADC Peripheral*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//Enable Timers.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
/* Set the clock for the GPIO Port B */
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
/* Set the type of the GPIO Pin */
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_5);
/* UART configuration */
InitConsole();
//Setting the timer for PWM
TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM);
TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
/*Configure ADC Peripheral*/
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
/*Configure ADC Sequence*/
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH5 | ADC_CTL_IE | ADC_CTL_END);
/*Enable ADC sequence*/
ADCSequenceEnable(ADC0_BASE, 3);
/*Clear ADC Interrupt*/
ADCIntClear(ADC0_BASE, 3);
IntMasterEnable();
TimerLoadSet(TIMER2_BASE, TIMER_B, 500);
TimerLoadSet(TIMER1_BASE, TIMER_A, 500);
TimerLoadSet(TIMER0_BASE, TIMER_A, 500);
unsigned long i,k,counter=0,i1=0;
long num1,y=0,num2,num3,j=0,sum1=0,sum2=0,sum3=0;
while(1)
{
for(i=0;i<15648;i++)
{
if(i%24 == 0)
{
ADCProcessorTrigger(ADC0_BASE, 3);
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
ADCIntClear(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, temp);
x[i/24]=temp[0];
}
}
num1=0;
num2=0;
num3=0;
n1=_IQ17(0);
n2=_IQ17(0);
n3=_IQ17(0);
for(k=0;k<652;k++)
{
l1= _IQ17(b1[k]);
l2= _IQ17(b2[k]);
l3= _IQ17(b3[k]);
m= _IQ17(x[651-k]);
n1=n1 + _IQ17mpy(l1,m);
n2=n2 + _IQ17mpy(l2,m);
n3=n3 + _IQ17mpy(l3,m);
}
num1=_IQ17int(n1);
num2=_IQ17int(n2);
num3=_IQ17int(n3);
sum1+=num1*num1;
sum2+=num2*num2;
sum3+=num3*num3;
j++;
if(j==15)
{
sum1=sum1/500;
sum2=sum2/500;
sum3=sum3/500;
r1=isqrt(sum1);
r2=isqrt(sum2);
r3=isqrt(sum3);
sum1=sum2=0;
j=0;
}
r01=r1*r1*r1;
r02=r2*r2*r2;
r03=r3*r3*r3;
if(r01>0)
{
TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
pwm1(256-r01);
}
else
{
TimerConfigure(TIMER0_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC);
}
if(r02>0)
{
TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PWM);
pwm2(256-r02);
}
else
{
TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC);
}
if(r03>0)
{
TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PWM);
pwm3(256-r03);
}
else
{
TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_B_PERIODIC);
}
}
}