From: batt Date: Wed, 9 Jun 2010 11:01:15 +0000 (+0000) Subject: Minor fixes in AT91 ADC module. X-Git-Tag: 2.5.0~9 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=c860c4c4a186878d3623df87be5e6577c59ad31f;p=bertos.git Minor fixes in AT91 ADC module. Improve documentation and fix macros in order to always use a frequency compliant with ADC specifications. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3908 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/cfg_adc.h b/bertos/cfg/cfg_adc.h index dd65e134..35e58661 100644 --- a/bertos/cfg/cfg_adc.h +++ b/bertos/cfg/cfg_adc.h @@ -57,9 +57,12 @@ /** * Clock Frequency for ADC conversion. + * This frequency will be rounded down to an integer + * submultiple of CPU_FREQ. * * $WIZ$ type = "int" * $WIZ$ supports = "at91" + * $WIZ$ max = 5000000 */ #define CONFIG_ADC_CLOCK 4800000UL @@ -67,16 +70,16 @@ * Minimum time for starting up a conversion [us]. * * $WIZ$ type = "int" - * $WIZ$ min = 0 + * $WIZ$ min = 20 * $WIZ$ supports = "at91" */ #define CONFIG_ADC_STARTUP_TIME 20 /** - * Minimum time for sample and hold [us]. + * Minimum time for sample and hold [ns]. * * $WIZ$ type = "int" - * $WIZ$ min = 0 + * $WIZ$ min = 600 * $WIZ$ supports = "at91" */ #define CONFIG_ADC_SHTIME 834 diff --git a/bertos/cpu/arm/drv/adc_at91.c b/bertos/cpu/arm/drv/adc_at91.c index fadaa4be..4ac35861 100644 --- a/bertos/cpu/arm/drv/adc_at91.c +++ b/bertos/cpu/arm/drv/adc_at91.c @@ -184,6 +184,7 @@ void adc_hw_init(void) #endif /* \} */ + LOG_INFO("Computed ADC_CLOCK %ld\n", ADC_COMPUTED_CLOCK); LOG_INFO("prescaler[%ld], stup[%ld], shtim[%ld]\n",ADC_COMPUTED_PRESCALER, ADC_COMPUTED_STARTUPTIME, ADC_COMPUTED_SHTIME); @@ -201,7 +202,7 @@ void adc_hw_init(void) ADC_MR &= ~ADC_SHTIME_MASK; ADC_MR |= ((ADC_COMPUTED_SHTIME << ADC_SHTIME_SHIFT) & ADC_SHTIME_MASK); LOG_INFO("shtime[%ld]\n", (ADC_COMPUTED_SHTIME << ADC_SHTIME_SHIFT) & ADC_SHTIME_MASK); - + #if CONFIG_KERN //Register and enable irq for adc. adc_enable_irq(); diff --git a/bertos/cpu/arm/drv/adc_at91.h b/bertos/cpu/arm/drv/adc_at91.h index 07ef6a40..2ec0cdb5 100644 --- a/bertos/cpu/arm/drv/adc_at91.h +++ b/bertos/cpu/arm/drv/adc_at91.h @@ -57,9 +57,10 @@ * Macro for computing correct value to write into ADC * register. */ -#define ADC_COMPUTED_PRESCALER ((CPU_FREQ/(2 * CONFIG_ADC_CLOCK)) - 1) -#define ADC_COMPUTED_STARTUPTIME (((CONFIG_ADC_STARTUP_TIME * CONFIG_ADC_CLOCK)/ 8000000UL) - 1) -#define ADC_COMPUTED_SHTIME (((CONFIG_ADC_SHTIME * CONFIG_ADC_CLOCK)/1000000000UL) - 1) +#define ADC_COMPUTED_PRESCALER (DIV_ROUNDUP(CPU_FREQ, 2 * CONFIG_ADC_CLOCK) - 1) +#define ADC_COMPUTED_CLOCK (CPU_FREQ / ((ADC_COMPUTED_PRESCALER + 1) * 2)) +#define ADC_COMPUTED_STARTUPTIME (((CONFIG_ADC_STARTUP_TIME * ADC_COMPUTED_CLOCK) / 8000000UL) - 1) +#define ADC_COMPUTED_SHTIME ((uint32_t)((CONFIG_ADC_SHTIME * (uint64_t)ADC_COMPUTED_CLOCK) / 1000000000UL) - 1) /** * Init pins macro for adc.