libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
adc_common_f47.c
Go to the documentation of this file.
1/** @addtogroup adc_file ADC peripheral API
2@ingroup peripheral_apis
3
4@author @htmlonly © @endhtmlonly 2012
5Ken Sarkies <ksarkies@internode.on.net>
6
7@date 30 August 2012
8
9LGPL License Terms @ref lgpl_license
10 */
11/*
12 * This file is part of the libopencm3 project.
13 *
14 * Copyright (C) 2012 Ken Sarkies <ksarkies@internode.on.net>
15 *
16 * This library is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Lesser General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with this library. If not, see <http://www.gnu.org/licenses/>.
28 */
29
31
32/**@{*/
33
34/*---------------------------------------------------------------------------*/
35/** @brief ADC Set the Sample Time for a Single Channel
36
37The sampling time can be selected in ADC clock cycles from 1.5 to 239.5.
38
39@param[in] adc Unsigned int32. ADC block register address base @ref adc_reg_base
40@param[in] channel Unsigned int8. ADC Channel integer 0..18 or from @ref
41adc_channel
42@param[in] time Unsigned int8. Sampling time selection from @ref adc_sample_rg
43 * NOTE Common with f1, f2 and f37x
44*/
45void adc_set_sample_time(uint32_t adc, uint8_t channel, uint8_t time)
46{
47 uint32_t reg32;
48
49 if (channel < 10) {
50 reg32 = ADC_SMPR2(adc);
51 reg32 &= ~(0x7 << (channel * 3));
52 reg32 |= (time << (channel * 3));
53 ADC_SMPR2(adc) = reg32;
54 } else {
55 reg32 = ADC_SMPR1(adc);
56 reg32 &= ~(0x7 << ((channel - 10) * 3));
57 reg32 |= (time << ((channel - 10) * 3));
58 ADC_SMPR1(adc) = reg32;
59 }
60}
61
62/*---------------------------------------------------------------------------*/
63/** @brief ADC Set the Sample Time for All Channels
64
65The sampling time can be selected in ADC clock cycles from 1.5 to 239.5, same
66for all channels.
67
68@param[in] adc Unsigned int32. ADC block register address base @ref adc_reg_base
69@param[in] time Unsigned int8. Sampling time selection from @ref adc_sample_rg
70 * NOTE Common with f1, f2 and f37x
71*/
72void adc_set_sample_time_on_all_channels(uint32_t adc, uint8_t time)
73{
74 uint8_t i;
75 uint32_t reg32 = 0;
76
77 for (i = 0; i <= 9; i++) {
78 reg32 |= (time << (i * 3));
79 }
80 ADC_SMPR2(adc) = reg32;
81
82 for (i = 10; i <= 17; i++) {
83 reg32 |= (time << ((i - 10) * 3));
84 }
85 ADC_SMPR1(adc) = reg32;
86}
87
88
89/*---------------------------------------------------------------------------*/
90/** @brief ADC Set Dual/Triple Mode
91
92The multiple mode uses ADC1 as master, ADC2 and optionally ADC3 in a slave
93arrangement. This setting is applied to ADC1 only.
94
95The various modes possible are described in the reference manual.
96
97@param[in] mode Unsigned int32. Multiple mode selection from @ref adc_multi_mode
98*/
99void adc_set_multi_mode(uint32_t mode)
100{
101 ADC_CCR |= mode;
102}
103
104
105/** Enable The VBat Sensor.
106 * This enables the battery voltage measurements on ADC1 channel 18. On
107 * STM32F42x and STM32F43x, this must be disabled when the temperature sensor
108 * is enabled. If both are enabled, only the VBat conversion is performed.
109 */
111{
113}
114
115/** Disable The VBat Sensor.
116 * Disabling this will reduce power consumption from the battery voltage
117 * measurement.
118 */
120{
121 ADC_CCR &= ~ADC_CCR_VBATE;
122}
123
124/**@}*/
#define ADC_CCR_VBATE
#define ADC_SMPR1(block)
Definition: adc_common_v1.h:61
#define ADC_CCR
#define ADC_SMPR2(block)
Definition: adc_common_v1.h:64
void adc_set_sample_time_on_all_channels(uint32_t adc, uint8_t time)
ADC Set the Sample Time for All Channels.
void adc_set_sample_time(uint32_t adc, uint8_t channel, uint8_t time)
ADC Set the Sample Time for a Single Channel.
void adc_disable_vbat_sensor(void)
Disable The VBat Sensor.
void adc_set_multi_mode(uint32_t mode)
ADC Set Dual/Triple Mode.
void adc_enable_vbat_sensor(void)
Enable The VBat Sensor.