ADS131E08 custom sample rate contains zeros in the data - Page 1
Forum section: electronics / projects

author: ali_asadzadeh
author_rank: Super Contributor
timestamp: February 23, 2019, 12:21:12 pm
content: Hi,I wanted to capture data from this ADC with a custom sample rate, so I have set my STM32 timer to fire for example 12800 samples per second, and I have tied it's output to the start pin signal. Also I have connected the DRDY signal to one of external Pins of my MCU configured as an Interrupt on falling edges, when the interrupt fires, I just use the RDATA command to read the ADC data value, but the problem with this approach is that in some samples my data is zero, here is a screen shot of the captured data with matlab,This is my main loop codeCode://Reset ADCHAL_GPIO_WritePin(GPIOA,ADC_RST_Pin,GPIO_PIN_RESET);HAL_Delay(1);HAL_GPIO_WritePin(GPIOA,ADC_RST_Pin,GPIO_PIN_SET);//Start ADC in continuous modeHAL_GPIO_WritePin(GPIOA,ADC_START_Pin,GPIO_PIN_SET);//Send SDATACtx=0x11;ADC_sendCommand(tx,rx,1);tx=0x43;//Wrtie config3 Regtx=0x00;//Number of regs to write = 1tx=0xcc;//the value to be writtenADC_sendCommand(tx,rx,3);//wait for internal Ref to power upfor(i=0;i<10000;i++);//read reg to verifytx=0x23;//Read config3 Regtx=0x00;//Number of regs to Read = 1tx=0x00;//ADC_sendCommand(tx,rx,3);tx=0x41;//Wrtie config1 Regtx=0x00;//Number of regs to write = 1tx=0xD2;//the value to be written //set sample clock to 16KspsADC_sendCommand(tx,rx,3);tx=0x42;//Wrtie config2 Regtx=0x00;//Number of regs to write = 1tx=0xF0;//the value to be writtenADC_sendCommand(tx,rx,3);tx=0x46;//Wrtie CH2 Regtx=0x00;//Number of regs to write = 1tx=0x10;//the value to be writtenADC_sendCommand(tx,rx,3);tx=0x26;//Read CH2 Regtx=0x00;//Number of regs to Read = 1tx=0x00;//ADC_sendCommand(tx,rx,3);tx=0x44;//Write Fualt Regtx=0x00;//Number of regs to Read = 1tx=0x00;//ADC_sendCommand(tx,rx,3);tx=0x4D;//Write Unknown1 Regtx=0x00;//Number of regs to Read = 1tx=0x00;//ADC_sendCommand(tx,rx,3);tx=0x4E;//Write Unknown2 Regtx=0x00;//Number of regs to Read = 1tx=0x00;//ADC_sendCommand(tx,rx,3);tx=0x4F;//Write Unknown3 Regtx=0x00;//Number of regs to Read = 1tx=0x00;//ADC_sendCommand(tx,rx,3);tx=0x50;//Write Unknown4 Regtx=0x00;//Number of regs to Read = 1tx=0x00;//ADC_sendCommand(tx,rx,3);tx=0x51;//Write Unknown5 Regtx=0x00;//Number of regs to Read = 1tx=0x00;//ADC_sendCommand(tx,rx,3);//Send SDATACtx=0x11;ADC_sendCommand(tx,rx,1);//sample = 12800 and our time clock is 84MHz so set the time to 12800HzHAL_TIM_Base_Start_IT(&htim1);HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);TIM1->ARR=77;TIM1->CCR1 = 39;HAL_GPIO_WritePin(GPIOA,ADC_START_Pin,GPIO_PIN_RESET); // Start = 0HAL_GPIO_WritePin(GPIOA,ADC_CS_Pin,GPIO_PIN_RESET);//CS = 0ADC_ready=0;Start_capture=0;while (1){if(Start_capture){Start_capture=0;HAL_GPIO_WritePin(GPIOA,ADC_START_Pin,GPIO_PIN_SET); // Start = 1}if(ADC_ready){ADC_ready=0;tx=0x12; //RDATA Commandfor(int g=1;g<28;g++){tx=0;}HAL_SPI_TransmitReceive(&hspi1,tx,rx,28,100);HAL_GPIO_WritePin(GPIOA,ADC_START_Pin,GPIO_PIN_RESET); // Start = 0adcBuf=(rx << 24) | (rx << 16) | (rx<<8) | 0x00;adcBuf /= 256;}}Ans this is my External interrupt codeCode:void EXTI3_IRQHandler(void){/* USER CODE BEGIN EXTI3_IRQn 0 *//* USER CODE END EXTI3_IRQn 0 */HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);/* USER CODE BEGIN EXTI3_IRQn 1 */ADC_ready=1;/* USER CODE END EXTI3_IRQn 1 */}and here is my timer interrupt codeCode:void TIM1_UP_TIM10_IRQHandler(void){/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 0 *//* USER CODE END TIM1_UP_TIM10_IRQn 0 */HAL_TIM_IRQHandler(&htim1);/* USER CODE BEGIN TIM1_UP_TIM10_IRQn 1 */if(ADC_ready == 0){Start_capture = 1;}/* USER CODE END TIM1_UP_TIM10_IRQn 1 */}So what's missing or am doing it wrong?