Wait function that uses 16 Bit Timer 1 instead of using 32 bit Timer 0 to be used in conjunction with 'TextLCD16x4_Wait' and 'PulseWidthCapture' to measure the +ve and -ve Pulsewdth of a signal
Dependents: PulseWidthCapture_Program
LCD_Wait.cpp@2:46e8391685c4, 2014-12-11 (annotated)
- Committer:
- Ellor1
- Date:
- Thu Dec 11 08:59:33 2014 +0000
- Revision:
- 2:46e8391685c4
- Parent:
- 1:57aba608a20d
Wait Library for TextLCD16x4;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ellor1 | 2:46e8391685c4 | 1 | /*********************************************************************************************************************** |
Ellor1 | 2:46e8391685c4 | 2 | This library has been created to create a new wait function that uses the 16 bit Timer 1 rather that the traditional 32 Bit Timer 0. |
Ellor1 | 2:46e8391685c4 | 3 | This library is intended for use with the 'TextLCD_16x4' Library to get the lcd to work alongside the 'PulseWidthCapture' Program. |
Ellor1 | 2:46e8391685c4 | 4 | |
Ellor1 | 2:46e8391685c4 | 5 | Created by |
Ellor1 | 2:46e8391685c4 | 6 | Callum Ellor |
Ellor1 | 2:46e8391685c4 | 7 | **************************************************************************************************************************/ |
Ellor1 | 2:46e8391685c4 | 8 | |
Ellor1 | 0:538efd9574f7 | 9 | #include "mbed.h" |
Ellor1 | 0:538efd9574f7 | 10 | #include "LCD_Wait.h" |
Ellor1 | 0:538efd9574f7 | 11 | |
Ellor1 | 1:57aba608a20d | 12 | LCD_Wait::LCD_Wait(void) //LCD_Wait constructor |
Ellor1 | 0:538efd9574f7 | 13 | { |
Ellor1 | 0:538efd9574f7 | 14 | |
Ellor1 | 1:57aba608a20d | 15 | LPC_SYSCON->SYSAHBCLKCTRL |= CT16B1_CLK_ENABLE; // setup system clock to enable 16 bit Timer 1 Page 30 of user manual |
Ellor1 | 0:538efd9574f7 | 16 | |
Ellor1 | 1:57aba608a20d | 17 | LPC_CT16B1->PR = 48000; // Set prescale value to give 1ms clock. |
Ellor1 | 1:57aba608a20d | 18 | |
Ellor1 | 0:538efd9574f7 | 19 | } |
Ellor1 | 2:46e8391685c4 | 20 | |
Ellor1 | 1:57aba608a20d | 21 | void LCD_Wait::Wait(float num_wait) { // wait function |
Ellor1 | 0:538efd9574f7 | 22 | |
Ellor1 | 1:57aba608a20d | 23 | LPC_CT16B1->TC = 0; //set Timer Counter register to 0 |
Ellor1 | 0:538efd9574f7 | 24 | |
Ellor1 | 0:538efd9574f7 | 25 | // Start the timer |
Ellor1 | 0:538efd9574f7 | 26 | LPC_CT16B1->TCR = CT16B1_TCR_CEN; // enable |
Ellor1 | 0:538efd9574f7 | 27 | |
Ellor1 | 0:538efd9574f7 | 28 | // blocking while loop that waits for the timer counter to exceed the set value |
Ellor1 | 0:538efd9574f7 | 29 | // If another interrupt fires during this while loop, this Wait function might take a little longer than expected |
Ellor1 | 1:57aba608a20d | 30 | |
Ellor1 | 0:538efd9574f7 | 31 | while(LPC_CT16B1->TC < num_wait); |
Ellor1 | 0:538efd9574f7 | 32 | |
Ellor1 | 0:538efd9574f7 | 33 | } |
Ellor1 | 0:538efd9574f7 | 34 |