Beispiel #1
0
extern void ADCA_Process(void){
	static int i = 0;
	ServiceDog();

	if(cont == 0)
		i = 0;

	if(cont<(N<<1)){
		x1[cont] = (float)(ADC_RESULT_PTR[ADCA]->ADCRESULT2*3.3/4096)-1.5;    // Parte real
		x1[cont+1] = 0.0f;  // Parte imaginiaria
		x[i] = x1[cont];
		x2[cont] = (float)(ADC_RESULT_PTR[ADCA]->ADCRESULT3*3.3/4096)-1.5;    // Parte real
		x2[cont+1] = 0.0f;  // Parte imaginiaria

		x3[cont] = (float)(ADC_RESULT_PTR[ADCA]->ADCRESULT4*3.3/4096)-1.5;    // Parte real
		x3[cont+1] = 0.0f;  // Parte imaginiaria

		cont=cont+2;
		i++;
	}
}
void main(void)
{
//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xS_SysCtrl.c file.
//
    InitSysCtrl();

//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xS_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
// InitGpio();

//
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
    DINT;

//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xS_PieCtrl.c file.
//
    InitPieCtrl();

//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
    IER = 0x0000;
    IFR = 0x0000;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in F2837xS_DefaultIsr.c.
// This function is found in F2837xS_PieVect.c.
//
    InitPieVectTable();

//
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
//
    EALLOW;  // This is needed to write to EALLOW protected registers
    PieVectTable.WAKE_INT = &wakeint_isr;
    EDIS;    // This is needed to disable write to EALLOW protected registers

//
// Step 4. User specific code, enable interrupts:
// Clear the counters
//
    WakeCount = 0; // Count interrupts
    LoopCount = 0; // Count times through idle loop

//
// Connect the watchdog to the WAKEINT interrupt of the PIE
// Write to the whole SCSR register to avoid clearing WDOVERRIDE bit
//
    EALLOW;
    WdRegs.SCSR.all = C28X_BIT1;
    EDIS;

//
// Enable WAKEINT in the PIE: Group 1 interrupt 8
// Enable INT1 which is connected to WAKEINT:
//
    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
    PieCtrlRegs.PIEIER1.bit.INTx8 = 1;   // Enable PIE Group 1 INT8
    IER |= M_INT1;                       // Enable CPU INT1
    EINT;                                // Enable Global Interrupts

//
// Reset the watchdog counter
//
    ServiceDog();

//
// Enable the watchdog
//
    EALLOW;
    WdRegs.WDCR.all = 0x0028;
    EDIS;

//
// Step 6. IDLE loop. Just sit and loop forever (optional):
//
    for(;;)
    {
        LoopCount++;

        //
        // Uncomment ServiceDog to just loop here
        // Comment ServiceDog to take the WAKEINT instead
        //
        // ServiceDog();
    }
}
Beispiel #3
0
int main(void){

	float Es,E;
	unsigned int i, j;
	unsigned int doa_aux[3];
	int diff[3];

#ifdef _FLASH
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif


	/*------------------------------------------------------*/
	/*                   Inicialización                     */
	/*------------------------------------------------------*/
    InitSysCtrl();
    InitSysPll(XTAL_OSC,IMULT_20,FMULT_0,PLLCLK_BY_2);
    EDIS;
    InitGpio();
    InitPieCtrl();

    IER = 0x0000;
    IFR = 0x0000;

    InitPieVectTable();

    //Configura operación del ADC-A
    ADC_Configure(ADCA,16000);

    //Configura los canales 2,3,4 y 5 del ADC-A
    ADC_Init(ADCA, 2);
    ADC_Init(ADCA, 3);
    ADC_Init(ADCA, 4);

    //La interrupción del ADC-A se da cuando termine el canal 4
    ADC_Int(ADCA, 4);


    hnd_cfft->OutPtr  = CFFToutBuff;  // Apuntador al Buffer de salida
    hnd_cfft->Stages  = STAGE;  // Número de etapas de la FFT
    hnd_cfft->FFTSize = N;    // Tamaño de la FFT

    hnd_cfft->CoefPtr = CFFTF32Coef;  // Auntador a los coeficientes de Fourier
    CFFT_f32_sincostable(hnd_cfft);   // Calcula los factores de Fourier


    //Configura el puerto serial
    Serial_Init();
	Serial_Configure(BR9600);
	Serial_Start();

	ADC_Start(ADCA);   //Inicia la conversión del ADC-A
	cont = 0;

    //calculo de la energía del silencio (que filosófico suena esto)
	EINT;
	Es = 0;
	while(cont<(N<<1));
	ServiceDog();
	cont = 0;
	Es = energy(x);
	while(cont<(N<<1));
	ServiceDog();
	cont = 0;
	Es += energy(x);
	Es = Es/2;
	doaG = 0;

	while(1){

#ifndef DEBUG
		init = false;
		while(!init);
#endif
		E = Es;
		for(j=0;j<3;j++){

			//recibe datos y verifica si es ruido o no
			do{
				ADC_Start(ADCA);
				while(cont<(N<<1));
				cont = 0;    	//Una vez llenos los buffers de datos procedemos a realizar el algoritmo
				ADC_Stop(ADCA); //detiene la adquisición para obtener las FFT
				ServiceDog();
			}while(!vad(x,E));


			//FFT mic 1
			hnd_cfft->InPtr = x1;
			CFFT_f32u(hnd_cfft);
			for(i=0;i<(N<<1);i++){
				xw1[i] = hnd_cfft->CurrentInPtr[i];
			}

			//FFT mic 2
			hnd_cfft->InPtr = x2;
			CFFT_f32u(hnd_cfft);
			for(i=0;i<(N<<1);i++){
				xw2[i] = hnd_cfft->CurrentInPtr[i];
			}

			//FFT mic 3
			hnd_cfft->InPtr = x3;
			CFFT_f32u(hnd_cfft);
			for(i=0;i<(N<<1);i++){
				xw3[i] = hnd_cfft->CurrentInPtr[i];
			}

			ServiceDog();

			doa_aux[j]  = doa_est(xw1,xw2,xw3,30); //50
			//doaG +=doa_aux[j];


			DELAY_US(100000); //retraso de 100ms
			ServiceDog();
			E = 0.8*E;

		}//for j

		diff[0] = doa_aux[0]-doa_aux[1]; //diferencia entre primer y segundo frame
		diff[1] = doa_aux[1]-doa_aux[2]; //diferencia entre segundo y tercer frame
		diff[2] = doa_aux[0]-doa_aux[2]; //diferencia entre primer y tercer frame


		if(diff[0]<0)
			diff[0] = -diff[0];
		if(diff[1]<0)
			diff[1] = -diff[1];
		if(diff[2]<0)
			diff[2] = -diff[2];

		if( diff[0]<=diff[1] && diff[0]<=diff[2] )
			doaG = (doa_aux[0]+doa_aux[1])>>1;
		else if ( diff[1]<=diff[0] && diff[1]<=diff[2] )
			doaG = (doa_aux[1]+doa_aux[2])>>1;
		else