Justin Jordan
/
MAX32630FTHR_SqwvGen
Simple square wave generator using MAX32630FTHR and a potentiometer.
Revision 0:bcb65a6f0e8a, committed 2017-07-05
- Comitter:
- j3
- Date:
- Wed Jul 05 22:49:24 2017 +0000
- Child:
- 1:649584ec899f
- Commit message:
- init commit
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jul 05 22:49:24 2017 +0000 @@ -0,0 +1,80 @@ +/****************************************************************************** +* MIT License +* +* Copyright (c) 2017 Justin J. Jordan +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: + +* The above copyright notice and this permission notice shall be included in all +* copies or substantial portions of the Software. + +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +* SOFTWARE. +******************************************************************************/ + + +//Demo uses pot connected between 3.3 and GND with wiper on AIN_0. +//SQWV is generated on P4_0 + + +#include "mbed.h" +#include "max32630fthr.h" +#include "adc.h" + + +int main() +{ + MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); + + MBED_ASSERT(ADC_Init() == E_NO_ERROR); + + //Init pwm signal + PwmOut pwmOut(P4_0); + pwmOut.write(0.5F); + + uint16_t rawADCdata; + float volts = 0.0F; + float period = 0.0F; + + pwmOut.period_us(period); + + printf("\033[H"); //home + printf("\033[0J"); //erase from cursor to end of screen + + //loop + while(1) + { + //Do ADC conversion + ADC_StartConvert(ADC_CH_0_DIV_5, 1, 1); + ADC_GetData(&rawADCdata); + + //Get ADC value in volts + volts = ((6.0F * rawADCdata) / 1023.0F); + + //convert to percentage for pwm + period = (volts / 3.3F); + if(period > 1.0F) + { + period = 1.0F; + } + pwmOut.period_us(period); + + //Display data + printf("Raw Data = 0x%04x\r\n", rawADCdata); + printf("Volts = %3.2f\r\n", volts); + printf("Period = %3.2f\r\n", period); + printf("\033[H"); //home + + wait(0.1F); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max32630fthr.lib Wed Jul 05 22:49:24 2017 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/MaximIntegrated/code/max32630fthr/#60997adf01a2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Wed Jul 05 22:49:24 2017 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#8828635da469162cf2854b5287561c663fb96e72