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.
main_Lec9.cpp@0:34ee385f4d2d, 2021-10-23 (annotated)
- Committer:
- rajathr
- Date:
- Sat Oct 23 05:49:09 2021 +0000
- Revision:
- 0:34ee385f4d2d
At 23rd Oct 21 - All Code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rajathr | 0:34ee385f4d2d | 1 | #include "gpio.h" |
| rajathr | 0:34ee385f4d2d | 2 | #include "led1.h" |
| rajathr | 0:34ee385f4d2d | 3 | #include "main_Lec9.h" //Mort: including main_Lec9.h |
| rajathr | 0:34ee385f4d2d | 4 | #include "mbed.h" |
| rajathr | 0:34ee385f4d2d | 5 | #include "hardware_timer3.h" |
| rajathr | 0:34ee385f4d2d | 6 | #include "interrupt.h" |
| rajathr | 0:34ee385f4d2d | 7 | |
| rajathr | 0:34ee385f4d2d | 8 | Serial pc(USBTX, USBRX); |
| rajathr | 0:34ee385f4d2d | 9 | |
| rajathr | 0:34ee385f4d2d | 10 | |
| rajathr | 0:34ee385f4d2d | 11 | int main(void) |
| rajathr | 0:34ee385f4d2d | 12 | { |
| rajathr | 0:34ee385f4d2d | 13 | uint32_t i,j; |
| rajathr | 0:34ee385f4d2d | 14 | //uint16_t countervalue; |
| rajathr | 0:34ee385f4d2d | 15 | //uint16_t checkvalue; |
| rajathr | 0:34ee385f4d2d | 16 | |
| rajathr | 0:34ee385f4d2d | 17 | /* All of your init functions need to be here */ |
| rajathr | 0:34ee385f4d2d | 18 | |
| rajathr | 0:34ee385f4d2d | 19 | //This is for first LED function |
| rajathr | 0:34ee385f4d2d | 20 | //init_LED1(); //Calling the initialization function - To initialize PortB as its corresponding functionality //Mort: Do not need to say void here |
| rajathr | 0:34ee385f4d2d | 21 | |
| rajathr | 0:34ee385f4d2d | 22 | //This is for Probelm 10 Exercises - START |
| rajathr | 0:34ee385f4d2d | 23 | // //This is for Output Compare: |
| rajathr | 0:34ee385f4d2d | 24 | // InitGPIOBPin0asOutputCompare(); |
| rajathr | 0:34ee385f4d2d | 25 | // TMR3CH3OutputCompare(); |
| rajathr | 0:34ee385f4d2d | 26 | // |
| rajathr | 0:34ee385f4d2d | 27 | // //This is for Input Capture: |
| rajathr | 0:34ee385f4d2d | 28 | // InitGPIOCPin6asInputCapture(); |
| rajathr | 0:34ee385f4d2d | 29 | // TMR3CH1GPIOCPin6asInputCapture(); |
| rajathr | 0:34ee385f4d2d | 30 | //This is for Probelm 10 Exercises - END |
| rajathr | 0:34ee385f4d2d | 31 | |
| rajathr | 0:34ee385f4d2d | 32 | |
| rajathr | 0:34ee385f4d2d | 33 | // //Exercise 11 PWM MODE - 1st Problem - START |
| rajathr | 0:34ee385f4d2d | 34 | // //Initializing PortB Pin 0 as a Output Pin |
| rajathr | 0:34ee385f4d2d | 35 | // InitGPIOBPin0asPWMMode1(); |
| rajathr | 0:34ee385f4d2d | 36 | // TMR3CH3OutputPWMMode1(); |
| rajathr | 0:34ee385f4d2d | 37 | // //Exercise 11 PWM MODE - 1st Problem - END |
| rajathr | 0:34ee385f4d2d | 38 | |
| rajathr | 0:34ee385f4d2d | 39 | // //Exercise 11 PWM MODE - 2nd Problem - START |
| rajathr | 0:34ee385f4d2d | 40 | // //Initializing PortB Pin 0 as a Output Pin |
| rajathr | 0:34ee385f4d2d | 41 | // InitPortBPin0asOutput(); |
| rajathr | 0:34ee385f4d2d | 42 | // initTimer3ToInterrupt(); |
| rajathr | 0:34ee385f4d2d | 43 | // //Exercise 11 PWM MODE - 2nd Problem - END |
| rajathr | 0:34ee385f4d2d | 44 | |
| rajathr | 0:34ee385f4d2d | 45 | //Exercise 11 PWM MODE - 3rd Problem - START |
| rajathr | 0:34ee385f4d2d | 46 | //Initializing PortB Pin 0 as a Output Pin |
| rajathr | 0:34ee385f4d2d | 47 | enableEXTI6OnPortC(); |
| rajathr | 0:34ee385f4d2d | 48 | //Exercise 11 PWM MODE - 3rd Problem - END |
| rajathr | 0:34ee385f4d2d | 49 | |
| rajathr | 0:34ee385f4d2d | 50 | |
| rajathr | 0:34ee385f4d2d | 51 | while(true) |
| rajathr | 0:34ee385f4d2d | 52 | { |
| rajathr | 0:34ee385f4d2d | 53 | //Create FOR Loop to have some delay between toggling |
| rajathr | 0:34ee385f4d2d | 54 | for(i=1; i<100; i++) //Mort: Your code was fine, just your delay was too large. |
| rajathr | 0:34ee385f4d2d | 55 | { |
| rajathr | 0:34ee385f4d2d | 56 | //pc.printf("hi hi hi \n"); |
| rajathr | 0:34ee385f4d2d | 57 | j=j+1; |
| rajathr | 0:34ee385f4d2d | 58 | } |
| rajathr | 0:34ee385f4d2d | 59 | toggle_LED1(); //Function Call to toggle LED |
| rajathr | 0:34ee385f4d2d | 60 | |
| rajathr | 0:34ee385f4d2d | 61 | // countervalue = readCounterValueIfFlagIsSet(); |
| rajathr | 0:34ee385f4d2d | 62 | // if (countervalue > 0 & checkvalue != countervalue) |
| rajathr | 0:34ee385f4d2d | 63 | // { |
| rajathr | 0:34ee385f4d2d | 64 | // pc.printf("\nCounter Value is = %d", countervalue); |
| rajathr | 0:34ee385f4d2d | 65 | // checkvalue = countervalue; |
| rajathr | 0:34ee385f4d2d | 66 | } |
| rajathr | 0:34ee385f4d2d | 67 | } |
| rajathr | 0:34ee385f4d2d | 68 | } |
| rajathr | 0:34ee385f4d2d | 69 | |
| rajathr | 0:34ee385f4d2d | 70 | void debugPrint(uint32_t what) |
| rajathr | 0:34ee385f4d2d | 71 | { |
| rajathr | 0:34ee385f4d2d | 72 | pc.printf("The value is %u\n",what); |
| rajathr | 0:34ee385f4d2d | 73 | } |
| rajathr | 0:34ee385f4d2d | 74 |