Library to Capture the +ve and -ve Pulsewidth of a signal

Dependents:   PulseWidthCapture_Program

Files at this revision

API Documentation at this revision

Comitter:
Ellor1
Date:
Thu Dec 11 08:59:09 2014 +0000
Parent:
1:6bb38ae2e503
Commit message:
Pulse Width Capture;

Changed in this revision

PulseWidthCapture.cpp Show annotated file Show diff for this revision Revisions of this file
PulseWidthCapture.h Show annotated file Show diff for this revision Revisions of this file
diff -r 6bb38ae2e503 -r 857c3c8e7a2f PulseWidthCapture.cpp
--- a/PulseWidthCapture.cpp	Wed Dec 10 10:33:32 2014 +0000
+++ b/PulseWidthCapture.cpp	Thu Dec 11 08:59:09 2014 +0000
@@ -1,18 +1,37 @@
+ /* mbed Library - PulseWidthCapture
+ * Copyright (c) 2014
+ * released under MIT license http://mbed.org/licence/mit
+ */
+/***********************************************************************//**
+ * @file        PulseWidthCapture.cpp
+ * @brief       cpp file for the PulseWidthCapture library. 
+ * @version     0.0
+ * @date        03 Dec 2014
+ * @author      Callum Ellor
+ **************************************************************************/
+/***************************************************************************
+ * Revision     Date        Comments
+ *----------    --------    -----------------------------------------------
+ *
+ *  0.0         03/12/14    Initial creation
+ ***************************************************************************/
+
 #include "mbed.h"
 #include "TextLCD_16x4.h"
 #include "USBSerial.h"
-#include "PulseWidthCapture/PulseWidthCapture.h"
-#include "rtos.h"
+#include "PulseWidthCapture.h"
 
-USBSerial serial;
+//USBSerial serial;
 TextLCD lcd(P0_21, P0_20, P1_15, P0_19, P0_5, P0_4, TextLCD::LCD16x4); // rs, e, d4, d5, d6, d7
 
+/*Status Led's to check that program is entering ISR's   */
+
 DigitalOut led(P0_9);
 DigitalOut led2(P0_8);
-DigitalOut led3(P0_7);
+//DigitalOut led3(P0_7);
 DigitalOut led4(P0_17);
 
-//AnalogIn Ain(P0_11);
+AnalogIn Ain(P0_11);
 
 Capture *Capture::instance;
 
@@ -22,75 +41,78 @@
   * @param      None   Uses P0_12 as the Capture input (Pin 16)
  * @return      None
  **********************************************************************/
-Capture::Capture(void)
+Capture::Capture(void)          //Capture Constructor
 {       
-    /* Set up clock and power, using default peripheral system clock divider */   
-    LPC_SYSCON->SYSAHBCLKCTRL |=   CT32B0_CLK_ENABLE; // See page 30 of the 11U24 User Guide
-    // Check the clock divider ratio by reading   LPC_SYSCON->SYSAHBCLKDIV ls byte
-    
-    LPC_SYSCON->SYSAHBCLKCTRL |=   CT32B1_CLK_ENABLE; 
+
+    /* Configure registers */
+
+    /* Set up clock and power, using default peripheral system clock divider */  // See page 30 of the 11U24 User Guide 
     
-    LPC_SYSCON->SYSAHBCLKCTRL |=   CT16B0_CLK_ENABLE;
-    
-    LPC_CT32B0->PR  =  0;                           // Prescale counter divide by ...
-    LPC_CT32B1->PR  =  0;
-    LPC_CT16B0->PR  =  1000;             //
-       
-    /* Configure IOCON for the proper function of the capture pin. Use a pull-up.     */
-    LPC_IOCON->PIO1_29 = (CT32B0_CAP1); // See page 125 of the 11U24 User Guide   
+    LPC_SYSCON->SYSAHBCLKCTRL |=   CT32B0_CLK_ENABLE; // setup 32 bit Timer 0 Clock
         
-    LPC_IOCON->TMS_PIO0_12 = CT32B1_CAP0 | ADMODE;
-                 
-    // Select the capture edge and int mode
-    LPC_CT32B0->CCR =   CCR_CAP1RE  | CCR_CAP1I;    // Select inputs and interrupts.
+    LPC_SYSCON->SYSAHBCLKCTRL |=   CT32B1_CLK_ENABLE; // setup 32 bit Timer 1 Clock
+    
+    LPC_SYSCON->SYSAHBCLKCTRL |=   CT16B0_CLK_ENABLE; // setup 16 bit Timer 0 Clock
     
-    LPC_CT32B1->CCR =   CCR_CAP0FE  | CCR_CAP0I;
+    LPC_CT32B0->PR  =  0;                           // set Prescale to 0 to use 48MHz Clock
+    LPC_CT32B1->PR  =  0;                           // set Prescale to 0 to use 48MHz Clock
+    LPC_CT16B0->PR  =  1000;                        // set Prescale to 1000 to use 48KHz Clock
+       
+    /* Configure IOCON for the proper function of the capture pin. Setup PIO1_29 for Capture */
+    LPC_IOCON->PIO1_29 = (CT32B0_CAP1); // See page 125 of the 11U24 User Guide   
+      
+    /* Configure IOCON. Setup TMS_PIO0_12 for Capture mode, also set up for Digital Function mode */     
+    LPC_IOCON->TMS_PIO0_12 = CT32B1_CAP0 | ADMODE; // See page 94 of the 11U24 User Guide
+                     
+    // Select the capture edge and interrupt mode
+    /* will start capturing on the rising edge of CT32B0_CAP1 (P1_29) will also generate an interrupt */
+    LPC_CT32B0->CCR =   CCR_CAP1RE  | CCR_CAP1I;    // See page 357 of the 11U24 User Guide 
+    
+    /* will start capturing on the falling edge of CT32B1_CAP0 (TMS_P0_12) will also generate an interrupt */
+    LPC_CT32B1->CCR =   CCR_CAP0FE  | CCR_CAP0I;    // See page 356 of the 11U24 User Guide 
 
-    LPC_CT16B0->MCR =   CT16B0_MR0I | CT16B0_MR0R;
+    /* Setup match register for 16 bit timer. will interrupt when value in MR0 matches the value in the Timer Counter TC
+    will also reset the timer TC when the value in MR0 is matched*/
   
-    // Set up the rising edge clear, using timer mode
-    LPC_CT32B0->CTCR = CT32B0_CTCR_CTM_TIMER | CT32B0_CTCR_ENCC | CT32B0_CTCR_SEICC_CAP1FE;
+    LPC_CT16B0->MCR =   CT16B0_MR0I | CT16B0_MR0R;  // See page 337 of the 11U24 User Guide 
+  
+    // Set up the Count Control Register for Timer mode, and to clear the timer on a falling edge
+    LPC_CT32B0->CTCR = CT32B0_CTCR_CTM_TIMER | CT32B0_CTCR_ENCC | CT32B0_CTCR_SEICC_CAP1FE; // See page 361 of the 11U24 User Guide 
     
-   // clear timer on falling edge
-    LPC_CT32B1->CTCR = CT32B1_CTCR_CTM_TIMER | CT32B1_CTCR_ENCC | CT32B1_CTCR_SEICC_CAP0RE;
+   // Set up the Count Control Register for Timer mode, and to clear the timer on a rising edge
+    LPC_CT32B1->CTCR = CT32B1_CTCR_CTM_TIMER | CT32B1_CTCR_ENCC | CT32B1_CTCR_SEICC_CAP0RE;// See page 362 of the 11U24 User Guide 
                
-   // Clear interrupt flag
-    LPC_CT32B0->IR = CT32B0_IR_CR1INT;                
+   // Clear interrupt flags
+    LPC_CT32B0->IR = CT32B0_IR_CR1INT;      // See page 353 of the 11U24 User Guide            
     
-    LPC_CT32B1->IR = CT32B1_IR_CR0INT; 
+    LPC_CT32B1->IR = CT32B1_IR_CR0INT;      // See page 353 of the 11U24 User Guide 
     
-    LPC_CT16B0->IR = CT16B0_IR_MR0INT; 
+    LPC_CT16B0->IR = CT16B0_IR_MR0INT;      // See page 335 of the 11U24 User Guide 
     
 
     //* Attach IRQ
-    instance = this;
-    NVIC_SetVector(TIMER_32_0_IRQn, (uint32_t)&_Captureisr1);     
-    NVIC_SetVector(TIMER_32_1_IRQn, (uint32_t)&_Captureisr2); 
-    NVIC_SetVector(TIMER_16_0_IRQn, (uint32_t)&_Captureisr3);
+    instance = this; 
+    NVIC_SetVector(TIMER_32_0_IRQn, (uint32_t)&_Fall_ISR);    //setuip ISR's
+    NVIC_SetVector(TIMER_32_1_IRQn, (uint32_t)&_Rise_ISR); 
+    NVIC_SetVector(TIMER_16_0_IRQn, (uint32_t)&_Wait_ISR);
 
 }
 
 /*********************************************************************//**
- * @brief        Start capturing data. Average the specified number of samples. 
- * @param        (int) numsamples    Log base 2 of the number of samples to be averaged
- * @return        None
+ * @brief        Start capturing data. Enable 32 Bit Timer 0 & Timer 1 for interrupt an start the timer
  **********************************************************************/
 void Capture::Start_1(void) {
-    capturedata = 0;                        // Clear the accumulator
-                                          // No data ready
-    
+                            
     /* Enable interrupt for CAPTURE  */
     NVIC_EnableIRQ(TIMER_32_0_IRQn); 
     
     // Start the timer
-    LPC_CT32B0->TCR =  CT32B0_TCR_CEN; // enable
+    LPC_CT32B0->TCR =  CT32B0_TCR_CEN; // enable. See page 354 of the 11U24 User Guide 
     
 }
 
 void Capture::Start_2(void) {
-    capturedata_2 = 0;                        // Clear the accumulator
-                                 // No data ready
-    
+                    
     /* Enable interrupt for CAPTURE  */
     NVIC_EnableIRQ(TIMER_32_1_IRQn); 
     
@@ -100,207 +122,203 @@
 }
 
 /*********************************************************************//**
- * @brief        Read (accumulated) sample count. 
- * 
- * @return       (unsigned int) Accumulated capture value
+Debug code to test what values are in certain registers when writing the program
  **********************************************************************/
  
  unsigned int Capture::Debug(void) {
  
- debug = LPC_IOCON->TMS_PIO0_12 ;               // to check teh values in registers
+ debug = LPC_IOCON->TMS_PIO0_12 ;  // to check the values in registers (This example checks whats in register the IOCON register for TMS_PIO0_12
  
  return debug;
  
 }
  
-//unsigned int Capture::Read_1(void) {
-void Capture::Read_1(void) {  
-
-   // static unsigned int i_1 = 0;
-    i_1 = capturedata;
-   // fall = ((i_1/48003280)*1000000);
-    //test_1 = 101;
-   // i_1 = capturedata_2;
+/*********************************************************************//**
+Wait function that interrupts the program once the value in the match register matches whats in the TC register. This then jumps to the 
+Wait_ISR routine which displays the data to the screen or LCD
+ **********************************************************************/
  
-   // return capturedata;
-    
-}
-
-
-//unsigned int Capture::Read_2(void) {
-void Capture::Read_2(void) {  
-
-   // static unsigned int j_1 = 0;
-    j_1 = capturedata_2;
-   // rise = ((j_1/48003280)*1000000);
-   // test_2 = 105;   
-      //  j_1 = capturedata_2;
-    
-    //return capturedata_2;
-    
-}
-
-
+ 
 void Capture::Wait(void) {
     
-    led3 = !led3;
+    //led3 = !led3;
     
      //Enable interrupt 
-    NVIC_EnableIRQ(TIMER_16_0_IRQn); 
+    NVIC_EnableIRQ(TIMER_16_0_IRQn);        //Enable 16 bit timer 0 for interrupt
     
     // Start the timer
     LPC_CT16B0->TCR =  CT16B0_TCR_CEN; // enable
-  
+
     LPC_CT16B0->MR0 = 1000000000;
      
 }
 
-
-
-/* Capture isr instantiator */   
-void Capture::_Captureisr1(void)
+/* Capture Fall_ISR instantiator */   
+void Capture::_Fall_ISR(void)
 {
-    instance->Captureisr1();
+    instance->Fall_ISR();
 }
  
-/* Capture isr instantiator */    
-void Capture::_Captureisr2(void)
+/* Capture Rise_ISR instantiator */    
+void Capture::_Rise_ISR(void)
 {
-    instance->Captureisr2();
+    instance->Rise_ISR();
 }
 
-/* Capture isr instantiator */    
-
+/* Capture Wait_ISR  instantiator */    
 
-void Capture::_Captureisr3(void)
+void Capture::_Wait_ISR(void)
 {
-    instance->Captureisr3();
+    instance->Wait_ISR();
 }
 
 
 /*********************************************************************//**
- * @brief        Capture interrupt service routine. Handles accumulation.
- * 
- * @param[in]    none
- *                                 
- * @return       none
+ * @brief        Capture interrupt service routine for falling edge. 
  **********************************************************************/
-void Capture::Captureisr1(void) {
+void Capture::Fall_ISR(void) {
 
-    static int capturesum = 0;    // Accumulates the readings
+    static int capturesum = 0;                           // set variable capturesum to 0
     
-    led = !led;
-    capturesum = LPC_CT32B0->CR2;
-    rise = (((float)capturesum/48003280)*1000000);
-    // capturedata = 101;
-     capturedata = capturesum;
-    // rise = ((capturedata/48003280)*1000000);
-    //test_1 = 101;
-    LPC_CT32B0->IR |= CT32B0_IR_CR1INT; 
+    led = !led;                                          // status led to check that program has entered ISR
+    capturesum = LPC_CT32B0->CR2;                        // read the value in LPC_CT32B0->CR2 and store in variable 'capturesum'
+                                                         // It is necessary to use "CR2" in order to get the proper
+                                                         // offset from the base address (an issue with CMSIS)
+    fall = (((float)capturesum/48003280)*1000000);       // Convert the value in the capture register into a value in us. the internal clock 
+                                                         // was measured at 48003280 so this has been used for the calculations.
+                                                         // It is neccessary to assign the 'float' data type to 'capturesum' at this point 
+                                                         // otherwise the variable fall which has been set to float will return a value of 0.
+                    
+    LPC_CT32B0->IR |= CT32B0_IR_CR1INT;                  // Clear the interrupt
              
     return;
 
 }
 
 /*********************************************************************//**
- * @brief        Capture interrupt service routine. Handles accumulation.
- * 
- * @param[in]    none
- *                                 
- * @return       none
+ * @brief        Capture interrupt service routine for rising edge. 
  **********************************************************************/
-void Capture::Captureisr2(void) {
+void Capture::Rise_ISR(void) {
 
     static int capturesum_2 = 0;    // Accumulates the readings
   
     led2 = !led2;
     capturesum_2 = LPC_CT32B1->CR0;
-   // rise = capturesum_2;
-   // rise_2 = ((rise/48003280)*1000000);
-    //rise = ((capturesum_2/48003280)*1000000);
-    capturedata_2 = capturesum_2;
-    
-    fall = (((float)capturesum_2/48003280)*1000000);
-    //test_2 = 105;
+    rise = (((float)capturesum_2/48003280)*1000000);
     LPC_CT32B1->IR |= CT32B1_IR_CR0INT; 
       
     return;
 }
 
-
+/*********************************************************************//**
+ * @brief        Wait interrupt service routine to display the results to a screen/lcd at set intervals 
+ **********************************************************************/
 
-void Capture::Captureisr3(void) {
+void Capture::Wait_ISR(void) {
     
-    NVIC_DisableIRQ(TIMER_32_0_IRQn);
-    NVIC_DisableIRQ(TIMER_32_1_IRQn);
+    NVIC_DisableIRQ(TIMER_32_0_IRQn);                   //disable 32 bit timer 0 interrupt so that the Wait_ISR can continue uninterrupted
+    NVIC_DisableIRQ(TIMER_32_1_IRQn);                   //disable 32 bit timer 1 interrupt so that the Wait_ISR can continue uninterrupted
     
-    led4 = !led4;
-    //m_1 = i_1 + j_1;
-   
-  // ((i_1/48003280)*1000000);
-     //rise = ((capturedata/48003280)*1000000);
+    led4 = !led4;                                       // status led to test that Wait_ISR is being entered
    
-   
-   
-   //serial.printf("rise:%d \n\r", rise);
-   
-   
-    //serial.printf("test_1:%d \n\r", test_1);
-   // serial.printf("test_2:%d \n\r", test_2);
+    period = rise + fall;                               // calculation for period
+   // freq = (1/(float)period)*1000000;                   // calculation for frequency (not required)                                
+    ADCdata = Ain * 10;                                 // calculation to convert ADC value to 10V
     
-   // serial.printf("rise:%d \n\r", rise);
-    //serial.printf("rise_2:%d \n\r", rise_2);
-      
-    //serial.printf("%.2f \n\r",ADCdata);
+  /*  if (freq < 1000) {                                // unit conversion for frequency
+      freq_unit = "Hz";
+      freq1 = freq;
+      }
+      else if (freq > 1000) {
+      freq1 = freq/1000;
+      freq_unit = "KHz";
+    }
+*/
+
+    if (period < 1000) {                                // unit conversion for period
+        per_sec_unit = "us";
+        period1 = period;
+        }
+     else if (period > 1000) {
+         period1 = period/1000;
+         per_sec_unit = "ms";
+         }   
+         
+    if (rise < 1000) {                                  //unit conversion for +ve Pulsewidth
+        rise_sec_unit = "us";
+        rise1 = rise;
         
-    //serial.printf("fall:%d \n\r", fall);
-    
-    int x;
-    
-    for (x = 0; x<100; x++){
-    
-    //if (serial.writeable())
-    //{
-       // if ( x == 99) {
-    
-    
-    }
-    
-    period = rise + fall;
-    freq = (1/(float)period)*1000000;
-    
-    lcd.cls();
-    lcd.locate(0,0);
-   // lcd.printf("capturedata:%d \n\r", capturedata);
-   lcd.printf("rise:%.4f", rise);
+        }
+     else if (rise > 1000) {
+         rise1 = rise/1000;
+         rise_sec_unit = "ms";
+         }   
+         
+    if (fall < 1000) {                                  //unit conversion for -ve Pulsewidth
+        fall_sec_unit = "us";
+        fall1 = fall;
+        }
+     else if (fall > 1000) {
+         fall1 = fall/1000;
+         fall_sec_unit = "ms";
+         }   
+          
+/* Display Rise, Fall, Period and Voltage to LCD screen */
+
+    lcd.locate(0,0);    
+    lcd.printf("Rise:");
     lcd.locate(0,1);
-    lcd.printf("fall:%.4f", fall);
+    lcd.printf("Fall:");
     lcd.locate(0,2);
-    lcd.printf("period:%.4f", period);
+    lcd.printf("Per:");
     lcd.locate(0,3);
-    lcd.printf("freq:%.2f", freq);
+    lcd.printf("Voltage:");
+   // lcd.printf("Freq:");
     
     
     
-   // serial.printf("capturedata:%d \n\r", capturedata);
-   // serial.printf("fall:%f \n\r", rise);
-   // serial.printf("fall:%f \n\r", fall);
-   // serial.printf("i_1:%.8f \n\r\n", i_1);
-   // serial.printf("i:%.8f \n\r\n", ((i_1/48003280)*1000000));
+/* These values are the ones that change over the course of the program so they have been put seprately to the values above
+   Because individual lines on the LCD can't be cleared due to limitaions of the hardware to clear an individual line write blanks to the display
+   for eg. lcd.printf("           ");
+ */
+ 
+ 
+    lcd.locate(5,0);
+    lcd.printf("%.2f", rise1);
+    lcd.locate(14,0);
+    lcd.printf("%s", rise_sec_unit);        
+    lcd.locate(5,1);
+    lcd.printf("%.2f", fall1);
+    lcd.locate(14,1);
+    lcd.printf("%s", fall_sec_unit);
+    lcd.locate(4,2);
+    lcd.printf("%.2f", period1);
+    lcd.locate(14,2);
+    lcd.printf("%s", per_sec_unit);
+    lcd.locate(8,3);
+    lcd.printf("%.2f", ADCdata);
+    lcd.locate(15,3);
+    lcd.printf("V");
+    //lcd.printf("%.2f %s", freq1, freq_unit);
     
-    x = 0;
- // }   
-  
-  
-  
-   // serial.printf("j:%.8f \n\r\n", ((j_1/48003280)*1000000));
-       
-   // serial.printf("i+j:%.8f \n\r\n", m_1);  
-      
-    NVIC_EnableIRQ(TIMER_32_0_IRQn);
-    NVIC_EnableIRQ(TIMER_32_1_IRQn);
     
-    LPC_CT16B0->IR |= CT16B0_IR_MR0INT; 
+
+    //if (serial.writeable())                                       // write values to serial (some issues seen with serial where the serial port hangs causing
+                                                                    // the program not to work. Sometimes works and sometimes it doesn't
+    //{
+     
+    //serial.printf("rise:%f \n\r", rise);
+   // serial.printf("fall:%f \n\r", fall);
+   // serial.printf("period:%f \n\r", period);
+    //serial.printf("freq:%f \n\r", freq);
+    //serial.printf("ADC:%f \n\r", ADCdata);
+    //serial.printf("hello");
+     // } 
+
+    NVIC_EnableIRQ(TIMER_32_0_IRQn);                        //re-enable 32 bit timer 0 for interrupts
+    NVIC_EnableIRQ(TIMER_32_1_IRQn);                        //re-enable 32 bit timer 1 for interrupts
+    
+    LPC_CT16B0->IR |= CT16B0_IR_MR0INT;                     // Clear the interrupt
     
     return;
     
diff -r 6bb38ae2e503 -r 857c3c8e7a2f PulseWidthCapture.h
--- a/PulseWidthCapture.h	Wed Dec 10 10:33:32 2014 +0000
+++ b/PulseWidthCapture.h	Thu Dec 11 08:59:09 2014 +0000
@@ -8,7 +8,7 @@
  * @brief       Header file for the PulseWidthCapture library. 
  * @version     0.0
  * @date        03 Dec 2014
- * @author      
+ * @author      Callum Ellor
  **************************************************************************/
 /***************************************************************************
  * Revision     Date        Comments
@@ -27,56 +27,39 @@
 
 
 /* Public Functions ----------------------------------------------------------- */
-/** @defgroup Capture_Public_Functions Capture Public Functions
+/** Capture_Public_Functions Capture Public Functions
 */
 class Capture {
 public:
 
-/** Create a Capture object and configure it
- *
- * @param none
- */
+/* Create a Capture object and configure it */
 Capture(void);
 
-/** Start capturing data. Accumulate the specified number of samples. 
- * @param numsamples    The number of samples to be accumulated
- * @return        None
- */
+/* Start capturing data. */
 void Start_1(void);
-
 void Start_2(void);
 
+/* Wait function */
 void Wait(void);
 
-
-/** Read (accumlated) sample count. 
- * 
- * @return       (unsigned int) Accumulated capture value
- */
-//unsigned int Read_1(void);
-void Read_1(void);
-
-//unsigned int Read_2(void);
-void Read_2(void);
-
+/* Debug function */
 unsigned int Debug(void);
 
 /* Public Macros -------------------------------------------------------------- */
 
 private:
-static void _Captureisr1(void);
-static void _Captureisr2(void);
-static void _Captureisr3(void);
-void Captureisr1(void);  
-void Captureisr2(void);  
-void Captureisr3(void);  
+static void _Fall_ISR(void);
+static void _Rise_ISR(void);
+static void _Wait_ISR(void);
+void Fall_ISR(void); 
+void Rise_ISR(void);  
+void Wait_ISR(void);  
 static Capture *instance;
-//double capturedata;
-unsigned int capturedata;
-unsigned int capturedata_2;
-unsigned int test_1, test_2; 
-float rise, fall, period, freq;
-double rise_2, fall_2, i_1, j_1, m_1;
+const char * freq_unit;
+const char * rise_sec_unit;
+const char * fall_sec_unit;
+const char * per_sec_unit;
+float rise, rise1, fall, fall1, period, period1, freq, freq1, ADCdata;
 unsigned int debug;    
                                         
 /* Private Macros ------------------------------------------------------------- */
@@ -86,38 +69,38 @@
 /*********************************************************************//**
  * Macro defines for CT32B0->IR Interrupt tegister
  **********************************************************************/
-#define CT32B0_IR_CR0INT                   ((uint32_t)(1<<4))
+#define CT32B0_IR_CR0INT                   ((uint32_t)(1<<4))        /**< Interrupt flag for capture channel 0 */
 #define CT32B0_IR_CR1INT                   ((uint32_t)(1<<6))        /**< Interrupt flag for capture channel 1 */
 
-#define CT16B0_IR_MR0INT                   ((uint32_t)(1<<0))
-
-
 /*********************************************************************//**
  * Macro defines for CT32B1->IR Interrupt tegister
  **********************************************************************/
-#define CT32B1_IR_CR0INT                   ((uint32_t)(1<<4))        /**< Interrupt flag for capture channel 1 */
-#define CT32B1_IR_CR1INT                   ((uint32_t)(1<<5))
+#define CT32B1_IR_CR0INT                   ((uint32_t)(1<<4))        /**< Interrupt flag for capture channel 0 */
+#define CT32B1_IR_CR1INT                   ((uint32_t)(1<<5))        /**< Interrupt flag for capture channel 1 */
 
 /*********************************************************************//**
- * Macro defines for IOCON->PIO1_29 register bits LPC11U24
+ * Macro defines for CT16B0->IR Interrupt tegister                  
+ **********************************************************************/
+#define CT16B0_IR_MR0INT                   ((uint32_t)(1<<0))        /**< Interrupt flag for Match channel 0 */
+
+/*********************************************************************//**
+ * Macro defines for IOCON->PIO1_29 register bits LPC11U24   page 125
  **********************************************************************/
 #define P1_29_PIN_PULL_UP                     2UL
 #define P1_29_PIN_REPEATER                    3UL
 #define P1_29_PIN_NORESISTOR                  0UL
 #define P1_29_PIN_PULL_DOWN                   1UL 
 
-/* FUNC bits */
+/* FUNC bits */                                                       // define what fucntion the pin should be set up in
 #define PORT_PIO1_29                          0UL
 #define SCKO                                  1UL
 #define CT32B0_CAP1                           2UL
 
-
-
 /* MODE bits */
 #define P1_29_CAP_PULLUP                 ((uint32_t)(PIN_PULL_UP<<3))          // Pull up on the CT32B0_CAP1 input pin
 
 /*********************************************************************//**
- * Macro defines for IOCON->PIO0_12 register bits LPC11U24
+ * Macro defines for IOCON->PIO0_12 register bits LPC11U24      page 94
  **********************************************************************/
 #define P0_12_PIN_PULL_UP                     2UL
 #define P0_12_PIN_REPEATER                    3UL
@@ -125,17 +108,18 @@
 #define P0_12_PIN_PULL_DOWN                   1UL 
 
 /* FUNC bits */
-#define PIO0_12                               1UL
+#define PIO0_12                               1UL                     // define what fucntion the pin should be set up in
 #define ADL                                   2UL
-#define CT32B1_CAP0                           3UL             //forPIO0_12
-#define ADMODE                           ((uint32_t)(1<<7)) 
+#define CT32B1_CAP0                           3UL             
+
+#define ADMODE                           ((uint32_t)(1<<7))           // Set to digital function mode to allow capture input on this pin
 #define FILTR                            ((uint32_t)(1<<8))    
 
 /* MODE bits */
 #define P0_12_CAP_PULLUP                 ((uint32_t)(PIN_PULL_UP<<3))          // Pull up on the CT32B0_CAP1 input pin
 
 /*********************************************************************//**
- * Macro defines for SYSCON->SYSAHBCLKDIV register  bits LPC11U24
+ * Macro defines for SYSCON->SYSAHBCLKDIV register  bits LPC11U24      page 30
  **********************************************************************/
 #define CT32B0_CLK_ENABLE          ((uint32_t)(1<<9))        /**< CT32B0 clock enable */ 
 
@@ -143,36 +127,36 @@
 
 #define CT16B0_CLK_ENABLE          ((uint32_t)(1<<7))
 /*********************************************************************//**
- * Macro defines for CT32B0->TCR register  bits LPC11U24
+ * Macro defines for CT32B0->TCR register  bits LPC11U24                page 353
  **********************************************************************/
 #define CT32B0_TCR_CEN                         1UL
 
 /*********************************************************************//**
- * Macro defines for CT32B1->TCR register  bits LPC11U24
+ * Macro defines for CT32B1->TCR register  bits LPC11U24                page 353
  **********************************************************************/
 #define CT32B1_TCR_CEN                          1UL
 
 /*********************************************************************//**
- * Macro defines for CT16B0->TCR register  bits LPC11U24
+ * Macro defines for CT16B0->TCR register  bits LPC11U24                page 335
  **********************************************************************/
 #define CT16B0_TCR_CEN                          1UL
 
 /*********************************************************************//**
- * Macro defines for CT32B0->CCR register  bits LPC11U24
+ * Macro defines for CT32B0->CCR register  bits LPC11U24                page 357
  **********************************************************************/
 #define CCR_CAP1RE                     ((uint32_t)(1<<6)) 
 #define CCR_CAP1FE                     ((uint32_t)(1<<7))
 #define CCR_CAP1I                      ((uint32_t)(1<<8))  
 
 /*********************************************************************//**
- * Macro defines for CT32B1->CCR register  bits LPC11U24
+ * Macro defines for CT32B1->CCR register  bits LPC11U24                page 356
  **********************************************************************/
 #define CCR_CAP0RE                     ((uint32_t)(1<<0)) 
 #define CCR_CAP0FE                     ((uint32_t)(1<<1))
 #define CCR_CAP0I                      ((uint32_t)(1<<2))  
 
 /*********************************************************************//**
- * Macro defines for CT32B0->CTCR register  bits LPC11U24
+ * Macro defines for CT32B0->CTCR register  bits LPC11U24               page  361
  **********************************************************************/
 #define CT32B0_CTCR_CTM_TIMER                  0UL
 #define CT32B0_CTCR_ENCC                       ((uint32_t)(1<<4))
@@ -181,19 +165,19 @@
 
 
 /*********************************************************************//**
- * Macro defines for CT32B1->CTCR register  bits LPC11U24
+ * Macro defines for CT32B1->CTCR register  bits LPC11U24               page 362
  **********************************************************************/
 #define CT32B1_CTCR_CTM_TIMER                  0UL
 #define CT32B1_CTCR_ENCC                       ((uint32_t)(1<<4))
 #define CT32B1_CTCR_SEICC_CAP0RE               ((uint32_t)(0<<5))          //CT32B1_CAP0
 #define CT32B1_CTCR_SEICC_CAP0FE               ((uint32_t)(1<<5))
 
+/*********************************************************************//**
+ * Macro defines for CT16B0->MCR register  bits LPC11U24               page 337
+ **********************************************************************/
 #define CT16B0_MR0I                            ((uint32_t)(1<<0))
-
 #define CT16B0_MR0R                            ((uint32_t)(1<<1))
 
-
-
 }; // End of Capture class information
 #endif /* CAPTURE_H */
 /* --------------------------------- End Of File ------------------------------ */