Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 1:c125f4e65df7
- Parent:
- 0:716b93ab9a58
--- a/main.cpp Fri Oct 29 20:56:20 2021 +0000 +++ b/main.cpp Wed Nov 03 05:31:26 2021 +0000 @@ -1,50 +1,47 @@ #include "gpio.h" -#include "led1.h" -#include "main_Lec9.h" //Mort: including main_Lec9.h #include "mbed.h" -#include "hardware_timer.h" +#include "hardware_adc.h" +#include "hardware_dma_controller.h" Serial pc(USBTX, USBRX); int main(void) { - //uint32_t i,j; - uint16_t countervalue; - uint16_t checkvalue; - - //This is for first LED function - //init_LED1(); //Calling the initialization function - To initialize PortB as its corresponding functionality //Mort: Do not need to say void here - + uint32_t i,j,k; + j = 0; - //This is for Output Compare: - InitGPIOBPin0asOutputCompare(); - TMR3CH3OutputCompare(); + //For Design Problem 1 - Exercise 10 - START + initADC3_5_withDMA(); + InitPortBPin0asOutput(); //initialize GPIOB as Output + startADCConversion(); + //For Design Problem 1 - Exercise 10 - END - //This is for Input Capture: - InitGPIOCPin6asInputCapture(); - TMR3CH1GPIOCPin6asInputCapture(); - - while(true) + //For Design Problem 2 - Exercise 10 - START + initADC3_567_withDMA(); + InitPortBPin0asOutput(); //initialize GPIOB as Output + startADCConversion(); + //For Design Problem 2 - Exercise 10 - END + + while(1) { - // Create FOR Loop to have some delay between toggling -// for(i=1; i<100; i++) //Mort: Your code was fine, just your delay was too large. -// { -// //pc.printf("hi hi hi \n"); -// j=j+1; -// } - //toggle_LED1(); //Function Call to toggle LED - - countervalue = readCounterValueIfFlagIsSet(); - if (countervalue > 0 & checkvalue != countervalue) + for (i=0; i<10000000; i++) { - pc.printf("\nCounter Value is = %d", countervalue); - checkvalue = countervalue; + for(k=0; k<10000000; k++) + { + j=j+1; //Tiny Delay + } } - } + + //Code for DMA - DESIGN PROBLEM 1 - Exercise 10 - START + pc.printf("ADC Value is %u\n", returnADC3StoredValue1Channel(0)); + toggleGPIOB0(); + //Code for DMA - DESIGN PROBLEM 1 - Exercise 10 - END + + + //Code for DMA - DESIGN PROBLEM 2 - Exercise 10 - START + pc.printf("ADC Value 1 is %u, ADC Value 2 is % u and ADC Value 3 is %u\n", returnADC3StoredValue3Channel(0), returnADC3StoredValue3Channel(1), returnADC3StoredValue3Channel(2)); + toggleGPIOB0(); + //Code for DMA - DESIGN PROBLEM 2 - Exercise 10 - END + } } - -void debugPrint(uint32_t what) -{ - pc.printf("The value is %u\n",what); -}