summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/adc-power/README.md5
-rw-r--r--tests/adc-power/adc-power.c14
-rw-r--r--tests/adc-power/main-stm32f3-disco.c6
3 files changed, 15 insertions, 10 deletions
diff --git a/tests/adc-power/README.md b/tests/adc-power/README.md
index 7dbbe8a..7da8ad7 100644
--- a/tests/adc-power/README.md
+++ b/tests/adc-power/README.md
@@ -1,3 +1,8 @@
+
+For most boards, adc channels 1 and 5 are PA1 and PA5.
+
+Not the F3. oh no, that board is cray cray. PA0 and PF4
+
https://github.com/libopencm3/libopencm3/pull/471
https://github.com/libopencm3/libopencm3/pull/457
https://github.com/libopencm3/libopencm3/pull/534
diff --git a/tests/adc-power/adc-power.c b/tests/adc-power/adc-power.c
index 4b591a6..db72a8e 100644
--- a/tests/adc-power/adc-power.c
+++ b/tests/adc-power/adc-power.c
@@ -21,10 +21,12 @@
// Still have some bad shit to deal with...
#if defined(STM32F3)
-#define SAMPLE_TIME_BASIC ADC_SMPR1_SMP_19DOT5CYC
+#define SAMPLE_TIME_BASIC ADC_SMPR1_SMP_181DOT5CYC
+#define SAMPLE_TIME_TEMP ADC_SMPR1_SMP_601DOT5CYC // 2.2usecs or more
+#define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP
#elif defined(STM32F4)
#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_28CYC
-#define SAMPLE_TIME_TEMP ADC_SMPR_SMP_144CYC
+#define SAMPLE_TIME_TEMP ADC_SMPR_SMP_144CYC // 10 usecs or more, in theory needs 840cycles!
#define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP
#define ADC_CHANNEL_TEMP ADC_CHANNEL_TEMP_F40
#define SEPARATE_VREF 0
@@ -50,13 +52,8 @@ void adc_power_init(void)
rcc_periph_clock_enable(RCC_ADC12);
rcc_adc_prescale(RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_1, RCC_CFGR2_ADCxPRES_PLL_CLK_DIV_1);
adc_enable_regulator(ADC1);
- adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR1_SMP_19DOT5CYC);
#else
rcc_periph_clock_enable(RCC_ADC1);
- adc_set_sample_time_on_all_channels(ADC1, SAMPLE_TIME_BASIC);
- adc_set_sample_time(ADC1, ADC_CHANNEL_TEMP, SAMPLE_TIME_TEMP);
- adc_set_sample_time(ADC1, ADC_CHANNEL_TEMP, SAMPLE_TIME_VREF);
-
#if 0
// DANGER DANGER! doing this without DMA is dum.
// but... we're busy polling, we should be right... right?
@@ -68,6 +65,9 @@ void adc_power_init(void)
#endif
#endif
+ adc_set_sample_time_on_all_channels(ADC1, SAMPLE_TIME_BASIC);
+ adc_set_sample_time(ADC1, ADC_CHANNEL_TEMP, SAMPLE_TIME_TEMP);
+ adc_set_sample_time(ADC1, ADC_CHANNEL_TEMP, SAMPLE_TIME_VREF);
adc_enable_temperature_sensor();
#if (SEPARATE_VREF == 1)
adc_enable_vrefint();
diff --git a/tests/adc-power/main-stm32f3-disco.c b/tests/adc-power/main-stm32f3-disco.c
index 277ca17..6ce40a8 100644
--- a/tests/adc-power/main-stm32f3-disco.c
+++ b/tests/adc-power/main-stm32f3-disco.c
@@ -102,8 +102,8 @@ int main(void)
printf("hi guys!\n");
rcc_periph_clock_enable(RCC_GPIOA);
- gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0);
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1);
+ gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5);
adc_power_init();
for (i = 0; i < 0x1000; i++) { /* need as much as 10 usecs for vreg */
@@ -113,13 +113,13 @@ int main(void)
adc_power_task_up();
gpio_toggle(GPIOE, GPIO8);
- for (i = 0; i < 0x800000; i++) { /* Wait a bit. */
+ for (i = 0; i < 0x100000; i++) { /* Wait a bit. */
__asm__("NOP");
}
printf("tick...\n");
adc_power_task_down();
gpio_toggle(GPIOE, GPIO8);
- for (i = 0; i < 0x800000; i++) { /* Wait a bit. */
+ for (i = 0; i < 0x100000; i++) { /* Wait a bit. */
__asm__("NOP");
}
}