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:
- 1:57aba608a20d
- Parent:
- 0:538efd9574f7
- Child:
- 2:46e8391685c4
--- a/LCD_Wait.cpp Wed Dec 10 10:33:53 2014 +0000 +++ b/LCD_Wait.cpp Wed Dec 10 11:00:33 2014 +0000 @@ -1,125 +1,30 @@ #include "mbed.h" -#include "TextLCD_16x4.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::instance; - -LCD_Wait::LCD_Wait(void) +LCD_Wait::LCD_Wait(void) //LCD_Wait constructor { - LPC_SYSCON->SYSAHBCLKCTRL |= CT16B1_CLK_ENABLE; - - LPC_CT16B1->PR = 48000; - - //LPC_CT16B1->MCR = CT16B1_MR0I | CT16B1_MR0R; + LPC_SYSCON->SYSAHBCLKCTRL |= CT16B1_CLK_ENABLE; // setup system clock to enable 16 bit Timer 1 Page 30 of user manual - // LPC_CT16B1->IR = CT16B1_IR_MR0INT; - - - - //instance = this; - //NVIC_SetVector(TIMER_16_1_IRQn, (uint32_t)&_Wait_ISR); - + LPC_CT16B1->PR = 48000; // Set prescale value to give 1ms clock. + } -void LCD_Wait::Wait(float num_wait) { +void LCD_Wait::Wait(float num_wait) { // wait function - // wait_n = num_wait; - //led = !led; - - LPC_CT16B1->TC = 0; + LPC_CT16B1->TC = 0; //set Timer Counter register to 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; - - -} -*/