Tool/software: TI C/C++ Compiler
Hi,
I am interfacing TM4C123 with LTC2442 external ADC. I am facing an issue while reading the ADC values using delay. I am reading the ADC in 2 method.
SSI configuration
void LTC2442_SPI_config(void)
{
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_SSI0));
/*The SSI0eperipheral is on Port A and pins 2,3,4 and 5.*/
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
/*configure the port pins for clock,chipselect,receiver,transmitter*/
ROM_GPIOPinConfigure(LTC2442_SPI_CLK);
// ROM_GPIOPinConfigure(LTC2442_SPI_CS); // Using the chip select externally so configure as output
ROM_GPIOPinConfigure(LTC2442_SPI_RX);
ROM_GPIOPinConfigure(LTC2442_SPI_TX);
// ROM_GPIOPinConfigure(GPIO_PIN_7);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3);
LTC2442_SPI_CS_HI;
ROM_GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_7); //Busy status pin
/* Configure the pin for SSI*/
ROM_GPIOPinTypeSSI(GPIO_PORTA_BASE, LTC2442_SPI_TX_PIN | LTC2442_SPI_RX_PIN | LTC2442_SPI_CLK_PIN);
/* Clock setting for SSI*/
// SSIClockSourceSet(SSI0_BASE, SSI_CLOCK_SYSTEM);
ROM_SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 2000000, 16);
ROM_SSIEnable(SSI0_BASE);
}
first method
int LTC2442_ADC_OutputRead(unsigned int Channelnumber)
{
uint32_t TX[2] = {0};
uint32_t data =0;
int i=0;
float sum =0;
float ADC_Conv = 0.2980232416405;
//unsigned int channel_number = 0xB0000000;
//uint32_t dataread, datastored;
while(GPIOPinRead(GPIO_PORTA_BASE, LTC2442_SPI_BUSY_PIN));
/* make cs pin to low after reading the adc data*/
LTC2442_SPI_CS_LO;
while(GPIOPinRead(GPIO_PORTA_BASE, LTC2442_SPI_BUSY_PIN));
/* make cs pin to low after reading the adc data*/
LTC2442_SPI_CS_LO;
//ADC_SPI_Rqst_pkt = LTC2442_ADC_SPIPktGen(ADC_Channel_No); //Generate the Packet for the ADC Channel data request.
//ADC_SPI_Read_Pkt = LTC2442_ADC_Communication(ADC_SPI_Rqst_pkt); //Dummy Read to set the next output channel
switch(Channelnumber)
{
case 0:
{
for(i =0; i<2;i++)
{
for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++)
{
ROM_SSIDataPut(SSI0_BASE, ch0[ulindex]);
while(ROM_SSIBusy(SSI0_BASE)){}
ROM_SSIDataGet(SSI0_BASE, &ulDataRx[ulindex]);
while(ROM_SSIBusy(SSI0_BASE)){}
Delay(100); //5 millisecond delay
}
}
}
break;
}
LTC2442_SPI_CS_HI;
Method 2
unsigned int LTC2442_ADC_Communication(unsigned int ADC_SPI_Rqst_pkt)
{
volatile unsigned int Temp_Pkt = 0,ADC_SPI_Read_Pkt = 0,Tx_Temp_Buff = 0 ;
while(GPIOPinRead(GPIO_PORTA_BASE, LTC2442_SPI_BUSY_PIN));
/* make cs pin to low after reading the adc data*/
LTC2442_SPI_CS_LO;
while(ROM_SSIBusy(SSI0_BASE)){}
Tx_Temp_Buff = ((ADC_SPI_Rqst_pkt>>16) & 0x0000ffff) ;
ROM_SSIDataPut(SSI0_BASE,Tx_Temp_Buff);
while(ROM_SSIBusy(SSI0_BASE)){}
ROM_SSIDataGet(SSI0_BASE, &Temp_Pkt);
while(ROM_SSIBusy(SSI0_BASE)){}
ADC_SPI_Read_Pkt = Temp_Pkt ;
ADC_SPI_Read_Pkt = ADC_SPI_Read_Pkt << 16 ;
Tx_Temp_Buff = (ADC_SPI_Rqst_pkt & 0x0000ffff) ;
ROM_SSIDataPut(SSI0_BASE,Tx_Temp_Buff); //Second 16 bit packet to DAC.
while(SSIBusy(SSI0_BASE)){}
ROM_SSIDataGet(SSI0_BASE,&Temp_Pkt);
while(SSIBusy(SSI0_BASE)){}
LTC2442_SPI_CS_HI;
ADC_SPI_Read_Pkt |= Temp_Pkt ;
return ADC_SPI_Read_Pkt;
}
In first method I am putting delay and able to read data. If I am not putting delay it is not reading and in method 2 reading data without delay.
Why delay is affecting data read.
I want to read constant voltage at the output of ADC. When I am trying to read voltages are fluctuating in microvolt range. I connected a constant voltage source at the input of ADC and read the ADC output, but the voltages are fluctuating in microvolt range.When taking average also the values are fluctuating only. Is there any way to reduce this fluctuation.
Thank you,
Alphy