Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

two dimension array problem

Status
Not open for further replies.

swapan

Full Member level 4
Joined
Feb 20, 2009
Messages
199
Helped
27
Reputation
54
Reaction score
24
Trophy points
1,298
Location
Kolkata
Activity points
2,806
Hi guys,
With a view to modulate the width of pulse of a sine wave inverter to get stable output I took 14 sets of values (each set consisting 32 values for 180 degree cycle. Depending upon sample output voltage the sine values will be obtained from corresponding sets. I have derived 14 sets of sine values for 65% to 100% duty cycles. But the code does not built. Please see the code and the error report.

Code:
const unsigned char table[13][31]={
{0, 20, 40, 59, 78, 96, 113, 129, 144, 157, 169, 179, 188, 194, 199, 202, 203, 202, 199, 194, 188, 179, 169, 157, 144, 129, 113, 96, 78, 59, 40, 20}, //67.5%
{0, 20, 40, 60, 79, 98, 115, 131, 146, 160, 172, 183, 191, 198, 203, 206, 207, 206, 203, 198, 191, 183, 172, 160, 146, 131, 115, 98, 79, 60, 40, 20}, //70%
{0, 21, 41, 61, 80, 99, 117, 133, 148, 162, 175, 185, 194, 201, 206, 209, 210, 209, 206, 201, 194, 185, 175, 162, 148, 133, 117, 99, 80, 61, 41, 21}, //72.5%
{0, 21, 42, 62, 82, 100, 118, 135, 151, 165, 177, 188, 197, 204, 209, 212, 213, 212, 209, 204, 197, 188, 177, 165, 151, 135, 118, 100, 82, 62, 42, 21}, //75%
{0, 21, 42, 63, 83, 102, 121, 138, 153, 168, 180, 191, 200, 208, 213, 216, 217, 216, 213, 208, 200, 191, 180, 168, 153, 138, 121, 102, 83, 63, 42, 21}, //77.5%
{0, 22, 43, 64, 84, 104, 122, 140, 156, 170, 183, 194, 203, 211, 216, 219, 220, 219, 216, 211, 203, 194, 183, 170, 156, 140, 122, 104, 84, 64, 43, 22}, //80%
{0, 22, 44, 65, 86, 106, 124, 142, 158, 173, 186, 198, 207, 214, 220, 223, 224, 223, 220, 214, 207, 198, 186, 173, 158, 142, 124, 106, 86, 65, 44, 22}, //82.5%
{0, 22, 44, 66, 87, 107, 126, 144, 161, 175, 189, 200, 210, 217, 223, 226, 227, 226, 223, 217, 210, 200, 189, 175, 161, 144, 126, 107, 87, 66, 44, 22}, //85
{0, 23, 45, 67, 88, 109, 128, 147, 163, 179, 192, 204, 213, 221, 227, 230, 231, 230, 227, 221, 213, 204, 192, 179, 163, 147, 128, 109, 88, 67, 45, 23}, //87.5%
{0, 23, 46, 68, 90, 110, 130, 148, 165, 181, 195, 206, 216, 224, 230, 233, 234, 233, 230, 224, 216, 206, 195, 181, 165, 148, 130, 110, 90, 68, 46, 23}, //90%
{0, 23, 46, 69, 91, 112, 132, 151, 168, 184, 198, 210, 220, 228, 233, 237, 238, 237, 233, 228, 220, 210, 198, 184, 168, 151, 132, 112, 91, 69, 46, 23}, //92.5%
{0, 24, 47, 71, 93, 115, 135, 154, 172, 188, 202, 214, 225, 233, 238, 242, 243, 242, 238, 233, 225, 214, 202, 188, 172, 154, 135, 115, 93, 71, 47, 24}, // 95%
{0, 24, 48, 72, 95, 117, 138, 157, 175, 192, 206, 219, 229, 237, 243, 247, 248, 247, 243, 237, 229, 219, 206, 192, 175, 157, 138, 117, 95, 72, 48, 24} //98%
};


The error message is as under

30 389 Too many initializers of subaggregate SINEWAVE_TWO_DIMENSION.c


30 325 Too many initializers
 

You declare two dimensions array, but trying to assign single one.
const unsigned char table[][] = {{ 0,1,2,3,4 }, {0,1,2,3,4},{0,1,2,3,4}};
 

Thanks Easyrider83. I could not got the point please. Also I cannot detect what is difference between your example and that of my code. A little bit detail requested.
 

You may be exceeding the number of elements 31 i suppose.
 

Must be const unsigned char table[13][32]

each row has 32 elements.
 

I have tried using const unsigned char table [13][32] = { } Still the same error message was returned while building the code.
 

If you define AND initialize array in one line you don't have to put the array size in the definition as Easyrider83 suggested. The array size will be calculated during compilation.
But if you don't initialize array elements in the definition line, you must explicitly write array size.
 

Still the same error message was returned while building the code.
Sounds unlikely. Original constant array works e.g. with XC8 after correcting the array size to [13][32].

- - - Updated - - -

If you define AND initialize array in one line you don't have to put the array size in the definition as Easyrider83 suggested.

Not generally accepted for multi-dimensional arrays. Often only the outermost dimension (13 in this case) can be omitted.
 

How much effort needed to calculate amount of elements in array? Correct size of const unsigned char table[13][32]
 

Thanks everybody for their valuable comments and assistance. Finally the problem is fixed. In the code, I wrongly wrote one dimension instead of two. Now the code builds successfully.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top