
ADC example on AIN_0
Dependencies: max32630fthr mbed
main.cpp@0:ecc75690fcf5, 2017-02-21 (annotated)
- Committer:
- j3
- Date:
- Tue Feb 21 19:39:04 2017 +0000
- Revision:
- 0:ecc75690fcf5
- Child:
- 1:047c43d8b360
init commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:ecc75690fcf5 | 1 | /****************************************************************************** |
j3 | 0:ecc75690fcf5 | 2 | * MIT License |
j3 | 0:ecc75690fcf5 | 3 | * |
j3 | 0:ecc75690fcf5 | 4 | * Copyright (c) 2017 Justin J. Jordan |
j3 | 0:ecc75690fcf5 | 5 | * |
j3 | 0:ecc75690fcf5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
j3 | 0:ecc75690fcf5 | 7 | * of this software and associated documentation files (the "Software"), to deal |
j3 | 0:ecc75690fcf5 | 8 | * in the Software without restriction, including without limitation the rights |
j3 | 0:ecc75690fcf5 | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
j3 | 0:ecc75690fcf5 | 10 | * copies of the Software, and to permit persons to whom the Software is |
j3 | 0:ecc75690fcf5 | 11 | * furnished to do so, subject to the following conditions: |
j3 | 0:ecc75690fcf5 | 12 | |
j3 | 0:ecc75690fcf5 | 13 | * The above copyright notice and this permission notice shall be included in all |
j3 | 0:ecc75690fcf5 | 14 | * copies or substantial portions of the Software. |
j3 | 0:ecc75690fcf5 | 15 | |
j3 | 0:ecc75690fcf5 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
j3 | 0:ecc75690fcf5 | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
j3 | 0:ecc75690fcf5 | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
j3 | 0:ecc75690fcf5 | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
j3 | 0:ecc75690fcf5 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
j3 | 0:ecc75690fcf5 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
j3 | 0:ecc75690fcf5 | 22 | * SOFTWARE. |
j3 | 0:ecc75690fcf5 | 23 | ******************************************************************************/ |
j3 | 0:ecc75690fcf5 | 24 | |
j3 | 0:ecc75690fcf5 | 25 | |
j3 | 0:ecc75690fcf5 | 26 | #include "mbed.h" |
j3 | 0:ecc75690fcf5 | 27 | #include "max32630fthr.h" |
j3 | 0:ecc75690fcf5 | 28 | |
j3 | 0:ecc75690fcf5 | 29 | |
j3 | 0:ecc75690fcf5 | 30 | int main () |
j3 | 0:ecc75690fcf5 | 31 | { |
j3 | 0:ecc75690fcf5 | 32 | //Init board and set GPIO to 3.3V logic |
j3 | 0:ecc75690fcf5 | 33 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
j3 | 0:ecc75690fcf5 | 34 | |
j3 | 0:ecc75690fcf5 | 35 | //Turn RGB LED off |
j3 | 0:ecc75690fcf5 | 36 | DigitalOut rLED(LED1, LED_OFF); |
j3 | 0:ecc75690fcf5 | 37 | DigitalOut gLED(LED2, LED_OFF); |
j3 | 0:ecc75690fcf5 | 38 | DigitalOut bLED(LED3, LED_OFF); |
j3 | 0:ecc75690fcf5 | 39 | |
j3 | 0:ecc75690fcf5 | 40 | AnalogIn a0(AIN_0); |
j3 | 0:ecc75690fcf5 | 41 | float a0_val; |
j3 | 0:ecc75690fcf5 | 42 | |
j3 | 0:ecc75690fcf5 | 43 | while(1) |
j3 | 0:ecc75690fcf5 | 44 | { |
j3 | 0:ecc75690fcf5 | 45 | //ADC is configured for no input scaling and no input buffer bypass, |
j3 | 0:ecc75690fcf5 | 46 | //so range is 0 to 1.2V. See 'analogin_api.c' for target and |
j3 | 0:ecc75690fcf5 | 47 | //user's guide page 567, |
j3 | 0:ecc75690fcf5 | 48 | //https://www.maximintegrated.com/en/app-notes/index.mvp/id/6349 |
j3 | 0:ecc75690fcf5 | 49 | a0_val = (a0.read() * 1.2F); |
j3 | 0:ecc75690fcf5 | 50 | |
j3 | 0:ecc75690fcf5 | 51 | printf("AIN_0 = %f volts\r\n", a0_val); |
j3 | 0:ecc75690fcf5 | 52 | |
j3 | 0:ecc75690fcf5 | 53 | wait(0.25); |
j3 | 0:ecc75690fcf5 | 54 | gLED = !gLED; |
j3 | 0:ecc75690fcf5 | 55 | } |
j3 | 0:ecc75690fcf5 | 56 | } |