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
Diff: LCD_Wait.cpp
- Revision:
- 0:538efd9574f7
- Child:
- 1:57aba608a20d
diff -r 000000000000 -r 538efd9574f7 LCD_Wait.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD_Wait.cpp Wed Dec 10 10:33:53 2014 +0000 @@ -0,0 +1,125 @@ +#include "mbed.h" +#include "TextLCD_16x4.h" +#include "LCD_Wait.h" + +//DigitalOut led(P0_9); +//DigitalOut led2(P0_8); +//DigitalOut led3(P0_7); +//DigitalOut led4(P0_17); +//DigitalOut led5(P0_1); + +LCD_Wait *LCD_Wait::instance; + +LCD_Wait::LCD_Wait(void) +{ + + LPC_SYSCON->SYSAHBCLKCTRL |= CT16B1_CLK_ENABLE; + + LPC_CT16B1->PR = 48000; + + //LPC_CT16B1->MCR = CT16B1_MR0I | CT16B1_MR0R; + + // LPC_CT16B1->IR = CT16B1_IR_MR0INT; + + + + //instance = this; + //NVIC_SetVector(TIMER_16_1_IRQn, (uint32_t)&_Wait_ISR); + +} + + +void LCD_Wait::Wait(float num_wait) { + + // wait_n = num_wait; + //led = !led; + + LPC_CT16B1->TC = 0; + + // Start the timer + LPC_CT16B1->TCR = CT16B1_TCR_CEN; // enable + + // blocking while loop that waits for the timer counter to exceed the set value + // If another interrupt fires during this while loop, this Wait function might take a little longer than expected + // while(LPC_CT16B1->TC < my_max_count_value); + while(LPC_CT16B1->TC < num_wait); + + } + + //Enable interrupt + // NVIC_EnableIRQ(TIMER_16_1_IRQn); + + // Start the timer + // LPC_CT16B1->TCR = CT16B1_TCR_CEN; // enable + + // LPC_CT16B1->MR0 = wait_n; + + // } + + + + /* +void LCD_Wait::Wait(int num_wait) { + + wait_n = num_wait; + led = !led; + + //Enable interrupt + NVIC_EnableIRQ(TIMER_16_1_IRQn); + + // Start the timer + LPC_CT16B1->TCR = CT16B1_TCR_CEN; // enable + + //for ( + + //if (LPC_CT16B1->TC == wait_n) { + + // NVIC_DisableIRQ(TIMER_16_1_IRQn); + + //return; + +// } + + + + // LPC_CT16B1->MR0 = wait_n; + + } + */ + +/* +void LCD_Wait::Wait(int num_wait) { + + wait_n = num_wait; + int x; + for (x = 0; x < wait_n; x++) { + + } + x = 0; + +} +*/ + +/* +void LCD_Wait::_Wait_ISR(void) +{ + instance->Wait_ISR(); +} + +void LCD_Wait::Wait_ISR(void) { + + led2 = !led2; + + // NVIC_DisableIRQ(TIMER_32_0_IRQn); + // NVIC_DisableIRQ(TIMER_32_1_IRQn); + + +NVIC_DisableIRQ(TIMER_16_1_IRQn); + +LPC_CT16B1->IR = CT16B1_IR_MR0INT; + + return; + + +} +*/