/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file PLL is set to x12 with a PREDIV /2 so the system clock SYSCLK = 48MHz */ ConfigureGPIO(); SetClockForADC(); CalibrateADC(); ConfigureGPIOforADC(); EnableADC(); ConfigureADC(); ConfigureDMA(); ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversions */ GPIOC->BSRR = (1<<9); /* switch on the green led */ __WFI(); /* No interrupt should occur, as only error could trigger an interrupt */ GPIOC->BRR = (1<<9); /* switch off the green led */ DisableADC(); SysTick_Config(48000); /* 1ms config */ while (1) /* Infinite loop */ { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file PLL is set to x12 with a PREDIV /2 so the system clock SYSCLK = 48MHz */ ConfigureGPIO(); ConfigureExternalIT(); RCC->APB2ENR = RCC_APB2ENR_ADC1EN; /* Enable the peripheral clock of the ADC */ RCC->CFGR |= RCC_CFGR_PPRE_2; /* Set peripheral prescaler to /2 so PCLK = HCLK/2 = 24MHz */ CalibrateADC(); EnableADC(); ConfigureADC(); ConfigureDMA(); ADC1->CR |= ADC_CR_ADSTART; /* Start the ADC conversions */ while (error < ERROR_UNEXPECTED_DMA_IT) /* loop till no unrecoverable error */ { __WFI(); } DisableADC(); SysTick_Config(48000); /* 1ms config */ while (1) /* Infinite loop */ { } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file PLL is set to x12 with a PREDIV /2 so the system clock SYSCLK = 48MHz */ ConfigureGPIO(); ConfigureExternalIT(); SetClockForADC(); CalibrateADC(); ConfigureGPIOforADC(); EnableADC(); ConfigureADC(); CurrentChannel = 0; /* Initializes the CurrentChannel */ ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversions */ while (error == 0) /* loop till no unrecoverable error, should never be exited */ { __WFI(); } DisableADC(); SysTick_Config(48000); /* 1ms config */ while (1) /* Infinite loop */ { } }
unsigned int SampNoise(char chan) { SetCH0In(chan); // Set which Analog port to sample EnableADC(); // Enable ADC Module StartSamp(); // Start Sampling __delay_us(10); // Sample for 10us StopSamp(); // Stop sampling, start conversion while(!AD1CON1bits.DONE); return ADCBUF0; // Return Sampled Noise }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f072xb.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file PLL is set to x12 with a PREDIV /2 so the system clock SYSCLK = 48MHz */ /* defines the upper limit 15% above the factory value the value is adapted according to the application power supply versus the factory calibration power supply */ uint16_t vrefint_high = (*VREFINT_CAL_ADDR)* VDD_CALIB / VDD_APPLI * 115 / 100; /* defines the lower limit 15% below the factory value the value is adapted according to the application power supply versus the factory calibration power supply */ uint16_t vrefint_low = (*VREFINT_CAL_ADDR) * VDD_CALIB / VDD_APPLI * 85 / 100; ConfigureGPIO(); SetClockForADC(); CalibrateADC(); EnableADC(); ConfigureADC(); ConfigureTIM15(); ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversion */ while (error == 0) /* Loop till the measure is in the range */ { while ((ADC1->ISR & ADC_ISR_EOC) == 0); /* wait end of conversion */ if ((ADC1->DR > vrefint_high) && (ADC1->DR > vrefint_low)) { error |= WARNING_MEASURE; /* report a warning, the measure being out of range due to VDD shift */ } GPIOC->ODR ^= (1<<9); /* Toggle green led on PC9 */ } DisableADC(); SysTick_Config(48000); /* 1ms config */ while(1) { } }