This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Keil u vision and code composer studio with lm3s8962

Hi Community,

I have a set of FFT codes that is suppose to create an array of number after processing the incoming signal.

When I build my codes in code composer studio it was successfully built.

However, when I run it on debug mode it face problems.

The purpose of my project is to simply program a set of FFT algorithm in c, and allow my LM3s8962 micro-controller to process the incoming signal(Voice or sound).

I have another question, can I use the algorithm to run it in my keil uvision, since the keil uvision has the spectrum/logic analyser which I can see the frequency spectrum.

I will attach my algorithms here, if any kind hearted soul spot any mistakes in my algorithm please enlighten me.

/*
* main.c
*/
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "grlib/grLib.h"
#include "grlib/grLibDriver.h"

short sample[8];

#pragma vector=unused_interrupts
interrupt void user_trap_function(void)  //ISR to handle the end of sampling interrup, being the only enabled interrupt
{
int df = 15625;      //fs/N = 125000/8
int Re[8];
int Im[8];
int Ampl[8];
int fr[8];
int N = 8;        //number of samples
x[N] = (short)sample;    // convert sample values to short integers for computation
int out[2] = {0,0};      //init Re and Im results
int j=0;
for (j = 0; j < N; j++){
  dft(x,j,out);       //call DFT function
  Re[j] = out[0];
  Im[j] = out[1];      //collect real and imaginary parts
  Ampl[j] = ((Re[j]^2)+(Im[j]^2))^(1/2);
  fr[j] = df*j;

  long lX1 = (long)Ampl[j];
  long lX2 = (long)Ampl[j]+1;
  long lY = (long)fr[j];
  long ulValue = 128;

  void LineDrawH (pvDisplayData, lX1, , lX1, lY, ulValue);

}


}

int M = 0;
unsigned long sample[8]

void LineDrawH (void *pvDisplayData, long lX1, long lX2, long lY, unsigned long ulValue);

void ADC_init( void ) {
  SYSCTL_RCGC0_R |= SYSCTL_RCGC0_ADC;            // Enable the clock to the ADC module
  SYSCTL_RCGC0_R |= SYSCTL_RCGC0_ADCSPD125K;       // Configure the ADC to sample at 125KS/s
  ADCSequenceDisable(ADC_BASE, 0);             // Disable sample sequences 0
  ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 1);  // Configure sample sequence 0: processor trigger, priority = 1
  IntPrioritySet(INT_ADC0SS0,0);             // Set SS0 interrupt priority to 0
  ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH0);  // Configure sample sequence 0 to sample external input
  ADCSequenceStepConfigure(ADC_BASE, 0, 1, ADC_CTL_CH0);
  ADCSequenceStepConfigure(ADC_BASE, 0, 2, ADC_CTL_CH0);
  ADCSequenceStepConfigure(ADC_BASE, 0, 3, ADC_CTL_CH0);
  ADCSequenceStepConfigure(ADC_BASE, 0, 4, ADC_CTL_CH0);
  ADCSequenceStepConfigure(ADC_BASE, 0, 5, ADC_CTL_CH0);
  ADCSequenceStepConfigure(ADC_BASE, 0, 6, ADC_CTL_CH0);
  ADCSequenceStepConfigure(ADC_BASE, 0, 7, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); //set interrupt flag after the seventh step
  ADCIntEnable(ADC_BASE, 0);         // Enable the interrupt for sample sequence 0
  IntEnable(INT_ADC0SS0);                   // Enable SS0 Interupt in NVIC
  M+=M;               // integer to detect if ADC is initialized
}

unsigned long getADC0(void)
{

ADCProcessorTrigger(ADC0_BASE, 0);     //initiate sampling
while(!ADCIntStatus(ADC0_BASE, 0, false));   //monitor interrupt flag for completion of sampling
ADCSequenceDataGet(ADC0_BASE, 0, sample);  //assign samples to global variable, sample

return sample;         //return sample to calling function
}

int dft(long *x, short k, int *out)   //DFT function
{
  int sumRe = 0;       //init real component
  int sumIm = 0;      //init imaginary component
  int i = 0;
  int N = 8;
  float pi = 3.1416 ;
  float cs = 0;       //init cosine component
  float sn = 0;       //init sine component
  for (i = 0; i < N; i++)    //for N-point DFT
   {
   cs = cos(2*pi*(k)*i/N);   //real component
   sn = sin(2*pi*(k)*i/N);   //imaginary component
   sumRe += x[i]*cs;     //sum of real components
   sumIm -= x[i]*sn;     //sum of imaginary components
   }
  out[0] = sumRe;      //sum of real components
  out[1] = sumIm;      //sum of imaginary components

  return(out);
}
int main(void) {
if (M>0){
  ADC_init();       //initialize ADC module if not already initialized
}
getADC0();        //start conversion. Interrupt flag will be set after sampling and this functioned called again after ISR executes

return 0;
}

Parents
  • I am looking for a set of fft realistic algorithm that I can use it for my project. I am trying to come out by myself, as you can see there are just too many errors haha.

    With little more familiarity and experience with C, you will be able to make your DFT work.

    My professor kept saying, there is already available online. But I cannot find it.

    If you want a black box FFT (when you don't have to be concerned about the details on how it works, you just need to know how to use it), the CMSIS DSP Software Library is the answer to your problem.

    Visit these pages from Texas Instruments and try if you can find the FFT functions that you need from the software packages:

    The CMSIS DSP Software Library from KEIL can be found here, CMSIS DSP Software Library.

    If you are required to show the code of the FFT, you can find an example or template from textbooks, application notes from MPU/MCU/DSP suppliers, or from online articles. You need to port these codes to the LM3S8962.

    Also, there are just too many different kinds of fft algorithms out there. Which one is the right one?

    The differences exist because the FFT algorithms

    • are written for different platforms some FFTs are for DSPs, some are for microcontrollers, some are for general-purpose computers such as the PC.
    • can be decimation-in-time or decimation-in-frequency.
    • can support various radices, 2, 4, 8, 3, 5, split-radix, mixed-radix.
    • can be written for the general case when the input samples are complex numbers or they can be optimized for real input data.

    All of these will produce practically the same result for the same input, they will differ in speed, size, overall efficiency and suitability to a particular problem. You don't have to be concerned about these in the meantime. If you want a simpler version, look for these in the description: radix-2, decimation-in-time, floating-point.

Reply
  • I am looking for a set of fft realistic algorithm that I can use it for my project. I am trying to come out by myself, as you can see there are just too many errors haha.

    With little more familiarity and experience with C, you will be able to make your DFT work.

    My professor kept saying, there is already available online. But I cannot find it.

    If you want a black box FFT (when you don't have to be concerned about the details on how it works, you just need to know how to use it), the CMSIS DSP Software Library is the answer to your problem.

    Visit these pages from Texas Instruments and try if you can find the FFT functions that you need from the software packages:

    The CMSIS DSP Software Library from KEIL can be found here, CMSIS DSP Software Library.

    If you are required to show the code of the FFT, you can find an example or template from textbooks, application notes from MPU/MCU/DSP suppliers, or from online articles. You need to port these codes to the LM3S8962.

    Also, there are just too many different kinds of fft algorithms out there. Which one is the right one?

    The differences exist because the FFT algorithms

    • are written for different platforms some FFTs are for DSPs, some are for microcontrollers, some are for general-purpose computers such as the PC.
    • can be decimation-in-time or decimation-in-frequency.
    • can support various radices, 2, 4, 8, 3, 5, split-radix, mixed-radix.
    • can be written for the general case when the input samples are complex numbers or they can be optimized for real input data.

    All of these will produce practically the same result for the same input, they will differ in speed, size, overall efficiency and suitability to a particular problem. You don't have to be concerned about these in the meantime. If you want a simpler version, look for these in the description: radix-2, decimation-in-time, floating-point.

Children
No data