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@1:57aba608a20d, 2014-12-10 (annotated)
- Committer:
- Ellor1
- Date:
- Wed Dec 10 11:00:33 2014 +0000
- Revision:
- 1:57aba608a20d
- Parent:
- 0:538efd9574f7
- Child:
- 2:46e8391685c4
working wait function;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ellor1 | 0:538efd9574f7 | 1 | #include "mbed.h" |
Ellor1 | 1:57aba608a20d | 2 | //#include "TextLCD_16x4.h" |
Ellor1 | 0:538efd9574f7 | 3 | #include "LCD_Wait.h" |
Ellor1 | 0:538efd9574f7 | 4 | |
Ellor1 | 1:57aba608a20d | 5 | //LCD_Wait *LCD_Wait::instance; |
Ellor1 | 0:538efd9574f7 | 6 | |
Ellor1 | 1:57aba608a20d | 7 | LCD_Wait::LCD_Wait(void) //LCD_Wait constructor |
Ellor1 | 0:538efd9574f7 | 8 | { |
Ellor1 | 0:538efd9574f7 | 9 | |
Ellor1 | 1:57aba608a20d | 10 | LPC_SYSCON->SYSAHBCLKCTRL |= CT16B1_CLK_ENABLE; // setup system clock to enable 16 bit Timer 1 Page 30 of user manual |
Ellor1 | 0:538efd9574f7 | 11 | |
Ellor1 | 1:57aba608a20d | 12 | LPC_CT16B1->PR = 48000; // Set prescale value to give 1ms clock. |
Ellor1 | 1:57aba608a20d | 13 | |
Ellor1 | 0:538efd9574f7 | 14 | } |
Ellor1 | 0:538efd9574f7 | 15 | |
Ellor1 | 0:538efd9574f7 | 16 | |
Ellor1 | 1:57aba608a20d | 17 | void LCD_Wait::Wait(float num_wait) { // wait function |
Ellor1 | 0:538efd9574f7 | 18 | |
Ellor1 | 1:57aba608a20d | 19 | LPC_CT16B1->TC = 0; //set Timer Counter register to 0 |
Ellor1 | 0:538efd9574f7 | 20 | |
Ellor1 | 0:538efd9574f7 | 21 | // Start the timer |
Ellor1 | 0:538efd9574f7 | 22 | LPC_CT16B1->TCR = CT16B1_TCR_CEN; // enable |
Ellor1 | 0:538efd9574f7 | 23 | |
Ellor1 | 0:538efd9574f7 | 24 | // blocking while loop that waits for the timer counter to exceed the set value |
Ellor1 | 0:538efd9574f7 | 25 | // If another interrupt fires during this while loop, this Wait function might take a little longer than expected |
Ellor1 | 1:57aba608a20d | 26 | |
Ellor1 | 0:538efd9574f7 | 27 | while(LPC_CT16B1->TC < num_wait); |
Ellor1 | 0:538efd9574f7 | 28 | |
Ellor1 | 0:538efd9574f7 | 29 | } |
Ellor1 | 0:538efd9574f7 | 30 |