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
/**
* 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
* 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
#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);
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();
* 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.