Why ADC continuous readings from software are not possible?
I have STM32F303CCTX custom board.
IO Pin PB8 has a timer that triggers a gpio high for 200us and resets for 300us. creates a 1.8KHz wave with about 35% duty using plain timer mode. Timer IRQ handler also fires the adc conversion on pin PB0.
It continuously keeps running with no values for over a minute. Then suddenly exits to second for loop with the scans(mostly invalid values).
main.c
#define ADC_ARRY_SIZE 30
uint16_t adc_vals[ADC_ARRY_SIZE] = {0};
uint16_t adc_val = 0;
uint32_t adc_zero_count = 0;
uint32_t index_no = 0;
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
adc_val = HAL_ADC_GetValue(&hadc3);
if((adc_val != 0) && (index_no < ADC_ARRY_SIZE))
adc_vals[index_no++] = adc_val;
else if(adc_val == 0)
adc_zero_count++;
}
void set_pwm2_duty(uint32_t duty_count)
{
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, duty_count);
}
int main(void)
{
adc_val = 0;
adc_zero_count = 0;
index_no = 0;
adc_buffer_full = false;
int i;
//Generated code begin
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ADC3_Init();
MX_TIM2_Init();
MX_TIM6_Init();
//generated code end
set_laser_pwm_duty(3000);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOGPIOB, GPIO_PIN_8, GPIO_PIN_SET);
HAL_TIM_Base_Start_IT(&htim6);//start pulse timer
adc_trigger = true;
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if(index_no >= 30)
break;
HAL_Delay(1);
}
HAL_TIM_Base_Stop(&htim6);//start blink timer
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1);
HAL_ADC_Stop_IT(&hadc3);
for(i=0;i<ADC_ARRY_SIZE;i++)
ladc_vals[i] = adc_vals[i];
for(;;);
}