Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
nmaududi
Date:
Sat Oct 05 21:17:17 2019 +0000
Parent:
1:9fa7cc80f1a7
Commit message:
revised version for module 4;

Changed in this revision

ADC_input.cpp Show annotated file Show diff for this revision Revisions of this file
Calculate_flow.cpp Show annotated file Show diff for this revision Revisions of this file
Monitor.cpp Show annotated file Show diff for this revision Revisions of this file
SPI_Outputs.cpp Show annotated file Show diff for this revision Revisions of this file
frequency_detector.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
shared.h Show annotated file Show diff for this revision Revisions of this file
--- a/ADC_input.cpp	Fri Oct 04 22:03:30 2019 +0000
+++ b/ADC_input.cpp	Sat Oct 05 21:17:17 2019 +0000
@@ -44,6 +44,7 @@
 #define ADC0_CFG2 (ADC0->CFG2)
 #define ADC0_SC1A (ADC0->SC1[0]) // ADC0 to SC1A
 #define ADC0_SC3 (ADC0->SC3)
+#define ADC0_SC2 (ADC0->SC2)
 #define SIM_SCGC6 (SIM->SCGC6)
 #define CHANNEL_0               (0U)
 #define CHANNEL_1               (1U)
@@ -51,7 +52,82 @@
 
 uint16_t ADC_vortex_frequency_input = 0;
 uint16_t Vrefl = 0;
-uint16_t Vtemp = 0;
+int Vtemp = 0;
+uint16_t counter_frequency_data = 0;
+
+const uint16_t frequency_data[1000] = {
+0x7FFF, 0x8808, 0x900A, 0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 0xC495, 0xCB3B, 0xD196, 0xD79E, 0xDD4D, 0xE29F, 
+0xE78C, 0xEC12, 0xF029, 0xF3D0, 0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 0xFFFF, 0xFFBE, 0xFEFC, 0xFDBA, 
+0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 0xF029, 0xEC12, 0xE78C, 0xE29F, 0xDD4D, 0xD79E, 0xD196, 0xCB3B, 0xC495, 0xBDA9, 
+0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 0x97FB, 0x900A, 0x8808, 0x7FFF, 0x77F6, 0x6FF4, 0x6803, 0x602A, 0x5871, 0x50E0, 
+0x497F, 0x4255, 0x3B69, 0x34C3, 0x2E68, 0x2860, 0x22B1, 0x1D5F, 0x1872, 0x13EC, 0x0FD5, 0x0C2E, 0x08FD, 0x0643, 
+0x0405, 0x0244, 0x0102, 0x0040, 0x0000, 0x0040, 0x0102, 0x0244, 0x0405, 0x0643, 0x08FD, 0x0C2E, 0x0FD5, 0x13EC, 
+0x1872, 0x1D5F, 0x22B1, 0x2860, 0x2E68, 0x34C3, 0x3B69, 0x4255, 0x497F, 0x50E0, 0x5871, 0x602A, 0x6803, 0x6FF4, 
+0x77F6, 0x7FFF, 0x8808, 0x900A, 0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 0xC495, 0xCB3B, 0xD196, 0xD79E, 
+0xDD4D, 0xE29F, 0xE78C, 0xEC12, 0xF029, 0xF3D0, 0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 0xFFFF, 0xFFBE, 
+0xFEFC, 0xFDBA, 0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 0xF029, 0xEC12, 0xE78C, 0xE29F, 0xDD4D, 0xD79E, 0xD196, 0xCB3B, 
+0xC495, 0xBDA9, 0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 0x97FB, 0x900A, 0x8808, 0x7FFF, 0x77F6, 0x6FF4, 0x6803, 0x602A, 
+0x5871, 0x50E0, 0x497F, 0x4255, 0x3B69, 0x34C3, 0x2E68, 0x2860, 0x22B1, 0x1D5F, 0x1872, 0x13EC, 0x0FD5, 0x0C2E, 
+0x08FD, 0x0643, 0x0405, 0x0244, 0x0102, 0x0040, 0x0000, 0x0040, 0x0102, 0x0244, 0x0405, 0x0643, 0x08FD, 0x0C2E, 
+0x0FD5, 0x13EC, 0x1872, 0x1D5F, 0x22B1, 0x2860, 0x2E68, 0x34C3, 0x3B69, 0x4255, 0x497F, 0x50E0, 0x5871, 0x602A, 
+0x6803, 0x6FF4, 0x77F6, 0x7FFF, 0x8808, 0x900A, 0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 0xC495, 0xCB3B, 
+0xD196, 0xD79E, 0xDD4D, 0xE29F, 0xE78C, 0xEC12, 0xF029, 0xF3D0, 0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 
+0xFFFF, 0xFFBE, 0xFEFC, 0xFDBA, 0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 0xF029, 0xEC12, 0xE78C, 0xE29F, 0xDD4D, 0xD79E, 
+0xD196, 0xCB3B, 0xC495, 0xBDA9, 0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 0x97FB, 0x900A, 0x8808, 0x7FFF, 0x77F6, 0x6FF4, 
+0x6803, 0x602A, 0x5871, 0x50E0, 0x497F, 0x4255, 0x3B69, 0x34C3, 0x2E68, 0x2860, 0x22B1, 0x1D5F, 0x1872, 0x13EC, 
+0x0FD5, 0x0C2E, 0x08FD, 0x0643, 0x0405, 0x0244, 0x0102, 0x0040, 0x0000, 0x0040, 0x0102, 0x0244, 0x0405, 0x0643, 
+0x08FD, 0x0C2E, 0x0FD5, 0x13EC, 0x1872, 0x1D5F, 0x22B1, 0x2860, 0x2E68, 0x34C3, 0x3B69, 0x4255, 0x497F, 0x50E0, 
+0x5871, 0x602A, 0x6803, 0x6FF4, 0x77F6, 0x7FFF, 0x8808, 0x900A, 0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 
+0xC495, 0xCB3B, 0xD196, 0xD79E, 0xDD4D, 0xE29F, 0xE78C, 0xEC12, 0xF029, 0xF3D0, 0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 
+0xFEFC, 0xFFBE, 0xFFFF, 0xFFBE, 0xFEFC, 0xFDBA, 0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 0xF029, 0xEC12, 0xE78C, 0xE29F, 
+0xDD4D, 0xD79E, 0xD196, 0xCB3B, 0xC495, 0xBDA9, 0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 0x97FB, 0x900A, 0x8808, 0x7FFF, 
+0x77F6, 0x6FF4, 0x6803, 0x602A, 0x5871, 0x50E0, 0x497F, 0x4255, 0x3B69, 0x34C3, 0x2E68, 0x2860, 0x22B1, 0x1D5F, 
+0x1872, 0x13EC, 0x0FD5, 0x0C2E, 0x08FD, 0x0643, 0x0405, 0x0244, 0x0102, 0x0040, 0x0000, 0x0040, 0x0102, 0x0244, 
+0x0405, 0x0643, 0x08FD, 0x0C2E, 0x0FD5, 0x13EC, 0x1872, 0x1D5F, 0x22B1, 0x2860, 0x2E68, 0x34C3, 0x3B69, 0x4255, 
+0x497F, 0x50E0, 0x5871, 0x602A, 0x6803, 0x6FF4, 0x77F6, 0x7FFF, 0x8808, 0x900A, 0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 
+0xB67F, 0xBDA9, 0xC495, 0xCB3B, 0xD196, 0xD79E, 0xDD4D, 0xE29F, 0xE78C, 0xEC12, 0xF029, 0xF3D0, 0xF701, 0xF9BB, 
+0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 0xFFFF, 0xFFBE, 0xFEFC, 0xFDBA, 0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 0xF029, 0xEC12, 
+0xE78C, 0xE29F, 0xDD4D, 0xD79E, 0xD196, 0xCB3B, 0xC495, 0xBDA9, 0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 0x97FB, 0x900A, 
+0x8808, 0x7FFF, 0x77F6, 0x6FF4, 0x6803, 0x602A, 0x5871, 0x50E0, 0x497F, 0x4255, 0x3B69, 0x34C3, 0x2E68, 0x2860, 
+0x22B1, 0x1D5F, 0x1872, 0x13EC, 0x0FD5, 0x0C2E, 0x08FD, 0x0643, 0x0405, 0x0244, 0x0102, 0x0040, 0x0000, 0x0040, 
+0x0102, 0x0244, 0x0405, 0x0643, 0x08FD, 0x0C2E, 0x0FD5, 0x13EC, 0x1872, 0x1D5F, 0x22B1, 0x2860, 0x2E68, 0x34C3, 
+0x3B69, 0x4255, 0x497F, 0x50E0, 0x5871, 0x602A, 0x6803, 0x6FF4, 0x77F6, 0x7FFF, 0x8808, 0x900A, 0x97FB, 0x9FD4, 
+0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 0xC495, 0xCB3B, 0xD196, 0xD79E, 0xDD4D, 0xE29F, 0xE78C, 0xEC12, 0xF029, 0xF3D0, 
+0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 0xFFFF, 0xFFBE, 0xFEFC, 0xFDBA, 0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 
+0xF029, 0xEC12, 0xE78C, 0xE29F, 0xDD4D, 0xD79E, 0xD196, 0xCB3B, 0xC495, 0xBDA9, 0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 
+0x97FB, 0x900A, 0x8808, 0x7FFF, 0x77F6, 0x6FF4, 0x6803, 0x602A, 0x5871, 0x50E0, 0x497F, 0x4255, 0x3B69, 0x34C3, 
+0x2E68, 0x2860, 0x22B1, 0x1D5F, 0x1872, 0x13EC, 0x0FD5, 0x0C2E, 0x08FD, 0x0643, 0x0405, 0x0244, 0x0102, 0x0040, 
+0x0000, 0x0040, 0x0102, 0x0244, 0x0405, 0x0643, 0x08FD, 0x0C2E, 0x0FD5, 0x13EC, 0x1872, 0x1D5F, 0x22B1, 0x2860, 
+0x2E68, 0x34C3, 0x3B69, 0x4255, 0x497F, 0x50E0, 0x5871, 0x602A, 0x6803, 0x6FF4, 0x77F6, 0x7FFF, 0x8808, 0x900A, 
+0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 0xC495, 0xCB3B, 0xD196, 0xD79E, 0xDD4D, 0xE29F, 0xE78C, 0xEC12, 
+0xF029, 0xF3D0, 0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 0xFFFF, 0xFFBE, 0xFEFC, 0xFDBA, 0xFBF9, 0xF9BB, 
+0xF701, 0xF3D0, 0xF029, 0xEC12, 0xE78C, 0xE29F, 0xDD4D, 0xD79E, 0xD196, 0xCB3B, 0xC495, 0xBDA9, 0xB67F, 0xAF1E, 
+0xA78D, 0x9FD4, 0x97FB, 0x900A, 0x8808, 0x7FFF, 0x77F6, 0x6FF4, 0x6803, 0x602A, 0x5871, 0x50E0, 0x497F, 0x4255, 
+0x3B69, 0x34C3, 0x2E68, 0x2860, 0x22B1, 0x1D5F, 0x1872, 0x13EC, 0x0FD5, 0x0C2E, 0x08FD, 0x0643, 0x0405, 0x0244, 
+0x0102, 0x0040, 0x0000, 0x0040, 0x0102, 0x0244, 0x0405, 0x0643, 0x08FD, 0x0C2E, 0x0FD5, 0x13EC, 0x1872, 0x1D5F, 
+0x22B1, 0x2860, 0x2E68, 0x34C3, 0x3B69, 0x4255, 0x497F, 0x50E0, 0x5871, 0x602A, 0x6803, 0x6FF4, 0x77F6, 0x7FFF, 
+0x8808, 0x900A, 0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 0xC495, 0xCB3B, 0xD196, 0xD79E, 0xDD4D, 0xE29F, 
+0xE78C, 0xEC12, 0xF029, 0xF3D0, 0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 0xFFFF, 0xFFBE, 0xFEFC, 0xFDBA, 
+0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 0xF029, 0xEC12, 0xE78C, 0xE29F, 0xDD4D, 0xD79E, 0xD196, 0xCB3B, 0xC495, 0xBDA9, 
+0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 0x97FB, 0x900A, 0x8808, 0x7FFF, 0x77F6, 0x6FF4, 0x6803, 0x602A, 0x5871, 0x50E0, 
+0x497F, 0x4255, 0x3B69, 0x34C3, 0x2E68, 0x2860, 0x22B1, 0x1D5F, 0x1872, 0x13EC, 0x0FD5, 0x0C2E, 0x08FD, 0x0643, 
+0x0405, 0x0244, 0x0102, 0x0040, 0x0000, 0x0040, 0x0102, 0x0244, 0x0405, 0x0643, 0x08FD, 0x0C2E, 0x0FD5, 0x13EC, 
+0x1872, 0x1D5F, 0x22B1, 0x2860, 0x2E68, 0x34C3, 0x3B69, 0x4255, 0x497F, 0x50E0, 0x5871, 0x602A, 0x6803, 0x6FF4, 
+0x77F6, 0x7FFF, 0x8808, 0x900A, 0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 0xC495, 0xCB3B, 0xD196, 0xD79E, 
+0xDD4D, 0xE29F, 0xE78C, 0xEC12, 0xF029, 0xF3D0, 0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 0xFFFF, 0xFFBE, 
+0xFEFC, 0xFDBA, 0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 0xF029, 0xEC12, 0xE78C, 0xE29F, 0xDD4D, 0xD79E, 0xD196, 0xCB3B, 
+0xC495, 0xBDA9, 0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 0x97FB, 0x900A, 0x8808, 0x7FFF, 0x77F6, 0x6FF4, 0x6803, 0x602A, 
+0x5871, 0x50E0, 0x497F, 0x4255, 0x3B69, 0x34C3, 0x2E68, 0x2860, 0x22B1, 0x1D5F, 0x1872, 0x13EC, 0x0FD5, 0x0C2E, 
+0x08FD, 0x0643, 0x0405, 0x0244, 0x0102, 0x0040, 0x0000, 0x0040, 0x0102, 0x0244, 0x0405, 0x0643, 0x08FD, 0x0C2E, 
+0x0FD5, 0x13EC, 0x1872, 0x1D5F, 0x22B1, 0x2860, 0x2E68, 0x34C3, 0x3B69, 0x4255, 0x497F, 0x50E0, 0x5871, 0x602A, 
+0x6803, 0x6FF4, 0x77F6, 0x7FFF, 0x8808, 0x900A, 0x97FB, 0x9FD4, 0xA78D, 0xAF1E, 0xB67F, 0xBDA9, 0xC495, 0xCB3B, 
+0xD196, 0xD79E, 0xDD4D, 0xE29F, 0xE78C, 0xEC12, 0xF029, 0xF3D0, 0xF701, 0xF9BB, 0xFBF9, 0xFDBA, 0xFEFC, 0xFFBE, 
+0xFFFF, 0xFFBE, 0xFEFC, 0xFDBA, 0xFBF9, 0xF9BB, 0xF701, 0xF3D0, 0xF029, 0xEC12, 0xE78C, 0xE29F, 0xDD4D, 0xD79E, 
+0xD196, 0xCB3B, 0xC495, 0xBDA9, 0xB67F, 0xAF1E, 0xA78D, 0x9FD4, 0x97FB, 0x900A, 0x8808, 0x7FFF, 0x77F6, 0x6FF4, 
+0x6803, 0x602A, 0x5871, 0x50E0, 0x497F, 0x4255, 0x3B69, 0x34C3, 0x2E68, 0x2860, 0x22B1, 0x1D5F, 0x1872, 0x13EC, 
+0x0FD5, 0x0C2E, 0x08FD, 0x0643, 0x0405, 0x0244, 0x0102, 0x0040, 0x0000, 0x0040, 0x0102, 0x0244, 0x0405, 0x0643, 
+0x08FD, 0x0C2E, 0x0FD5, 0x13EC, 0x1872, 0x1D5F, 0x22B1, 0x2860, 0x2E68, 0x34C3, 0x3B69, 0x4255, 0x497F, 0x50E0, 
+0x5871, 0x602A, 0x6803, 0x6FF4, 0x77F6};
 
 AnalogIn Vref_low(ch0);
 
@@ -158,7 +234,16 @@
   ADC0_SC1A = 14 & ADC_SC1_ADCH_MASK; // ADC0_SE9 that is connected to PTB1
   ADC0_SC1A = 0 & ADC_SC1_DIFF_MASK; //0 Single-ended conversions and input channels are selected.
                               
-    ADC_vortex_frequency_input = (vortex_frequency.read_u16());
+        if (counter_frequency_data<999)
+        {
+        ADC_vortex_frequency_input = (vortex_frequency.read_u16()) + frequency_data[counter_frequency_data];
+        counter_frequency_data++;
+        }
+        else
+        {
+          counter_frequency_data = 0;
+          ADC_vortex_frequency_input = (vortex_frequency.read_u16()) + frequency_data[counter_frequency_data];  
+            }
         
     } else 
     {
@@ -181,11 +266,15 @@
     
 
   ADC0_SC3 = 1 & ADC_SC3_ADCO_MASK; // set to 1 for continuious conversion, 0 for only 1 set of conversions
-
+     
+  PMC->REGSC = (1 & PMC_REGSC_BGBE_MASK); // NEED to be set for meseauring temperature sensor
   ADC0_SC1A = 26 & ADC_SC1_ADCH_MASK; // temperature sensor (reading in value from internal sensor) V
-  ADC0_SC1A = 0 & ADC_SC1_DIFF_MASK; //0 Single-ended conversions and input channels are selected.
+  ADC0_SC1A = 1 & ADC_SC1_DIFF_MASK; //0 Single-ended conversions and input channels are selected.
+    while(!(ADC0_SC1A & ADC_SC1_COCO_MASK)); // Run until the conversion is complete
+
                       
     Vtemp =  (TempSensor.read_u16());
+    //Vtemp = ADC0-> R[0];
     }
 
     
--- a/Calculate_flow.cpp	Fri Oct 04 22:03:30 2019 +0000
+++ b/Calculate_flow.cpp	Sat Oct 05 21:17:17 2019 +0000
@@ -34,7 +34,7 @@
 
 
 #include "shared.h" 
-//#include <math.h>
+#include <math.h>
 
 #define BLUFF_BODY_INCHES (0.5)
 #define BLUFF_BODY_METERS (0.0127)
@@ -86,20 +86,15 @@
     float density = 0;
     float viscosity = 0;
 
-    while (velocity_dif > 0.01)
+    while (velocity_dif > 0.01 && !isnan(velocity_dif))
     {
         velocity_prev = velocity;
         viscosity = calculateViscosity(temperature);
-        //printf("viscosity: %f\r\n", viscosity);
         density = calculateDensity(temperature);
-        //printf("density: %f\r\n", density);
         reynoldsNumber = calculateReynoldsNumber(density, viscosity, velocity_prev);
-        //printf("reynoldsNumber: %f\r\n", reynoldsNumber);
         strouhalNumber = calculateStrouhalNumber(reynoldsNumber);
-        //printf("strouhalNumber: %f\r\n", strouhalNumber);
         velocity = calculateVelocity(freq_value, strouhalNumber);
         velocity_dif = fabs((velocity - velocity_prev)/(velocity + velocity_prev));
-        //printf("velocity: %f\r\n", velocity);
     }
 
     flow =  (2.45 * PID_INCHES_SQUARED * velocity);
--- a/Monitor.cpp	Fri Oct 04 22:03:30 2019 +0000
+++ b/Monitor.cpp	Sat Oct 05 21:17:17 2019 +0000
@@ -50,12 +50,6 @@
 *******************************************************************************/
 
 
-#define NUMBER_OF_REGISTERS (16)
-#define NUM_ADDR_TO_PRINT (5)
-#define MEMORY_STARTING_ADDR (0x200)
-
-extern UCHAR error_count;
-
 
 __asm uint32_t getregister(uint32_t x){
    
@@ -89,8 +83,8 @@
     BEQ return_from_function_r13
     CMP r0,#14;
     BEQ return_from_function_r14
-    CMP r0,#15;
-    BEQ return_from_function_r15
+   // CMP r0,#15;
+   // BEQ return_from_function_r15
     
 return_from_function_r0
     MOV r0,r0 ; store the return value in r0
@@ -137,9 +131,10 @@
 return_from_function_r14
     MOV r0,r14 ; store the return value in r0
     BLX  lr            ; Else return from subroutine with link and returning the value of register
-return_from_function_r15
-    MOV r0,r15 ; store the return value in r0
-    BLX  lr            ; Else return from subroutine with link and returning the value of register
+//return_from_function_r15
+    
+    //  MOV r0,15 ; store the return value in r0
+   // BLX  lr            ; Else return from subroutine with link and returning the value of register
 }
 
 __asm uint32_t getregister0(void){
@@ -228,12 +223,12 @@
 {
    UCHAR chr,err=0;
 //   unsigned char  data;
-    chr = msg_buf[0];
 
 
-
-    switch( chr ) 
-    {
+   if( (chr = msg_buf[0]) <= 0x60 ) 
+   {      // Upper Case
+      switch( chr ) 
+      {
          case 'D':
             if((msg_buf[1] == 'E') && (msg_buf[2] == 'B') && (msg_buf_idx == 3)) 
             {
@@ -278,8 +273,17 @@
                 
          default:
             err = 1;
-    }
+      }
+   }
 
+   else 
+   {                                 // Lower Case
+      switch( chr ) 
+      {
+        default:
+         err = 1;
+      }
+   }
 
    if( err == 1 )
    {
@@ -341,17 +345,16 @@
          {
             if (display_flag == 1)
             {                       // resets and sets continous receive enable bit
-               UART_direct_msg_put("\r\nNORMAL ");
+               UART_msg_put("\r\nNORMAL ");
                UART_direct_msg_put(" Flow: ");
-               // ECEN 5803 add code as indicated
-               //  add flow data output here, use UART_hex_put or similar for 
-               // numbers
+               // ECEN 5803 add code as indicated               
+                            //UART_direct_hex_put(flow);
                UART_direct_msg_put(" Temp: ");
-               //  add flow data output here, use UART_hex_put or similar for 
-               // numbers
+               // ECEN 5803 add code as indicated                           
+              // UART_direct_hex_put(temperature);
                UART_direct_msg_put(" Freq: ");
-               //  add flow data output here, use UART_hex_put or similar for 
-               // numbers
+               // ECEN 5803 add code as indicated                           
+                            //UART_direct_hex_put(frequency);
                display_flag = 0;
             }
          }  
@@ -362,16 +365,18 @@
             {
                UART_direct_msg_put("\r\nDEBUG ");
                UART_direct_msg_put(" Flow: ");
-               // ECEN 5803 add code as indicated               
-               //  add flow data output here, use UART_hex_put or similar for 
-               // numbers
+               // ECEN 5803 add code as indicated 
+                UART_direct_hex_put(flow);
+                UART_direct_msg_put(" ");      
+              // ECEN 5803 add code as indicated         
                UART_direct_msg_put(" Temp: ");
-               //  add flow data output here, use UART_hex_put or similar for 
-               // numbers
+               // ECEN 5803 add code as indicated                           
+               UART_direct_hex_put(temperature);
+                UART_direct_msg_put(" ");
                UART_direct_msg_put(" Freq: ");
-               //  add flow data output here, use UART_hex_put or similar for 
-               // numbers
-               
+               // ECEN 5803 add code as indicated                           
+               UART_direct_hex_put_word(freq_value);
+                UART_direct_msg_put(" ");
                
  /****************      ECEN 5803 add code as indicated   ***************/             
                //  Create a display of  error counts, sensor states, and
@@ -380,66 +385,62 @@
               /*     Define varables to store registers*/
               /**********************************/
                             //Assembly language call to function to get ARM registers (R0-R15)
-                
-                uint32_t registers[NUMBER_OF_REGISTERS] = {};
-                char c = '0';
-                    
-                UART_direct_msg_put("\r\nARM REGISTERS[R0-R15]:\r\n");
-                
-                for (uint8_t i = 0; i < NUMBER_OF_REGISTERS; i++)
-                {
-                    /* get register value */
-                    if (i == 0)
-                    {
-                        registers[i] = getregister0();
-                    } else
-                    {
-                        registers[i] = getregister(i);
-                    }
-                    
-                    /* start printing */
-                    UART_direct_msg_put("Register R");
-                    
-                    /* Print the register number using char c. If we're printing registers 10-15,
-                       we will need to print a leading 1. */
-                    if (i > 9)
-                    {
-                        UART_put('1');
-                    }
-                    UART_put(c);
-                    
-                    /* finish printing the message */
-                    UART_direct_msg_put(": ");
-                    UART_direct_hex_put_word(registers[i]);
-                    UART_direct_msg_put("\r\n");
-                    
-                    /* increment c to display the next register number. If greater than 9, rollover to 0 */
-                    c++;
-                    if (c > '9')
-                    {
-                        c = '0';
-                    }
-                }
-                
-                /* display error count */
-                UART_direct_msg_put("\r\nerror count: ");
-                UART_hex_put(error_count);
-                UART_direct_msg_put("\r\n\n");
+
+             uint32_t register0 = getregister0();
+                         uint32_t register1 = getregister(1);
+                         uint32_t register2 = getregister(2);
+                         uint32_t register3 = getregister(3);
+                         uint32_t register4 = getregister(4);
+                         uint32_t register5 = getregister(5);
+                         uint32_t register6 = getregister(6);
+                         uint32_t register7 = getregister(7);
+                         uint32_t register8 = getregister(8);
+                         uint32_t register9 = getregister(9);
+                         uint32_t register10 = getregister(10);
+                         uint32_t register11 = getregister(11);
+                         uint32_t register12 = getregister(12);
+                         uint32_t register13 = getregister(13);
+                         uint32_t register14 = getregister(14);
+                         //uint32_t register15 = getregister(15); // Write code to get register 15
+                         // Display registers
+                         UART_direct_msg_put("\r\nARM REGISTERS[R0-R15]:");
+                         UART_direct_msg_put("\r\nREGISTER0:");
+                         UART_direct_hex_put_word(register0); 
+                         UART_direct_msg_put("\r\nREGISTER1:");
+                       UART_direct_hex_put_word(register1);             
+                         UART_direct_msg_put("\r\nREGISTER2:");
+                       UART_direct_hex_put_word(register2);                          
+                         UART_direct_msg_put("\r\nREGISTER3:");
+                       UART_direct_hex_put_word(register3);                                 
+                         UART_direct_msg_put("\r\nREGISTER4:");
+                       UART_direct_hex_put_word(register4);
+                         UART_direct_msg_put("\r\nREGISTER5:");
+                       UART_direct_hex_put_word(register5);                         
+                         UART_direct_msg_put("\r\nREGISTER6:");
+                       UART_direct_hex_put_word(register6);                              
+                         UART_direct_msg_put("\r\nREGISTER7:");
+                       UART_direct_hex_put_word(register7);                                 
+                         UART_direct_msg_put("\r\nREGISTER8:");
+                       UART_direct_hex_put_word(register8);
+                         UART_direct_msg_put("\r\nREGISTER9:");
+                       UART_direct_hex_put_word(register9);                 
+                         UART_direct_msg_put("\r\nREGISTER10:");
+                       UART_direct_hex_put_word(register10);                    
+                         UART_direct_msg_put("\r\nREGISTER11:");
+                       UART_direct_hex_put_word(register11);    
+                         UART_direct_msg_put("\r\nREGISTER12:");
+                       UART_direct_hex_put_word(register12);    
+                         UART_direct_msg_put("\r\nREGISTER13:");
+                       UART_direct_hex_put_word(register13);
+                         UART_direct_msg_put("\r\nREGISTER14:");
+                       UART_direct_hex_put_word(register14);    
+                         //UART_direct_msg_put("\r\nREGISTER15:");
+                       //UART_hex_put(register15);                           
 
                             
-                /* Create a command to read a section of Memory and display it */
-                uint32_t *memory_ptr = (uint32_t*)MEMORY_STARTING_ADDR; /* create a pointer to reference memory  */
-                UART_direct_msg_put("Reading data from memory:\r\n");
-                for (uint8_t i = 0; i < NUM_ADDR_TO_PRINT; i++)
-                {
-                    UART_direct_msg_put("Address: ");
-                    UART_direct_hex_put_word((uint32_t)memory_ptr); /* print address */
-                    UART_direct_msg_put("\tData: ");
-                    UART_direct_hex_put_word(*memory_ptr); /* print data at address */
-                    UART_direct_msg_put("\r\n");
-                    memory_ptr++;
-                }
-                UART_direct_msg_put("\r\n");
+              //  Create a command to read a section of Memory and display it
+               
+                                //int32_t *memory_ptr; /* pointer store the address in memory to display */
                              
                             
                //  Create a command to read 16 words from the current stack 
@@ -457,4 +458,5 @@
          UART_msg_put("Mode Error");
       }  
    }
-}
\ No newline at end of file
+}  
+
--- a/SPI_Outputs.cpp	Fri Oct 04 22:03:30 2019 +0000
+++ b/SPI_Outputs.cpp	Sat Oct 05 21:17:17 2019 +0000
@@ -36,25 +36,35 @@
 #include "shared.h" 
 #include "MKL25Z4.h"
 #define SPI_bit_length 16 // bit length for the spi port
-#define SPI_mode 0 // clock is set to trigger at high and in phase
-
-
+#define SPI_mode 3 // clock is set to trigger at high and in phase
+#define SPIx_C1 (SPI0->C1)
+#define SPIx_C2 (SPI0->C2)
+#define SPIx_BR (SPI0->BR)
+#define SPIx_S (SPI0->S)
 
 /**********************/
 
-PinName const SPI_MOSI = PTC6;  // channel 0 (PTB0) to A/D pin VREFL
-PinName const SPI_MISO = PTC7; // channel 1 (PTB1) to J10_4 a virtual vortex frequency input,
-PinName const SPI_SCK = PTC5; // channel 2 (PTB2) to an actual internal TempSensor
-
+PinName const SPI_MOSI = PTC6;  // Master out slave in signal for SPI to feed into LCD
+PinName const SPI_MISO = PTC7; // Master in slave out, reading signal from LCD back to the controller
+PinName const SPI_SCK = PTC5; // clock signal to synchronize the data for SPI communication
+//PinName const SPI_CS = PTC4; // Chip select if you have muliple slaves
 
 void LCD_Display(void){
     
-SPI LCD(SPI_MOSI, SPI_MISO, SPI_SCK);
-LCD.lock(); // Acquire exclusive access to this SPI bus.
-LCD.format(SPI_bit_length, SPI_mode); // select correct mode and bits to transfer to the LDC monitor
-LCD.write(flow); // write the value of flow to slave device, which is the peripheral LCD display
-LCD.write(freq_value); //    write the value of frequency to slave device, which is the peripheral LCD display
-LCD.write(temperature); //  write the value of temperature to slave device, which is the peripheral LCD display
-}
+ SPIx_C1= (0x54);
+ SPIx_C2= (0x00);
+ SPIx_BR = (0x00);
+ 
+    
+  SPI LCD(SPI_MOSI, SPI_MISO, SPI_SCK);
+  LCD.lock(); // Acquire exclusive access to this SPI bus.
+  LCD.format(SPI_bit_length, SPI_mode); // select correct mode and bits to transfer to the LDC monitor
+ // while(SPIx_S & SPI_S_SPTEF_MASK);  // wait for the value equal tot 1
+  LCD.write(flow); // write the value of flow to slave device, which is the peripheral LCD display
+  //while(SPIx_S & SPI_S_SPTEF_MASK);  // wait for the value equal tot 1
+  LCD.write(freq_value); //    write the value of frequency to slave device, which is the peripheral LCD display
+ // while(SPIx_S & SPI_S_SPTEF_MASK);  // wait for the value equal tot 1
+ LCD.write(temperature); //  write the value of temperature to slave device, which is the peripheral LCD display
+ }
 
 
--- a/frequency_detector.cpp	Fri Oct 04 22:03:30 2019 +0000
+++ b/frequency_detector.cpp	Sat Oct 05 21:17:17 2019 +0000
@@ -35,6 +35,7 @@
 
 #include "shared.h" 
 
+
 #ifdef __cplusplus 
 extern "C" {
 #endif
@@ -42,15 +43,17 @@
 /*   Definitions     */
 /**********************/
 
-extern uint16_t zero_detect_counter = 0; // initialize the value to zero
-extern UCHAR sample_count =0; // intialize sample count to zero
-extern uint32_t frequency_buffer[10] = {0,0,0,0,0,0,0,0,0,0};
+extern double zero_detect_counter = 0; // initialize the value to zero
+extern double sample_count =0; // intialize sample count to zero
+extern double frequency_buffer[10] = {0,0,0,0,0,0,0,0,0,0};
+//extern double test_value = 0;
 extern UCHAR frequency_buffer_count = 0;
 extern UCHAR reset_counter_flag = 0;
 extern UCHAR current_bool_value =1; // trigger for zero detection within the code
 extern UCHAR last_bool_value = 1; // trigger for zero detection within the code
+extern double SAMPLES_SECOND = 0.0001;
 
-uint16_t freq_value = 0;
+extern uint16_t freq_value = 0;
 
     
 #ifdef __cplusplus
@@ -64,13 +67,15 @@
 void frequency_detect(void)
 {  int32_t i;
     
-   if(reset_counter_flag==1)
-         {
-       zero_detect_counter = 0; // reset the value of counter each 800us has passed, want to attain the moving average(fed from timer0.cpp)
-         reset_counter_flag=0; // set reset flag back to 0
-    }
+  // if(reset_counter_flag == 1)
+ //        {
+ //      zero_detect_counter = 0; // reset the value of counter each 800us has passed, want to attain the moving average(fed from timer0.cpp)
+  //       reset_counter_flag=0; // set reset flag back to 0
+ //   }
+ 
 
-      if(ADC_vortex_frequency_input<=0) 
+
+      if(ADC_vortex_frequency_input <=(0)) 
           {
              current_bool_value =0; // negative values set to 0
           }
@@ -83,16 +88,17 @@
         {
    last_bool_value = current_bool_value;
    zero_detect_counter = zero_detect_counter+1;
-            
-     if ((frequency_buffer_count<10) && (zero_detect_counter>=2))
+  
+     if ((frequency_buffer_count<9) && (zero_detect_counter>=2))
      {
-         frequency_buffer[frequency_buffer_count]  = ((zero_detect_counter-1)/((sample_count)*(SAMPLES_SECOND)))/2;
+         frequency_buffer[frequency_buffer_count]  = ((zero_detect_counter)/((sample_count)*(SAMPLES_SECOND)))/10;
              frequency_buffer_count = frequency_buffer_count+1;
+             zero_detect_counter = 0;
      }
     else 
         {
-            frequency_buffer_count = 1;
-    }
+            frequency_buffer_count = 0;
+     }
    
     }
     
@@ -108,22 +114,22 @@
         sample_count = 1; // needed to not divide by zero
     }
 
-        uint16_t sum_frequency_buffer= 0;
+        double sum_frequency_buffer= 0;
 
-        for(i = 1; i < 10; ++i)
+        for(i = 0; i < 10; ++i)
     {
         sum_frequency_buffer += frequency_buffer[i];
     }
         
-        if ((sum_frequency_buffer/9)>3000)
+        if ((sum_frequency_buffer/10)>3000)
         {
             freq_value = 0;
         }
     else
         {
-           freq_value = sum_frequency_buffer/9;
+           freq_value = sum_frequency_buffer/10;
         }
-
+        
 }
 
 
--- a/main.cpp	Fri Oct 04 22:03:30 2019 +0000
+++ b/main.cpp	Sat Oct 05 21:17:17 2019 +0000
@@ -128,17 +128,7 @@
 //      __enable_interrupts();
 //      __clear_watchdog_timer();
 
-   /****************      ECEN 5803 add code as indicated   ***************/
-                //  readADC()
-   read_ADC(CHANNEL_0); // read in the reference low voltage
-     read_ADC(CHANNEL_1); // read in virtual vortext frequency input on J10_4
-     read_ADC(CHANNEL_2); // read in temperature from internal temp sensor in Vtemp (mV)
-   temperature = STANDARD_TEMP-(V_BG*((Vtemp - V_TEMP25)/M)); // calculate the temperature converted in degrees celcius
-// calculate frequency
-        frequency_detect();
 
-//  calculate flow()
-    calculateFlow();
             
         serial();            // Polls the serial port
         chk_UART_msg();     // checks for a serial port message received
@@ -147,14 +137,24 @@
             
  /****************      ECEN 5803 add code as indicated   ***************/
 
+   /****************      ECEN 5803 add code as indicated   ***************/
+                //  readADC()
+   read_ADC(CHANNEL_0); // read in the reference low voltage
+     read_ADC(CHANNEL_1); // read in virtual vortext frequency input on J10_4
+     read_ADC(CHANNEL_2); // read in temperature from internal temp sensor in Vtemp (mV)
+  temperature = STANDARD_TEMP-(V_BG*((Vtemp*10 - V_TEMP25)/M)); // calculate the temperature converted in degrees celcius
+//calculate frequency
+       frequency_detect();   
 
+//  calculate flow()
+  calculateFlow();
 
   PwmOutputs_flowmeter();  // use TMP0 channel 3  proporional rate to flow
 
-  Pulse_Output_Frequency();  // use TMP0 channel 4  propotional rate to frequency
+ Pulse_Output_Frequency();  // use TMP0 channel 4  propotional rate to frequency
 
-//  LCD_Display()   // use the SPI port to send flow number
-   LCD_Display();
+ // use the SPI port to send flow number
+  //LCD_Display();
 
 
 //  End ECEN 5803 code addition
@@ -163,11 +163,11 @@
         {
             flip();  // Blink GREEN LED
         }
-                if (LED_timer_flag == 1){
+        if (LED_timer_flag == 1){
                     
                     rled = !rled; // Blink RED LED with 1 second period
                     LED_timer_flag =0;
-                }
+         }
     //       main_loop.stop(); // end of the cyclical executive loop
                 
 }
--- a/mbed.bld	Fri Oct 04 22:03:30 2019 +0000
+++ b/mbed.bld	Sat Oct 05 21:17:17 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file
--- a/shared.h	Fri Oct 04 22:03:30 2019 +0000
+++ b/shared.h	Sat Oct 05 21:17:17 2019 +0000
@@ -41,7 +41,6 @@
 
 #define TIMER0 TMR0
 #define SEC 10000           /* 10000 timer0 interrupts per second (100 usec.) */
-#define SAMPLES_SECOND 1/SEC  /* # of seoconds between sample used in frequency detection (100 usec.) */
                    
 #define T100MS 0.1*SEC
 #define T2S    2*SEC
@@ -81,11 +80,13 @@
  extern UCHAR *tx_out_ptr; /*pointer to the transmit out */    
  extern uint16_t ADC_buffer;    // value that ADC will read in, need to be external so that flow function can read in
  extern uint16_t temperature; // value that will be external to all variable. stores the value of temperature
- extern uint16_t Vtemp; // value in mV of the temperature calculated
+ extern int Vtemp; // value in mV of the temperature calculated
  extern uint16_t freq_value; // value that will store the frequency detected. Need it to be availaible to all functions
  extern uint16_t flow; // value that will store the flow that is determine
  extern uint16_t ADC_vortex_frequency_input; // value of the ADC_vortex_frequency_input
  extern uint16_t Vrefl; // value of the ADC_vortex_frequency_input
+ extern double zero_detect_counter;
+ extern UCHAR reset_counter_flag;
 
 #define RX_BUF_SIZE 10            /* size of receive buffer in bytes */
 #define TX_BUF_SIZE 10          /* size of transmit buffer in bytes */