2024-09-29 10:13 PM
Hello,
I am acquiring samples from 50Hz Sine Wave through a CT and want to get 100 samples of this signal (T=20ms). For this, I need each sample at 200us apart so I get an array of 100 bytes. I have following clock setup:
APB1 = 36Mhz; ADC = 12Mhz
TIM3 Event: 36,000,000/ 7,200 = 5,000Hz = 200us
ADC Sample Time: Sampling Time + 12.5 cycles = 239.5 + 12.5 = 252 cycles => 1/12Mhz X 252 = 21us
TIM3:
ADC:
Using above settings & calculations, SOC is supposed to complete said ADC in 21us and sample time is 200us which is fine. Here is the code:
/* USER CODE BEGIN PV */
uint16_t adc_value[500] = {0};
/* USER CODE END PV */
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start(&htim3);
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_value, sizeof(adc_value));
/* USER CODE END 2 */
/* ADC Config */
hadc1.Instance = ADC1;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T3_TRGO;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
sConfig.Channel = ADC_CHANNEL_5;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
/* ADC Config */
/* TIM3 Config */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 7200;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
/* TIM3 Config */
I am getting samples in the 400 byte array but I am supposed to get a complete sine wave cycle in first 100 byte but the cycle is completed in 200 bytes. Even I tried to increased sampling time (Counter Period: 14,400) it shows same the result. Here is the samples vs. data result:
Please guide, what I may be missing in the code or in calculations to get a complete 50Hz Sine Wave cycle in ADC of 100 samples.
Regards
Shahid