[LEFT][COLOR=#005032][COLOR=#005032]TIM_TIMERCFG_Type [/COLOR][/COLOR]TIM_ConfigStruct; [COLOR=#005032][COLOR=#005032]TIM_CAPTURECFG_Type[/COLOR][/COLOR] TIM_CaptureConfigStruct;[/LEFT] [LEFT]LPC_PINCON->[COLOR=#0000c0][COLOR=#0000c0]PINSEL3[/COLOR][/COLOR] |= (0x20300015); [/LEFT] [LEFT]TIM_ConfigStruct.[COLOR=#0000c0][COLOR=#0000c0]PrescaleOption[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]TIM_PRESCALE_TICKVAL[/COLOR][/COLOR][/I]; TIM_ConfigStruct.[COLOR=#0000c0][COLOR=#0000c0]PrescaleValue[/COLOR][/COLOR] = 125;[/LEFT] [LEFT]TIM_CaptureConfigStruct.[COLOR=#0000c0][COLOR=#0000c0]CaptureChannel[/COLOR][/COLOR] = 0; TIM_CaptureConfigStruct.[COLOR=#0000c0][COLOR=#0000c0]RisingEdge[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]ENABLE[/COLOR][/COLOR][/I]; TIM_CaptureConfigStruct.[COLOR=#0000c0][COLOR=#0000c0]FallingEdge[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]DISABLE[/COLOR][/COLOR][/I]; TIM_CaptureConfigStruct.[COLOR=#0000c0][COLOR=#0000c0]IntOnCaption[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]ENABLE[/COLOR][/COLOR][/I];[/LEFT] [LEFT]TIM_Init(LPC_TIM0, [I][COLOR=#0000c0][COLOR=#0000c0]TIM_TIMER_MODE[/COLOR][/COLOR][/I], &TIM_ConfigStruct); TIM_ConfigCapture(LPC_TIM0, &TIM_CaptureConfigStruct);[/LEFT] [LEFT]NVIC_SetPriority([I][COLOR=#0000c0][COLOR=#0000c0]TIMER0_IRQn[/COLOR][/COLOR][/I], ((0x01<<3)|0x01)); NVIC_EnableIRQ([I][COLOR=#0000c0][COLOR=#0000c0]TIMER0_IRQn[/COLOR][/COLOR][/I]);[/LEFT] [LEFT]TIM_ResetCounter(LPC_TIM0); TIM_Cmd(LPC_TIM0, [I][COLOR=#0000c0][COLOR=#0000c0]ENABLE[/COLOR][/COLOR][/I]);[/LEFT] [LEFT]...[/LEFT] [LEFT][B][COLOR=#7f0055][COLOR=#7f0055]void [/COLOR][/COLOR][/B][B]TIMER0_IRQHandler[/B]([B][COLOR=#7f0055][COLOR=#7f0055]void[/COLOR][/COLOR][/B]) { [B][COLOR=#7f0055][COLOR=#7f0055]if[/COLOR][/COLOR][/B] (TIM_GetIntCaptureStatus(LPC_TIM0, 0) == [I][COLOR=#0000c0][COLOR=#0000c0]SET[/COLOR][/COLOR][/I]) { [B][COLOR=#7f0055][COLOR=#7f0055]while[/COLOR][/COLOR][/B](LPC_GPIO1->[COLOR=#0000c0][COLOR=#0000c0]FIOPIN[/COLOR][/COLOR] & (1<<26)){ SDtoCoProcessor(); } } TIM_ClearIntCapturePending(LPC_TIM0, 0); [B][COLOR=#7f0055][COLOR=#7f0055]return[/COLOR][/COLOR][/B]; }[/LEFT] |
#ifdef __USE_CMSIS #include "LPC17xx.h" #endif #include <cr_section_macros.h> #include <NXP/crp.h> __CRP const unsigned int CRP_WORD = CRP_NO_CRP ; //LED #define LED (1 << 22) #define LED_ON LPC_GPIO0->FIOSET=LED #define LED_OFF LPC_GPIO0->FIOCLR=LED #define LED_TOG LPC_GPIO0->FIOPIN^=LED //TEST #define TEST (1 << 28) #define TEST_ON LPC_GPIO0->FIOSET=TEST #define TEST_OFF LPC_GPIO0->FIOCLR=TEST #define TEST_TOG LPC_GPIO0->FIOPIN^=TEST void EINT3_IRQHandler(void) // Note: EINT3 channel is shared with GPIO interrupts { if(LPC_GPIOINT->IO2IntStatR &(1<<13))//read only rising edge status { LPC_GPIOINT->IO2IntClr =(1<<13); //reset interrupt LED_ON; } if(LPC_GPIOINT->IO2IntStatF &(1<<13))//read only falling edge status { LPC_GPIOINT->IO2IntClr =(1<<13); //reset interrupt LED_OFF; } } int main(void) { LPC_GPIO0->FIODIR |= (LED | TEST); //LED, TEST output //GPIO interrupt LPC_GPIOINT->IO2IntEnF|=(1<<13); //enable falling edge LPC_GPIOINT->IO2IntEnR|=(1<<13); //enable rising edge NVIC_EnableIRQ(EINT3_IRQn); //enable GPIO interrupt, Note: EINT3 channel is shared with GPIO interrupts volatile static int i = 0 ; while(1) { i++; //inc counter if(i>5000000) //delay { TEST_TOG; //toggle TEST output P0.28 = J6-26 i=0; //reset counter } //end delay } return 0 ; } |
//LED #define LED (1 << 22) #define LED_ON LPC_GPIO0->FIOSET=LED #define LED_OFF LPC_GPIO0->FIOCLR=LED #define LED_TOG LPC_GPIO0->FIOPIN^=LED void TIMER0_IRQHandler(void) { uint32_t reg_val; reg_val = LPC_TIM0->IR; if(reg_val & (1<<4)) //CR0 interrupt { if(LPC_GPIO1->FIOPIN & (1<<26))//high? { LED_ON; } else { LED_OFF; } LPC_TIM0->IR = (1<<4); //reset interrupt } } int main(void) { LPC_GPIO0->FIODIR |= LED; //LED output volatile static int i = 0 ; //setup timer 0 capture //Setup P1.26 as CAP0.0 LPC_PINCON->PINSEL3 |= (3<<20); //set capture 0.0 //Note: reset values of timer registers are 0, so setting them isn't necessary LPC_TIM0->CCR =((1<<0)|(1<<1)|(1<<2)); //capture rising & falling with interrupt LPC_TIM0->TCR = 1; //start timer NVIC_EnableIRQ(TIMER0_IRQn); while(1) { i++ ; } return 0 ; } |
//LED #define LED (1 << 22) #define LED_ON LPC_GPIO0->FIOSET=LED #define LED_OFF LPC_GPIO0->FIOCLR=LED #define LED_TOG LPC_GPIO0->FIOPIN^=LED void EINT3_IRQHandler(void) // Note: EINT3 channel is shared with GPIO interrupts { if(LPC_GPIOINT->IO2IntStatR &(1<<13))//read only rising edge status { LPC_GPIOINT->IO2IntClr =(1<<13); //reset interrupt LED_ON; } if(LPC_GPIOINT->IO2IntStatF &(1<<13))//read only falling edge status { LPC_GPIOINT->IO2IntClr =(1<<13); //reset interrupt LED_OFF; } } int main(void) { LPC_GPIO0->FIODIR |= LED; //LED output //GPIO interrupt P2.13 LPC_GPIOINT->IO2IntEnF|=(1<<13); //enable falling edge LPC_GPIOINT->IO2IntEnR|=(1<<13); //enable rising edge NVIC_EnableIRQ(EINT3_IRQn); //enable GPIO interrupt, Note: EINT3 channel is shared with GPIO interrupts volatile static int i = 0 ; while(1) { i++ ; } return 0 ; } |
// TIM_Init(...) { LPC_TIM0->CCR &= ~0x3; LPC_TIM0->CCR |= 0; LPC_TIM0->TC = 0; LPC_TIM0->PC = 0; LPC_TIM0->PR = 0; LPC_TIM0->TCR |= (1<<1); // Hold counter reset LPC_TIM0->TCR &= ~(1<<1); // Release counter reset LPC_TIM0->PR = 124; // 200kHz @ Peripheral clock of 25MHz LPC_TIM0->IR = 0xFFFFFFFF; // Reset all interrupts // } // // TIM_CaptureConfig(...) { LPC_TIM0->CCR &= ~((uint32_t)(7<<(0*3))); // Clear CCR LPC_TIM0->CCR |= ((1<<(0*3))); // Enable capture on rising edge LPC_TIM0->CCR |= ((1<<((n*3)+2))); // Enable interrupt on CR0 load // } // // TIM_ResetCounter(...) { LPC_TIM0->TCR |= ((uint32_t)(1<<1)); // Hold counter reset LPC_TIM0->TCR &= ~((uint32_t)(1<<1)); // Release counter reset // } // // TIM_Cmd(...) { LPC_TIM0->TCR |= ((uint32_t)(1<<0)); // Enable counter // } |
Have you figure out the issue?
I have trans coded the library, to check the rising and falling edge on the Capture input pin. As in ISR am checking the time captured for both rising and falling edge,
But in my code, am not able to enter in ISR.
Please see the link. Let me know if any suggestions
LPC_PINCON->PINSELx &= ~(3<<n); LPC_PINCON->PINSELx |= (f<<n); |
struct init_entry_ { volatile uint32_t *loc; uint32_t value; }; void writeregs(const struct init_entry_ *p) { for (; p->loc; p ++) *p->loc = p->value; } static const struct init_entry_ init0_table[] = { {&LPC_SC->PCONP, 0xA060965e}, // USB, DMA, SSP0, SSP1, TIMER2... {&LPC_SC->PCLKSEL1, 0x800}, // SSP0: /2 {&LPC_PINCON->PINMODE1, 0x002a8000}, // adc inputs, DAC output {&LPC_PINCON->PINSEL1, 0x14254028}, // DAC, ad2, ad1, ad0, USB, MOSI0, MISO0 {&LPC_PINCON->PINMODE2, 0x00030000}, // pulldown PSEN {&LPC_PINCON->PINMODE4, 0x03000000}, // extpwr pulldn // Port init //10987654321098765432109876543210 {&LPC_GPIO0->FIOPIN, 0b00010000000000010000000101000010}, // oe, mtr control, SD ss, hlat, Flash_ss {&LPC_GPIO0->FIODIR, 0b00010100011110010000010101000010}, // bits 28- BLU, 16 - HLAT, OE, RTSOUT {&LPC_PWM1->PR, 25000000ul / PWM_CLK - 1}, // many more entries follow - actually the table has about 100 entries in a typical app {0, 0} // end of table marker }; int main (void) { writeregs(init0_table); // most of initialization // do the real stuff... } |