//init Timer32_1 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 12, (IOCON_FUNC3 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN)); //CT32B1_CAP0 Chip_TIMER_Init(LPC_TIMER32_1);//init timer LPC_TIMER32_1->CTCR = 2;//falling edge LPC_TIMER32_1->TCR = 1;//start timer |
LPC_SYSCTL->SYSAHBCLKCTRL |= (1 << 9); //Enables clock for 32-bit counter/timer 0. Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); //CT32B0_CAP0 Chip_TIMER_Init(LPC_TIMER32_0);//init timer LPC_TIMER32_0->CTCR = 2; //falling edge CT32B0_CAP0 LPC_TIMER32_0->TCR = 1; //start timer CountValue = Chip_TIMER_ReadCount(LPC_TIMER32_0); |
int main(void) { volatile uint32_t CountValue; SystemCoreClockUpdate(); Board_Init(); setSYSTICK(); config7segm(); LPC_SYSCTL->SYSAHBCLKCTRL |= (1 << 9); Board_LED_Set(0, true); //init Timer32 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 0, 17, 0); Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); //CT32B0_CAP0 Chip_TIMER_Init(LPC_TIMER32_0);//init timer LPC_TIMER32_0->CTCR = 2;//falling edge CT32B0_CAP0 LPC_TIMER32_0->TCR = 1;//start timer _delay_ms(600); while (1) { Imprime7segm(CountValue); Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 0, 7, Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 0, 17)); CountValue = Chip_TIMER_ReadCount(LPC_TIMER32_0); } } |
//init Timer32 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); //CT32B0_CAP0 Chip_TIMER_Init(LPC_TIMER32_0);//init timer LPC_TIMER32_0->CTCR = 2;//falling edge CT32B0_CAP0 LPC_TIMER32_0->TCR = 1; //start timer |
void RIT_IRQHandler(void){ /* Clearn interrupt */ Chip_RIT_ClearInt(LPC_RITIMER); CountValue = Chip_TIMER_ReadCount(LPC_TIMER32_0); LPC_TIMER32_0->TC=0; // reset TC Chip_GPIO_WritePortBit(LPC_GPIO_PORT, 0, 7, !Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, 0, 7)); } /** * @briefMain entry point * @returnNothing */ int main(void) { /* Generic Initialization */ SystemCoreClockUpdate(); Board_Init(); setSYSTICK(); config7segm(); LPC_SYSCTL->SYSAHBCLKCTRL |= (1 << 9); Board_LED_Set(0, true); /* Initialize RITimer */ Chip_RIT_Init(LPC_RITIMER); /* Configure RIT for a 1s interrupt tick rate */ Chip_RIT_SetTimerInterval(LPC_RITIMER, TIME_INTERVAL); NVIC_EnableIRQ(RIT_IRQn); //init Timer32 Chip_GPIO_WriteDirBit(LPC_GPIO_PORT, 0, 17, 0); Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); //CT32B0_CAP0 Chip_TIMER_Init(LPC_TIMER32_0);//init timer LPC_TIMER32_0->CTCR = 2;//falling edge CT32B0_CAP0 LPC_TIMER32_0->TCR = 1;//start timer _delay_ms(600); while (1) { Imprime7segm(CountValue); // print value in 7 segments display } } |
//init Timer32 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 17, (IOCON_FUNC2 | IOCON_MODE_PULLUP)); //CT32B0_CAP0 Chip_TIMER_Init(LPC_TIMER32_0);//init timer LPC_TIMER32_0->CTCR = 2;//falling edge CT32B0_CAP0 LPC_TIMER32_0->TCR = 1; //start timer |
#include "LPC11xx.h" #define KHZ_PRESCALE (SystemCoreClock / 1000) volatile uint16_t rpm, tmp_rpm; volatile uint8_t status_flag = 0; // obsluga przerwania TMR16B0 void TIMER16_0_IRQHandler(void) { if ( LPC_TMR16B0->IR & (0x1<<1) ) { LPC_TMR16B0->IR = 1;// clear flag from MR0 rpm = tmp_rpm; tmp_rpm = 0; status_flag = 1; } if ( LPC_TMR16B0->IR & (0x1<<4) )// sprawdzenie czy przerwanie od kanalu zliczajacego { LPC_TMR16B0->IR = 0x1<<4;// skasowanie flagi przerwania tmp_rpm++; } } int main(void) { LPC_SYSCON->SYSAHBCLKCTRL |= 1<<16;//wlaczenie zegara dla bloku IOCON_LOC LPC_IOCON->PIO0_2 &= ~0x07;// zerowanie 3 pierwszych bitow LPC_IOCON->PIO0_2 |= 0x02;// CT16B0_CAP0 // konfiguracja timera TMR16B0 LPC_SYSCON->SYSAHBCLKCTRL |= 1<<7;// wlaczenie zegara dla bloku timera TMR16B0 LPC_TMR16B0->PR = KHZ_PRESCALE - 1; // ustawienie preskalera na 1 kHz LPC_TMR16B0->MR0 = 1000;// for 1 s LPC_TMR16B0->CTCR = 2; // rosnace zbocze rozpoczyna zliczanie i generuje przerwanie LPC_TMR16B0->MCR = (0x1<<0) | (0x1<<1);// interrupt and reset MR0 NVIC_EnableIRQ(TIMER_16_0_IRQn); LPC_TMR16B0->TCR = 1;// wlaczenie timera while(1) { if (status_flag == 1) { status_flag = 0; printf("RPM=%d\r\n", rpm); } } return 0 ; } |