How can I to implement the FFT using an ADC?

Thread Starter

reyes33d88

Joined Jan 10, 2015
7
Hello guys, I need to convert one analog signal to digital signal, I done this point, but now I have to process this signal, I need to apply the FFT to this digital signal, but I don´t know how to do it?, does somebody could help me?, the code is shown next
Code:
#include <p33FJ12GP202.h>
_FOSC ( FCKSM_CSDCMD & IOL1WAY_OFF & OSCIOFNC_OFF & POSCMD_XT );
//#define _XTAL_FREQ 16000000
#define fcy 16000000


int main (void);
void atraso_ms();
void inicia_adc(void);

/////////////////INICIO DEL PROGRAMA////////////
int main (void)
{
    TRISB=0X0000;
    inicia_adc();
    AD1CON1bits.ADON=1;        //SE HABILITA EL ADC
while(1)
{
    AD1CON1bits.SAMP=1;///INICIA EL MUESTREO
    atraso_ms(3);///TIEMPO EN EL QUE SE REALIZA EL MUESTREO
    AD1CON1bits.SAMP=0;///RETIENE EL DATO
while(!AD1CON1bits.DONE); //MIENTRAS SE REALIZE LA CONVERSIÓN, LOS DATOS SE GUARDAN EN EL PUERTO B
PORTB=ADC1BUF0; // Datos se guardan en ADC1BUF0 y se envía al puerto B

}
}
void inicia_adc(void)
{
///////DEFINIMOS LA ENTRADA (RA0), LOS BITS DEL ADC Y SE CONFIGURA SOLO ADCON 1/////////////
    TRISA=0X0001;    //ENTRADA POR RA0
    AD1PCFGL=0X0000;        //ENTRADAS ANALÓGICAS
    AD1CON1bits.AD12B=1;//ADC DE 12 BITS}
    //AD1CON1bits.ADSIDL=0;
    //AD1CON1bits.FORM=0;
    AD1CON1bits.ASAM=0;///EL MUESTRO INICIA DESPUÉS DE LA ÚLTIMA CONVERSIÓN
    AD1CON1bits.SSRC=0b111;///TERMINA EL MUESTREO


////////////CONFIGURACIÓN AD1CON2//////////////
    AD1CON2bits.VCFG=0b00;///VDD Y VSS
    AD1CON2bits.CSCNA=0;//MUESTREO SECUENCIAL DESHABILITADO
    AD1CON2bits.SMPI=0b111;//DETERMINA LA CANTIDAD DE MUESTRAS (EN ESTE CASO 16)7
    AD1CON2bits.BUFM=0;//SIEMPRE SE LLENA EL BUFFER DESDE EL PRINCIPIO
    AD1CON2bits.ALTS=0;//SIEMPRE SE UTILIZA LA ENTRADA DE CANAL, PARA EL MUESTREO A
////////////CONFIGURACIÓN AD1CON3//////////////

    AD1CON3bits.ADRC=1;//SE SELECCIONA EL RELOJ INTERNO
    AD1CON3bits.ADRC=21;//TIEMPO DE CONVERSIÓN
    AD1CON3bits.SAMC=0b11111;//BITS DE AUTO MUESTREO
    AD1CON3bits.ADCS=0b11111;//TIEMPO DE CONVERSIÓN DE BITS ADC
////////////CONFIGURACIÓN AD1CHS0://////////////
    AD1CHS0bits.CH0NA=0;//ENTRADA NEGATIVA POR VSS
    AD1CHS0bits.CH0SA=0;//ENTRADA POSITIVA POR AN
}
/////////////CONFIGURACIÓN DEL RETARDO//////////////////////
void atraso_ms(){
T1CON= 0;
TMR1=0;//INICIAMOS RESETEANDO EL TIMER 1
IPC0bits.T1IP=0b101;//LA INTERRUPCIÓN TIENE UNA PRIORIDAD 5
    /////////////OSCILADOR DE 20MHz///////////////////////////////////////////
    ////////TCY=4/16MHz = 1/4us///////////////////////////////////////////////
    //////PARA UN RETARDO DE 1s SE CARGA A PR1 CON  39062.5///////////////////
    //////////////////////////////////////////////////////////////////////////
    //////FCY=20MHz/2=10MHz, PREESCALAR DE 256////////////////////////////////
    //////POR REGLA DE 3, PARA UN RETARDO DE 1ms, PR1=39.0625/////////////////
    PR1=39.0625;
    IFS0bits.T1IF=0;//LIMNPIA LA BANDERA DEL TIMER
    IEC0bits.T1IE=0;//CUANDO OCURRE UNA INTERRUPCIÓN DESHABILITA EL TIMER
    T1CON=0X8030;//CONFIGURA T1CON
while(IFS0bits.T1IF==0);
}
 

MrChips

Joined Oct 2, 2009
30,821
Before you start to consider doing FFT, state your specifications.

Number of bits =
Sampling rate =
Number of samples =

FFT max frequency required =
FFT resolution required =

How much RAM is available on your MCU?
How much flash (code) is available?

Then you need code to perform the FFT. You can find this on the internet.
 

Thread Starter

reyes33d88

Joined Jan 10, 2015
7
thank you for replayit, I have some answers

Number of bits = 32
Sampling rate =100 KHz
Number of samples = 56

FFT max frequency required = xxx
FFT resolution required =xxx

do you have some example?
 

MrChips

Joined Oct 2, 2009
30,821
There is no 32-bit ADC that I am aware of.
Number of samples should be a power of 2. For example, 64, 128 or 256.

FFT code are available open source on the Internet.
 
Top