f3 temp sensor working

This commit is contained in:
Karl Palsson 2015-11-03 23:21:44 +00:00
parent 4a1f9d06d2
commit 73e12bd0fd
3 changed files with 15 additions and 10 deletions

View file

@ -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

View file

@ -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();

View file

@ -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");
}
}