MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / ADC_TimebaseCalc

Function ADC_TimebaseCalc

bsp/efm32/Libraries/emlib/src/em_adc.c:492–521  ·  view source on GitHub ↗

/ * @brief * Calculate timebase value in order to get a timebase providing at least 1us. * * @param[in] hfperFreq Frequency in Hz of reference HFPER clock. Set to 0 to * use currently defined HFPER clock setting. * * @return * Timebase value to use for ADC in order to achieve at least 1 us. ******************************************************************************/

Source from the content-addressed store, hash-verified

490 * Timebase value to use for ADC in order to achieve at least 1 us.
491 ******************************************************************************/
492uint8_t ADC_TimebaseCalc(uint32_t hfperFreq)
493{
494 if (!hfperFreq)
495 {
496 hfperFreq = CMU_ClockFreqGet(cmuClock_HFPER);
497
498 /* Just in case, make sure we get non-zero freq for below calculation */
499 if (!hfperFreq)
500 {
501 hfperFreq = 1;
502 }
503 }
504#if defined(_EFM32_GIANT_FAMILY)
505 /* Handle errata on Giant Gecko, max TIMEBASE is 5 bits wide or max 0x1F */
506 /* cycles. This will give a warmp up time of e.g. 0.645us, not the */
507 /* required 1us when operating at 48MHz. One must also increase acqTime */
508 /* to compensate for the missing clock cycles, adding up to 1us in total.*/
509 /* See reference manual for details. */
510 if( hfperFreq > 32000000 )
511 {
512 hfperFreq = 32000000;
513 }
514#endif
515 /* Determine number of HFPERCLK cycle >= 1us */
516 hfperFreq += 999999;
517 hfperFreq /= 1000000;
518
519 /* Return timebase value (N+1 format) */
520 return (uint8_t)(hfperFreq - 1);
521}
522
523
524/** @} (end addtogroup ADC) */

Callers 1

rt_hw_adc_unit_initFunction · 0.85

Calls 1

CMU_ClockFreqGetFunction · 0.85

Tested by

no test coverage detected