/******************************************************************************\
 	


\******************************************************************************/
 
/******************************************************************************\
 Include files
\******************************************************************************/ 
#include "LPC214x.h" 
#include "pll.h" 
#include "vic.h" 
#include "Keys.h"
//#include "armboard3.h"
#include <math.h>
#include "window.h"
#include "adda.h"
#include "sine.h"


/*
		INITIALISATION COMPONENTS
*/

#define BufferSize 1024										// size of the buffer for 
															// cosinus or sinus signal
#define Threshold 10432										// threshold value for vector
	
unsigned int temp = 0;										// temporarily
signed short int FreqStep = 0;								// detection of freq between
															// 1 and 512
unsigned int SignalDetected =0;							// detec freq Y/N
unsigned int SaveInput = 0;										// filling buffer Y/N
unsigned short int BufferPosition = 0;						// position in buffer for data
unsigned short int InputBuffer[BufferSize];				// buffer for the calculated val


extern  void __enable_interrupts(); 
extern  void __disable_interrupts(); 

/******************************************************************************\ 
 convert read keys to usable numbers
\******************************************************************************/
unsigned int Convertkey(unsigned int Keypressed) 

{
	switch(Keypressed)
	{	
		case key_0:	return 0; break;
		case key_1:	return 1; break;
		case key_2: return 2; break;
		case key_3:	return 3; break;
		case key_4: return 4; break;		
		case key_5:	return 5; break;
		case key_6: return 6; break;		
		case key_7:	return 7; break;
		case key_8: return 8; break;	
		case key_9: return 9; break;
		default: return 999; break;
	}

}

/******************************************************************************\
 MyTimerInterrupt
\******************************************************************************/
extern void MyTimerInterrupt()   		// function name used as handle in VicSetup
{
	unsigned int Sample;					// load sample value
	Sample = AD_get();						// read single value of the sample

	if(SaveInput)							// load input buffer
	{
		InputBuffer[BufferPosition] = Sample;	// load sample value into buffer,
												// until next ISR
		if(++BufferPosition == BufferSize)		// 
		{										//when buffer is full dont load at
			SaveInput=0;						// next ISR and
			BufferPosition = 0;					// reset at next ad moment
		}
	}
	if(SignalDetected)
	{
		DACR = (AD_get() << 6);						// signal from input direct to 
	}											// output in 6 bits
	else
	{
		DACR =0;								// Output is zero
	}

// Clear Interrupt flags
	T1IR = 0xFF;
}	
	
 
/******************************************************************************\ 
 Initialize timer 1
 (interrupt source 5) to vic slot 0

\******************************************************************************/
void InitTimer()
{ 
	__disable_interrupts();
	
	// Initialise timer1
	T1TCR = 0;							// stop and reset counter and prescaler
	T1PC  = 2/*div by 2*/ - 1;			// prescale counter
	T1PC = 0;
	T1MR0 = 6000 /*VPBDIV*/;			// max counter value  pwm value (60MHz/10k Interrupts)
	T1MCR = 1<<1 | 1<<0;				// reset and interrupt on match
	T1IR = 0xFF;						// clear interrupt flags
	T1TC = 0;							// clear count value
	VicSetup((unsigned)MyTimerInterrupt,IRQ,5,0); // assign ISR to source and slot
	T1TCR = 1<<0;							// timer 1 go and reset
	VICVectAddr = 0xFF;					// update priority hardware spooling
	
	 __enable_interrupts(); 
}

/******************************************************************************\ 
 main
\******************************************************************************/

// READ VALUE FROM AD CONVERTOR
//unsigned int AD_get(void)
//{
//	unsigned int ingang;
//	AD0CR |= (1 << 24);					// start new conversion
	
//	{
//		ingang = ADOGDR;				// read data of the AD convertor
//	}
//	while (( ingang & 0x80000000)= 0);	// wait for last bit to be written
//	return (ingang >> 6) & 0x03FF;		// shift input for calculation
//}

// Initialise keys
extern int main()
{ 
	unsigned int KeyPressed;			// key input
	unsigned int KeyConversion;			// convert value to normal values
//	unsigned int p;						// counter to prevent jitter during keypressing

// Initialaise buffer

 	signed short MaxValue;				// to determine max vulue input buffer
 	signed short MinValue;				// to determine min value input buffer
 	signed int OffsetValue;					// shift input buffer to correct value
 	float RealPart;					//
 	float ImagPart;					//
 	float Vector;						//
// 	signed int asqr;
//	signed int bsqr;
//	signed int csqr;						// define the value for calcultion
 	
// initialiase counters
 	unsigned int i,j,p;						// 

}
//
// INITIALISATION
//
	AD_init();								//initialisation AD convertor
	DA_init();								//initialisation DA convertor
	PLL_init(); 							// initialisation PLL, proc freq at 60Mc.
	InitTimer();							// init the timers and GO
//	InitKeys();								// initialisation of keys


FreqValue = 64;								// set detec freq
SaveInput = 1;								// start to load input buffer

while(1)
{
	MaxValue = 0;
	MinValue = 1024;
	while(SaveInput);
	
	for (i=0;i<BufferSize;i++)					//determin max/min values zero line
	{
		MaxValue = (InputBuffer[i] > MaxValue) ? InputBuffer[i] : MaxValue;
		MinValue = (InputBuffer[i] < MinValue) ? InputBuffer[i] : MinValue;
	}

// determine zeroline
	OffsetValue = ((MaxValue - MinValue)/2) + MinValue;		// Setup the zeroline with
															// the Offset
	for (i=0;i<BufferSize;i++)								// Shift Value from Input-
															// Buffer to zero
	{
		InputBuffer[i] = InputBuffer[i] - OffsetValue;
	}

// window layed over InputBuffer
	for (i=0;i<BufferSize;i++)
	{
		InputBuffer[i] = Window[i] * InputBuffer[i];
	}
	
// calculation Imaginary
	ImagPart = 0;									//imaginair calc with 'sin'
	j = 0;
	for (i=0;i<BufferSize;i++)
	{
		ImagPart += (SineArray[j]-511) * InputBuffer[i]-511);
		j = (j + FreqValue) % BufferSize;				// pass 1 step depending on 
														// detection freq 
	}	
	ImagPart = ImagPart/1024;
// ImagPart = ImagPart / Buffersize;
	ImagPart = ImagPart/(511*511);

//	ImagPart = (ImagPart / BufferSize)/128;	// value to big for int therfore
														// devide by 128 (2^32)

// calculation Real
	Realpart = 0;
	j = (BufferSize /4) - 1;								// multiply with cos-buffer	
	for (i=0;i<BufferSize;i++)
	{
		Realpart += (SineArray[i]-511) * (InputBuffer[i]-511);
		j = (j + FreqValue) % BufferSize;				// pass 1 step depending on 
														// detection freq 
	}
	RealPart = (RealPart / 1024;
	RealPart = RealPart (511*511);

//	RealPart = (RealPart / BufferSize) /128;			// value to big for int therfore
														// devide by 128 (2^32)
												
// Vector calculation	
	Vector = (unsigned int)((RealPart * RealPart) + (ImagPart * ImagPart));
//
// 	Vector = sqrt((sqr RealPart)+(sgr ImagPart));
// or
//	{
//		asqr = ImagPart * ImagPart;		
//		bsqr = RealPart * RealPart;
//		csqr = asqr + bsqr;
//		Vector = sqrt (csqr);							// Amplitude calclution with
													// pythagoras Theorema	
//	}	
														
// 10& Threshold value
	if(Vector > Threshold)
	{
		SignalDetected = 1;
	}
	else
	{
		SignalDetected = 0;
	}
	
// Key action
	InitKeys();
	KeyPressed = ReadKeys();			// read key value from keys.c
	p = 100000							// prevent jittering of the switch
	while (p--);
	if(KeyPressed)		
	{
		InitKeys();
		KeyConversion =  ConvertKey(KeyPressed);
		if(KeyConversion 1 = 999)					//	
		{
			temp = (temp *10) + KeyConversion;
			KeyConversion = 0;
		}

		
		if(KeyConversion == 999 || temp >512 || temp < 1)
		{
			if(temp < 1 )
			{
				temp = 1;
			}
			else if(temp > 512)
			{
				temp = 512;
			}
			FreqValue = temp;					// store key value in temp
			temp = 0;							// reset value for new value
		}
		while(1)
		{
			If(!ReadKeys())
			{
				i++;
			}
			else
			{
				i = 0;
			}
			if(i==100)							// max of 100 samples
			{
				break;
			}
		}
		SignalDetected = 0;
		SaveInput = 1;
		}

	


	}
	return 0;										// don't ever come near this
}

Most of them are errors with same declaration in an other file it was working but strange now its not. Can someone advice. I work with PsPad
With the above code I have issue to solve the following errors, mainly I like to have advice at the repeating fault errors.

Thanks:

main.c:160: warning: unused variable 'p'
main.c:160: warning: unused variable 'j'
main.c:160: warning: unused variable 'i'
main.c:154: warning: unused variable 'Vector'
main.c:153: warning: unused variable 'ImagPart'
main.c:152: warning: unused variable 'RealPart'
main.c:151: warning: unused variable 'OffsetValue'
main.c:150: warning: unused variable 'MinValue'
main.c:149: warning: unused variable 'MaxValue'
main.c:144: warning: unused variable 'KeyConversion'
main.c:143: warning: unused variable 'KeyPressed'
main.c:162: warning: control reaches end of non-void function
main.c: At top level:
main.c:166: warning: data definition has no type or storage class
main.c:166: warning: type defaults to 'int' in declaration of 'AD_init'
main.c:166: error: conflicting types for 'AD_init'
adda.h:19: error: previous declaration of 'AD_init' was here
main.c:167: warning: data definition has no type or storage class
main.c:167: warning: type defaults to 'int' in declaration of 'DA_init'
main.c:167: error: conflicting types for 'DA_init'
adda.h:20: error: previous declaration of 'DA_init' was here
main.c:168: warning: data definition has no type or storage class
main.c:168: warning: type defaults to 'int' in declaration of 'PLL_init'
main.c:168: error: conflicting types for 'PLL_init'
pll.h:14: error: previous declaration of 'PLL_init' was here
main.c:169: warning: data definition has no type or storage class
main.c:169: warning: type defaults to 'int' in declaration of 'InitTimer'
main.c:169: error: conflicting types for 'InitTimer'
main.c:105: error: previous definition of 'InitTimer' was here
main.c:173: warning: data definition has no type or storage class
main.c:173: warning: type defaults to 'int' in declaration of 'FreqValue'
main.c:174: warning: data definition has no type or storage class
main.c:174: warning: type defaults to 'int' in declaration of 'SaveInput'
main.c:174: error: conflicting types for 'SaveInput'
main.c:36: error: previous definition of 'SaveInput' was here
main.c:149: warning: unused variable 'MaxValue'
main.c:144: warning: unused variable 'KeyConversion'
main.c:143: warning: unused variable 'KeyPressed'
main.c:162: warning: control reaches end of non-void function
main.c: At top level:
main.c:166: warning: data definition has no type or storage class
main.c:166: warning: type defaults to 'int' in declaration of 'AD_init'
main.c:166: error: conflicting types for 'AD_init'
adda.h:19: error: previous declaration of 'AD_init' was here
main.c:167: warning: data definition has no type or storage class
main.c:167: warning: type defaults to 'int' in declaration of 'DA_init'
main.c:167: error: conflicting types for 'DA_init'
adda.h:20: error: previous declaration of 'DA_init' was here
main.c:168: warning: data definition has no type or storage class
main.c:168: warning: type defaults to 'int' in declaration of 'PLL_init'
main.c:168: error: conflicting types for 'PLL_init'
pll.h:14: error: previous declaration of 'PLL_init' was here
main.c:169: warning: data definition has no type or storage class
main.c:169: warning: type defaults to 'int' in declaration of 'InitTimer'
main.c:169: error: conflicting types for 'InitTimer'
main.c:105: error: previous definition of 'InitTimer' was here
main.c:173: warning: data definition has no type or storage class
main.c:173: warning: type defaults to 'int' in declaration of 'FreqValue'
main.c:174: warning: data definition has no type or storage class
main.c:174: warning: type defaults to 'int' in declaration of 'SaveInput'
main.c:174: error: conflicting types for 'SaveInput'
main.c:36: error: previous definition of 'SaveInput' was here

Edited 4 Years Ago by Narue: added code tags

There is a loose closing bracket at line 159. Every function invocation you did was considered as a declaration and was conflicting with the previous function declarations. Perhaps the original function declarations were of void return type and the compiler was using the implicit return type: int. Either way, removing that might fix it.

Is there a question?
Always start with the first error.
If there is some un unused code you have that you will need later but it's causing a problem now, comment it out and re-compile.

This article has been dead for over six months. Start a new discussion instead.