Part Number:TMS320C5505
Dear sir,
i am taking two different signals to adc channels , set the sampling frequency 51200Hz since i want to read only 1024 samples at a time for one cycle as per calculation for fft calculation..i am getting data for one channel but the problem is when i read two channels at time i get the mixed data of two channels..i dont understan whats going wrong..following is my code:
/*===============================================================================================================================================================*/
void Init_SAR_ch3(void)
{
*SARCTRL = 0x7000; //clear the channels
*SARCTRL |= 0x3800; // Select AIN3 ch3, which is GPAIN1
*SARCLKCTRL = 0x0032; //100MHz/61=1.639344MHz/32=51229Hz //0x17D7; // 100MHz/6103 = 16385Hz/32=512Hz
*SARPINCTRL = 0x7104; //Bandgap-Based Reference Voltage set to 0.8V.
*SARGPOCTRL = 0;
return;
}
/*===============================================================================================================================================================*/
void Init_SAR_ch5(void)
{
*SARCTRL = 0x7000; //clear the channels
*SARCTRL |= 0x5800; //select ch5, GPAIN3
*SARCLKCTRL = 0x0032; //100MHz/61=1.639344MHz/32=51229Hz //0x17D7; // 100MHz/6103 = 16385Hz/32=512Hz
*SARPINCTRL = 0x7104; //Bandgap-Based Reference Voltage set to 0.8V.
*SARGPOCTRL = 0;
return;
}
/*===============================================================================================================================================================*/
double Read_GPAIN1_CH3(void)
{
Int32t val=0;
Uint16t i;double adcData;
*SARCTRL = 0xB800; // Select AIN3 ch3, which is GPAIN1
{
/*for(i=0;i<50; i++)
asm(" nop");*/
val = *SARDATA;
//val=(val/1023)*vref;
if((val&0x8000) == 0)
{
break;
}
}
return val;
}
/*==============================================================================================================================================================*/
double Read_GPAIN1_CH5(void)
{
Int32t val1=0;
Uint16t i;double adcData;
*SARCTRL = 0xD800; //for ch5 continuous conv
while(1)
{
val1 = *SARDATA;
if((val1&0x8000) == 0)
{
break;
}
}
return val1;
}
/*===============================================================================================================================================================*/
/*===============================================================================================================================================================*/
interrupt void gpt0Isr(void)
{
/* Clear Timer Interrupt Aggregation Flag Register (TIAFR) */
CSL_SYSCTRL_REGS->TIAFR = 0x01;
bit_set=1;
}
/*===================================================================================================================================================*/
int main(void)
{
// Uint16 err = 1;
fft_flag = FFT_FLAG;
scale_flag =SCALE_FLAG;
SYS_PCGCR1=0; //INIT clock
SYS_PCGCR2=0; //INIT clock
SYS_EXBUSSEL = 0x0A00;
*(ioport volatile unsigned *)0x0001 = 0x000E;
asm(" idle"); // must add at least one blank before idle in " ".//HWAFFT init
Init_SAR_ch3(); //ADC init
Delay(100);
Init_SAR_ch5(); //ADC init
Timer0_Init();
i=0;j=0;
while(1)
{
if(bit_set==1 &&i<DATA_LEN_1024)
{
adcOutCh3[i]=Read_GPAIN1_CH3();
adcOutCh5[i]=Read_GPAIN1_CH5();
i++;
bit_set=0;
}
if(i==DATA_LEN_1024)
break;
}
Timer0_Stop();
}
/*===============================================================================================================================================================*/
Int16 Timer0_Init(void)
{
/* Open the CSL GPT module */
hGpt = GPT_open (GPT_0, &gptObj, &status);
/* Reset the GPT module */
status = GPT_reset(hGpt);
/* Clear any pending interrupts */
IRQ_clearAll();
/* Disable all the interrupts */
IRQ_disableAll();
IRQ_setVecs((Uint32)(&VECSTART));
IRQ_plug(TINT_EVENT, &gpt0Isr);
IRQ_enable(TINT_EVENT);
hwConfig.autoLoad = GPT_AUTO_ENABLE;
hwConfig.ctrlTim = GPT_TIMER_ENABLE;
hwConfig.preScaleDiv = GPT_PRE_SC_DIV_1;
//for 1ms
hwConfig.prdLow = 0x01d6; // 0x00017d78 for 3.9ms=1/256Hz
hwConfig.prdHigh = 0x0000;
/* Configure the GPT module */
status = GPT_config(hGpt, &hwConfig);
/* Enable CPU Interrupts */
IRQ_globalEnable();
/* Start the Timer */
GPT_start(hGpt);
return (CSL_TEST_PASSED);
}
/*===============================================================================================================================================================*/