Merge pull request #10938 from miri64/feather-m0/enh/bat-adc-line

feather-m0: add BAT voltage ADC line (A7)
This commit is contained in:
Alexandre Abadie 2019-06-06 17:17:10 +02:00 committed by GitHub
commit eb0a4f99c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -24,7 +24,20 @@ SAMD21 mcu.
### Pinout
<img src="https://cdn-learn.adafruit.com/assets/assets/000/030/921/original/adafruit_products_2772_pinout_v1_0.png"
alt="Adafruit Feather M0 proto pinout" style="width:800px;"/>
alt="Adafruit Feather M0 proto pinout" style="width:800px;"/><br/>
`AIN7` can be used to [measure the voltage of a connected Lipoly battery][battery].
It is mapped to ADC_LINE(6) in RIOT.
~~~~~~~~~~~~~~~~ {.c}
int vbat = adc_sample(ADC_LINE(6), ADC_RES_10BIT);
vbat *= 2; /* voltage was divided by 2, so multiply it back */
vbat *= 33; /* reference voltage 3.3V * 10 */
vbat /= 10240; /* resolution * 10 (because we multiplied 3.3V by 10) */
printf("Bat: %dV\n", vbat);
~~~~~~~~~~~~~~~~
[battery]: https://learn.adafruit.com/adafruit-feather-m0-basic-proto/power-management#measuring-battery-4-9
### Flash the board

View File

@ -200,9 +200,10 @@ static const adc_conf_chan_t adc_channels[] = {
{ GPIO_PIN(PA, 4), ADC_INPUTCTRL_MUXPOS_PIN4 }, /* A3 */
{ GPIO_PIN(PA, 5), ADC_INPUTCTRL_MUXPOS_PIN5 }, /* A4 */
{ GPIO_PIN(PB, 2), ADC_INPUTCTRL_MUXPOS_PIN10 }, /* A5 */
{ GPIO_PIN(PA, 7), ADC_INPUTCTRL_MUXPOS_PIN7 }, /* A7 */
};
#define ADC_0_CHANNELS (6U)
#define ADC_0_CHANNELS (7U)
#define ADC_NUMOF ADC_0_CHANNELS
/** @} */