cancel
Showing results for 
Search instead for 
Did you mean: 

Summing elements in an array

Posted on August 20, 2008 at 06:00

Summing elements in an array

5 REPLIES 5
Posted on August 15, 2008 at 12:54

micro: ST7FLITE39

c compiler: cosmic 16k 4.5.7

IDE: ST Visual Developer 4.0.1

Hi,

I'm setting up an interrupt routine to populate an array, and then calculate the sum of the elements of the array as part of an RMS algorithm. I've put together some test code and got the interrupt working. The interrupt code fills the 10 elements of the array with some long integers, and now I want to sum the values in the array. This should only be a trivial operation, but I cannot get the code to compile. I keep getting the following error:

#error clnk Debug\st7 - 3.lkf:1 symbol c_xladd not defined (Debug\interrupt_vector.o )

I think the ''c_xladd'' is referring to the ''c_ladd'' function for adding two long integers, but I've tested the addition of two integers by adding two long integer variables. I only get the compile errors when I try to add two or more elements of the array.

Here's my code:

@interrupt void Timer2OverFlow(void)

{

unsigned long int voltages[10];

unsigned long int num1, num2, total = 0;

unsigned char loop_counter = 0;

unsigned int feedback_voltage = 0;

for (loop_counter = 0; loop_counter < 10; loop_counter++)

{

feedback_voltage = 1024;

voltages[loop_counter] = squared(feedback_voltage);

}

num1 = 1000000;

num2 = 1000000;

total = num1 + num2; // This addition works

//total = voltages[1] + voltages[2]; // when this is uncommented

// the code will no longer compile

// see the above error message

ClrBit(LTCSR2, LTCSR2_TB2F);

return;

}

Does anybody have any idea where I'm going wrong?

luca239955_st
Associate III
Posted on August 18, 2008 at 07:23

you are probably not linking the long/float library; post the linker file here if you want me to check.

Regards,

Luca (Cosmic)

Posted on August 19, 2008 at 07:28

Hi Luca,

Thanks for the reply. I think this is the linker file (.lkf):

# LINK COMMAND FILE AUTOMATICALLY GENERATED BY STVD7

# SHOULD NOT BE MANUALLY MODIFIED

#

# Put you segment configuration here

# define the .share segment when using compact or memory models only

#

# Segment Code,Constants:

+seg .text -b 0xe000 -m 0x2000 -n .text

+seg .const -a .text -n .const

# Segment Eeprom:

+seg .eeprom -b 0x1000 -m 0x100 -n .eeprom

# Segment Zero Page:

+seg .bsct -b 0x80 -m 0x80 -n .bsct

+seg .ubsct -a .bsct -n .ubsct

+seg .share -a .ubsct -n .share -is

# Segment Ram:

+seg .data -b 0x100 -m 0x80 -n .data

+seg .bss -a .data -n .bss

#

# Put you startup file here (it depends on the model used)

#

crtsx.st7

#

# Put your object files here (they depend on you application)

#

Debug\adc.o

Debug\initialise_io.o

Debug\main.o

Debug\rms_calcs.o

Debug\rs232.o

Debug\timers_and_clock.o

#

# Put your library name here (it depends on the model used)

#

libfsl.st7

libisl.st7

libm.st7

#

# Put your interrupt vectors file here if needed

#

+seg .const -b 0xffe0 -k

Debug\interrupt_vector.o

#

#

+def __endzp=@.ubsct # end of uninitialized zpage

+def __memory=@.bss # end of bss segment

+def __stack=0x1ff

#

I've set the memory model to long stack, and linked in the floating point long stack (libfsl.st7) and the integer long stack (libisl.st7) libraries, but maybe I'm missing something else.

Thanks,

Steve.

luca239955_st
Associate III
Posted on August 20, 2008 at 05:45

the probem comes from the fact that you link the libraries *before* the object Debug\interrupt_vector.o.

Either you change the order of the lines in your linker file or (suggested) you leave only the interrupt vectors in Debug\interrupt_vector.o and you move the interrupt functions in another module (that, of course, will be linked before the libraries).

Regards,

Luca (Cosmic)

luca239955_st
Associate III
Posted on August 20, 2008 at 06:00

on a side note, keep in mind that you might need to use the @svlreg keyword on your interrupt functions when you use long in there. In your code this is automatic, but if you call a fct in the interrupt (instead of doing the calculations directly inside the interrupt routine, as in your example), you will need to do that manually.

Hope it helps.

Luca