Bryan and Naved Debub monitor
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
Go to the documentation of this file.
00001 /**---------------------------------------------------------------------------- 00002 00003 \file main.cpp 00004 -- -- 00005 -- ECEN 5803 Mastering Embedded System Architecture -- 00006 -- Project 1 Module 4 -- 00007 -- Microcontroller Firmware -- 00008 -- main.cpp -- 00009 -- -- 00010 ------------------------------------------------------------------------------- 00011 -- 00012 -- Designed for: University of Colorado at Boulder 00013 -- 00014 -- 00015 -- Designed by: Tim Scherr 00016 -- Revised by: Student's name 00017 -- 00018 -- Version: 2.1 00019 -- Date of current revision: 2017-09-25 00020 -- Target Microcontroller: Freescale MKL25ZVMT4 00021 -- Tools used: ARM mbed compiler 00022 -- ARM mbed SDK 00023 -- Freescale FRDM-KL25Z Freedom Board 00024 -- 00025 -- 00026 -- Functional Description: Main code file generated by mbed, and then 00027 -- modified to implement a super loop bare metal OS. 00028 -- 00029 -- Copyright (c) 2015, 2016 Tim Scherr All rights reserved. 00030 -- 00031 */ 00032 00033 #define MAIN 00034 #include "shared.h" 00035 #undef MAIN 00036 00037 #define ADC_0 (0U) 00038 #define CHANNEL_0 (0U) 00039 #define CHANNEL_1 (1U) 00040 #define CHANNEL_2 (2U) 00041 #define LED_ON (0U) 00042 #define LED_OFF (1U) 00043 #define ADCR_VDD (65535U) /*! Maximum value when use 16b resolution */ 00044 #define V_BG (1000U) /*! BANDGAP voltage in mV (trim to 1.0V) */ 00045 #define V_TEMP25 (716U) /*! Typical VTEMP25 in mV */ 00046 #define M (1620U) /*! Typical slope: (mV x 1000)/oC */ 00047 #define STANDARD_TEMP (25) 00048 00049 extern volatile uint16_t SwTimerIsrCounter; 00050 00051 00052 Ticker tick; // Creates a timer interrupt using mbed methods 00053 Timer main_loop; 00054 Timer timer0_loop; 00055 /**************** ECEN 5803 add code as indicated ***************/ 00056 // Add code to control red, green and blue LEDs here - Control section added here(completed) 00057 00058 PinName const redLED = PTB18; // pin number for red LED 00059 PinName const greenLED = PTB19; // pin number for green LED 00060 PinName const blueLED = PTD1; // pin number for blue LED 00061 //Set LEDs to be off right now 00062 DigitalOut rled(redLED,1); 00063 DigitalOut gled(greenLED,1); 00064 DigitalOut bled(blueLED,1); 00065 00066 Serial pc(USBTX, USBRX); 00067 00068 void flip() 00069 { 00070 gled = !gled; 00071 } 00072 00073 //uint16_t temperature; // value that will be external to all variable. stores the value of temperature 00074 //uint16_t Vtemp; // value in mV of the temperature calculated 00075 //uint16_t frequency; // value that will store the frequency detected. Need it to be availaible to all functions 00076 //uint16_t flow; // value that will store the flow that is determine 00077 //uint16_t ADC_vortex_frequency_input; // value of the ADC_vortex_frequency_input 00078 //uint16_t Vrefl; // value of the ADC_vortex_frequency_input 00079 00080 00081 int main () 00082 { 00083 /**************** ECEN 5803 add code as indicated ***************/ 00084 // Add code to call timer0 function every 100 uS - Completed already 00085 tick.attach(&timer0, 0.0001); // setup ticker to call timer0 very 100 uS 00086 00087 // already being done in the code below pc.printf("Hello World!\n"); 00088 uint32_t count = 0; 00089 00090 00091 00092 // initialize serial buffer pointers 00093 rx_in_ptr = rx_buf; /* pointer to the receive in data */ 00094 rx_out_ptr = rx_buf; /* pointer to the receive out data*/ 00095 tx_in_ptr = tx_buf; /* pointer to the transmit in data*/ 00096 tx_out_ptr = tx_buf; /* pointer to the transmit out */ 00097 00098 00099 // Print the initial banner 00100 pc.printf("\r\nHello World!\n\n\r"); 00101 00102 /**************** ECEN 5803 add code as indicated ***************/ 00103 // uncomment this section after adding monitor code. - completed 00104 00105 00106 UART_direct_msg_put("\r\nSystem Reset\r\nCode ver. "); 00107 UART_direct_msg_put( CODE_VERSION ); 00108 UART_direct_msg_put("\r\n"); 00109 UART_direct_msg_put( COPYRIGHT ); 00110 UART_direct_msg_put("\r\n"); 00111 00112 set_display_mode(); 00113 00114 00115 //int i=0; // defined and declard i just for main loop duration in seconds 00116 // float main_loop_start_time=0; 00117 // float main_loop_end_time=0; 00118 00119 adc_calibration(); // calibration completed on ADC channel before reading from them 00120 00121 while(1) /// Cyclical Executive Loop 00122 { 00123 //for (;i < 2; i++) { 00124 // main_loop.start(); // start of the cyclical executive loop 00125 count++; // counts the number of times through the loop 00126 // __enable_interrupts(); 00127 // __clear_watchdog_timer(); 00128 00129 /**************** ECEN 5803 add code as indicated ***************/ 00130 // readADC() 00131 read_ADC(CHANNEL_0); // read in the reference low voltage 00132 read_ADC(CHANNEL_1); // read in virtual vortext frequency input on J10_4 00133 read_ADC(CHANNEL_2); // read in temperature from internal temp sensor in Vtemp (mV) 00134 temperature = STANDARD_TEMP-(V_BG*((Vtemp - V_TEMP25)/M)); // calculate the temperature converted in degrees celcius 00135 // calculate frequency 00136 frequency_detect(); 00137 00138 // calculate flow() 00139 calculateFlow(); 00140 00141 serial(); // Polls the serial port 00142 chk_UART_msg(); // checks for a serial port message received 00143 monitor(); // Sends serial port output messages depending 00144 // on commands received and display mode 00145 00146 /**************** ECEN 5803 add code as indicated ***************/ 00147 00148 00149 00150 PwmOutputs_flowmeter(); // use TMP0 channel 3 proporional rate to flow 00151 00152 Pulse_Output_Frequency(); // use TMP0 channel 4 propotional rate to frequency 00153 00154 // LCD_Display() // use the SPI port to send flow number 00155 LCD_Display(); 00156 00157 00158 // End ECEN 5803 code addition 00159 00160 if ((SwTimerIsrCounter & 0x1FFF) > 0x0FFF) 00161 { 00162 flip(); // Blink GREEN LED 00163 } 00164 if (LED_timer_flag == 1){ 00165 00166 rled = !rled; // Blink RED LED with 1 second period 00167 LED_timer_flag =0; 00168 } 00169 // main_loop.stop(); // end of the cyclical executive loop 00170 00171 } 00172 00173 }
Generated on Thu Jul 21 2022 22:29:23 by
1.7.2