Uses Timer 0 of the 11U24 to capture input pulsesl

Committer:
hexley
Date:
Thu Mar 13 17:52:43 2014 +0000
Revision:
0:22c6b94e7da6
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hexley 0:22c6b94e7da6 1 /* mbed Library - CaptureT0_11U24
hexley 0:22c6b94e7da6 2 * Copyright (c) 2014
hexley 0:22c6b94e7da6 3 * released under MIT license http://mbed.org/licence/mit
hexley 0:22c6b94e7da6 4 */
hexley 0:22c6b94e7da6 5
hexley 0:22c6b94e7da6 6 /***********************************************************************//**
hexley 0:22c6b94e7da6 7 * @file capturet1_11u24.h
hexley 0:22c6b94e7da6 8 * @brief Header file for the CaptureT0_11U24 library.
hexley 0:22c6b94e7da6 9 * @version 0.0
hexley 0:22c6b94e7da6 10 * @date 5 Feb 2014
hexley 0:22c6b94e7da6 11 * @author
hexley 0:22c6b94e7da6 12 **************************************************************************/
hexley 0:22c6b94e7da6 13 /***************************************************************************
hexley 0:22c6b94e7da6 14 * Revision Date Comments
hexley 0:22c6b94e7da6 15 *---------- -------- -----------------------------------------------
hexley 0:22c6b94e7da6 16 *
hexley 0:22c6b94e7da6 17 * 0.0 2/5/14 Initial creation
hexley 0:22c6b94e7da6 18 ***************************************************************************/
hexley 0:22c6b94e7da6 19
hexley 0:22c6b94e7da6 20 #ifndef CAPTURET0_H
hexley 0:22c6b94e7da6 21 #define CAPTURET0_H
hexley 0:22c6b94e7da6 22
hexley 0:22c6b94e7da6 23 /* Includes ------------------------------------------------------------------- */
hexley 0:22c6b94e7da6 24 #include "mbed.h"
hexley 0:22c6b94e7da6 25
hexley 0:22c6b94e7da6 26
hexley 0:22c6b94e7da6 27 /* Public Types --------------------------------------------------------------- */
hexley 0:22c6b94e7da6 28
hexley 0:22c6b94e7da6 29
hexley 0:22c6b94e7da6 30 /* Public Functions ----------------------------------------------------------- */
hexley 0:22c6b94e7da6 31 /** @defgroup Capture_Public_Functions Capture Public Functions
hexley 0:22c6b94e7da6 32 */
hexley 0:22c6b94e7da6 33 class Capture {
hexley 0:22c6b94e7da6 34 public:
hexley 0:22c6b94e7da6 35
hexley 0:22c6b94e7da6 36 /** Create a Capture object and configure it
hexley 0:22c6b94e7da6 37 *
hexley 0:22c6b94e7da6 38 * @param none
hexley 0:22c6b94e7da6 39 */
hexley 0:22c6b94e7da6 40 Capture(void);
hexley 0:22c6b94e7da6 41
hexley 0:22c6b94e7da6 42 /** Start capturing data. Accumulate the specified number of samples.
hexley 0:22c6b94e7da6 43 * @param numsamples The number of samples to be accumulated
hexley 0:22c6b94e7da6 44 * @return None
hexley 0:22c6b94e7da6 45 */
hexley 0:22c6b94e7da6 46 void Start(int numsamples);
hexley 0:22c6b94e7da6 47
hexley 0:22c6b94e7da6 48 /** Check to see if a new count is ready.
hexley 0:22c6b94e7da6 49 *
hexley 0:22c6b94e7da6 50 * @return (int) Status value. Negative means overrun.
hexley 0:22c6b94e7da6 51 */
hexley 0:22c6b94e7da6 52 int Ready(void);
hexley 0:22c6b94e7da6 53
hexley 0:22c6b94e7da6 54 /** Read (accumlated) sample count.
hexley 0:22c6b94e7da6 55 *
hexley 0:22c6b94e7da6 56 * @return (unsigned int) Accumulated capture value
hexley 0:22c6b94e7da6 57 */
hexley 0:22c6b94e7da6 58 unsigned int Read(void);
hexley 0:22c6b94e7da6 59
hexley 0:22c6b94e7da6 60
hexley 0:22c6b94e7da6 61
hexley 0:22c6b94e7da6 62 /* Public Macros -------------------------------------------------------------- */
hexley 0:22c6b94e7da6 63
hexley 0:22c6b94e7da6 64
hexley 0:22c6b94e7da6 65
hexley 0:22c6b94e7da6 66
hexley 0:22c6b94e7da6 67 private:
hexley 0:22c6b94e7da6 68 static void _Captureisr(void);
hexley 0:22c6b94e7da6 69 void Captureisr(void);
hexley 0:22c6b94e7da6 70 static Capture *instance;
hexley 0:22c6b94e7da6 71 int flag;
hexley 0:22c6b94e7da6 72 int channel;
hexley 0:22c6b94e7da6 73 //int capturecount;
hexley 0:22c6b94e7da6 74 unsigned int capturedata;
hexley 0:22c6b94e7da6 75 int Nsamples;
hexley 0:22c6b94e7da6 76 //int Nsamplebits;
hexley 0:22c6b94e7da6 77 //int *flagaddresspointer;
hexley 0:22c6b94e7da6 78
hexley 0:22c6b94e7da6 79
hexley 0:22c6b94e7da6 80
hexley 0:22c6b94e7da6 81 /* Private Macros ------------------------------------------------------------- */
hexley 0:22c6b94e7da6 82 /* --------------------- BIT DEFINITIONS -------------------------------------- */
hexley 0:22c6b94e7da6 83 /* Timer Capture Register Definitions --------------------- */
hexley 0:22c6b94e7da6 84
hexley 0:22c6b94e7da6 85 /*********************************************************************//**
hexley 0:22c6b94e7da6 86 * Macro defines for CT32B0->IR Interrupt tegister
hexley 0:22c6b94e7da6 87 **********************************************************************/
hexley 0:22c6b94e7da6 88 #define IR_CR1INT ((uint32_t)(1<<6)) /**< Interrupt flag for capture channel 1 */
hexley 0:22c6b94e7da6 89
hexley 0:22c6b94e7da6 90 /*********************************************************************//**
hexley 0:22c6b94e7da6 91 * Macro defines for IOCON->PIO1_29 register bits LPC11U24
hexley 0:22c6b94e7da6 92 **********************************************************************/
hexley 0:22c6b94e7da6 93 #define PIN_PULL_UP 2UL
hexley 0:22c6b94e7da6 94 #define PIN_REPEATER 3UL
hexley 0:22c6b94e7da6 95 #define PIN_NORESISTOR 0UL
hexley 0:22c6b94e7da6 96 #define PIN_PULL_DOWN 1UL
hexley 0:22c6b94e7da6 97
hexley 0:22c6b94e7da6 98 /* FUNC bits */
hexley 0:22c6b94e7da6 99 #define CT32B0_CAP1 2UL
hexley 0:22c6b94e7da6 100
hexley 0:22c6b94e7da6 101 /* MODE bits */
hexley 0:22c6b94e7da6 102 #define CAP_PULLUP ((uint32_t)(PIN_PULL_UP<<3)) // Pull up on the CT32B0_CAP1 input pin
hexley 0:22c6b94e7da6 103
hexley 0:22c6b94e7da6 104 /*********************************************************************//**
hexley 0:22c6b94e7da6 105 * Macro defines for SYSCON->SYSAHBCLKDIV register bits LPC11U24
hexley 0:22c6b94e7da6 106 **********************************************************************/
hexley 0:22c6b94e7da6 107 #define CT32B0_CLK_ENABLE ((uint32_t)(1<<9)) /**< CT32B0 clock enable */
hexley 0:22c6b94e7da6 108
hexley 0:22c6b94e7da6 109 /*********************************************************************//**
hexley 0:22c6b94e7da6 110 * Macro defines for CT32B0->TCR register bits LPC11U24
hexley 0:22c6b94e7da6 111 **********************************************************************/
hexley 0:22c6b94e7da6 112 #define TCR_CEN 1UL
hexley 0:22c6b94e7da6 113
hexley 0:22c6b94e7da6 114
hexley 0:22c6b94e7da6 115 /*********************************************************************//**
hexley 0:22c6b94e7da6 116 * Macro defines for CT32B0->CCR register bits LPC11U24
hexley 0:22c6b94e7da6 117 **********************************************************************/
hexley 0:22c6b94e7da6 118 #define CCR_CAP1RE ((uint32_t)(1<<6))
hexley 0:22c6b94e7da6 119 #define CCR_CAP1FE ((uint32_t)(1<<7))
hexley 0:22c6b94e7da6 120 #define CCR_CAP1I ((uint32_t)(1<<8))
hexley 0:22c6b94e7da6 121
hexley 0:22c6b94e7da6 122 /*********************************************************************//**
hexley 0:22c6b94e7da6 123 * Macro defines for CT32B0->CTCR register bits LPC11U24
hexley 0:22c6b94e7da6 124 **********************************************************************/
hexley 0:22c6b94e7da6 125 #define CTCR_CTM_TIMER 0UL
hexley 0:22c6b94e7da6 126 #define CTCR_ENCC ((uint32_t)(1<<4))
hexley 0:22c6b94e7da6 127 #define CTCR_SEICC_CAP1RE ((uint32_t)(4<<5))
hexley 0:22c6b94e7da6 128
hexley 0:22c6b94e7da6 129
hexley 0:22c6b94e7da6 130
hexley 0:22c6b94e7da6 131 }; // End of Capture class information
hexley 0:22c6b94e7da6 132 #endif /* CAPTURE_H */
hexley 0:22c6b94e7da6 133 /* --------------------------------- End Of File ------------------------------ */