This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28379D: How Can I take Square Root For Array Data?

Part Number: TMS320F28379D


Tool/software: Code Composer Studio

I'm using TMS320F28379D with Code Composer Studio.

'2837x_RFFT_ADC' project is used.

I want to take square root of data in 'RFFTmagBuff'. So, I built 'RFFTsqrtBuff' in 'main.c', and I think I have some mistake, but I cannot find it.

Please help me how to do it!

Here is my main.c code

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include "fpu_rfft.h" // Main include file

#include "math.h"

#include "examples_setup.h"

#include "F2837xD_device.h"

#define RFFT_STAGES 11 //9

#define RFFT_SIZE (1 << RFFT_STAGES)

#define F_PER_SAMPLE (ADC_SAMPLING_FREQ/(float)RFFT_SIZE)

#pragma DATA_SECTION(RFFTin1Buff,"RFFTdata1")

uint16_t RFFTin1Buff[2*RFFT_SIZE];

#pragma DATA_SECTION(RFFTmagBuff,"RFFTdata2")

float RFFTmagBuff[RFFT_SIZE]; // /2+1

#pragma DATA_SECTION(RFFToutBuff,"RFFTdata3")

float RFFToutBuff[RFFT_SIZE];

#pragma DATA_SECTION(RFFTF32Coef,"RFFTdata4")

float RFFTF32Coef[RFFT_SIZE];

RFFT_ADC_F32_STRUCT rfft_adc;

RFFT_ADC_F32_STRUCT_Handle hnd_rfft_adc = &rfft_adc; // & Bit Operator

RFFT_F32_STRUCT rfft;

RFFT_F32_STRUCT_Handle hnd_rfft = &rfft;

volatile uint16_t flagInputReady = 0;

volatile uint16_t sampleIndex = 0;

uint16_t pass = 0;

uint16_t fail = 0;

__interrupt void adcaIsr();

int16_t main(void)

{ // Locals

uint16_t i, j;

float freq = 0.0;

float freq1 = 0.0;

float RFFTsqrtBuff[RFFT_SIZE];

#ifdef FLASH

EALLOW;

Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0;

memcpy((uint32_t *)&RamfuncsRunStart, (uint32_t *)&RamfuncsLoadStart, (uint32_t)&RamfuncsLoadSize );

FPU_initFlash();

#endif // FLASH

FPU_initSystemClocks();

FPU_initEpie(); // Setup ADC-A

FPU_initADCA();

FPU_initEPWM(); // Setup EPWM1A as the sampling clock, EPWM2A as the signal to be sampled

EALLOW; // Map ISR functions

PieVectTable.ADCA1_INT = &adcaIsr; // Function for ADCA interrupt 1

EDIS; // Enable Global Interrupts and Higher Priority Real-Time Debug Events:

PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable ADC1INT

IER |= M_INT1; // Enable group 1 interrupts

EINT; // Enable Global interrupt INTM

ERTM; // Enable Global real time interrupt DBGM

FPU_startEPWM(); // Start up the EPWMs

hnd_rfft_adc->Tail = &(hnd_rfft->OutBuf);

hnd_rfft->FFTSize = RFFT_SIZE; // FFT size

hnd_rfft->FFTStages = RFFT_STAGES; // FFT stages

hnd_rfft_adc->InBuf = &RFFTin1Buff[0]; // Input buffer (16-bit ADC) input

hnd_rfft->OutBuf = &RFFToutBuff[0]; // Output buffer

hnd_rfft->CosSinBuf = &RFFTF32Coef[0]; // Twiddle factor

hnd_rfft->MagBuf = &RFFTmagBuff[0]; // Magnitude Output Buffer

RFFT_f32_sincostable(hnd_rfft); // Calculate Twiddle Factor

for (i=0; i < RFFT_SIZE; i++){

RFFToutBuff[i] = 0; // Clean up Output Buffer

}

for (i=0; i < RFFT_SIZE; i++){ // /2

RFFTmagBuff[i] = 0; // Clean up Magnitude Buffer

}

for (i=0; i < RFFT_SIZE; i++){ // /2

RFFTsqrtBuff[i] = 0; // Clean up Square-Root Buffer

}

while(1){

while(flagInputReady == 0){}; // Wait on ADC ISR to set the flag before proceeding

RFFT_adc_f32(hnd_rfft_adc); // Calculate real FFT with 16-bit ADC input

flagInputReady = 0; // Reset the flag

RFFT_f32_mag(hnd_rfft); // Calculate magnitude

j = 1;

freq = RFFTmagBuff[1];

freq1 = RFFTsqrtBuff[1];

for(i=2;i<RFFT_SIZE;i++){ // /2+1

if(RFFTmagBuff[i] > freq){

j = i;

freq = RFFTmagBuff[i];

}

for(i=2;i<RFFT_SIZE;i++){

if(RFFTsqrtBuff[i] < freq1){

j = i;

freq1 = sqrtf(RFFTmagBuff[i]);

}

}

}

freq = F_PER_SAMPLE * (float)j;

freq1 = F_PER_SAMPLE * (float)j;

}

done();

return 1;

}

__interrupt void adcaIsr()

{

RFFTin1Buff[sampleIndex++] = AdcaResultRegs.ADCRESULT0;

if(sampleIndex == (2*RFFT_SIZE - 1) ){

sampleIndex = 0;

flagInputReady = 1;

}

AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Clear INT1 flag

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------