/** * @brief main routine for timer example * @return Function should not exit. */ int main(void) { uint32_t timerBaseClock; SystemCoreClockUpdate(); Board_Init(); Board_LED_Set(0, false); Board_LED_Set(1, false); /* Initialize Timer 0 and Timer 1 */ Chip_TIMER_Init(LPC_TIMER0); Chip_TIMER_Init(LPC_TIMER1); /* Setup prescale value on Timer 0 to PCLK */ Chip_TIMER_PrescaleSet(LPC_TIMER0, 0); /* Setup prescale value on Timer 1 for lower resolution */ Chip_TIMER_PrescaleSet(LPC_TIMER1, PRESCALE_HZ2); /* Reset timers */ Chip_TIMER_Reset(LPC_TIMER0); Chip_TIMER_Reset(LPC_TIMER1); /* Enable both timers to generate interrupts when time matches */ Chip_TIMER_MatchEnableInt(LPC_TIMER0, 1); Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1); /* Get rate of timer base clock */ timerBaseClock = Chip_Clock_GetAsyncSyscon_ClockRate(); /* Setup Timer 0 for a match every 1s */ Chip_TIMER_SetMatch(LPC_TIMER0, 1, (timerBaseClock / TICKRATE_HZ1)); /* Setup Timer 1 for a match twice in a second */ Chip_TIMER_SetMatch(LPC_TIMER1, 1, (timerBaseClock / ((PRESCALE_HZ2 + 1) * TICKRATE_HZ2)) ); /* Setup both timers to restart when match occurs */ Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 1); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 1); /* Start both timers */ Chip_TIMER_Enable(LPC_TIMER0); Chip_TIMER_Enable(LPC_TIMER1); /* Clear both timers of any pending interrupts */ NVIC_ClearPendingIRQ(CT32B0_IRQn); NVIC_ClearPendingIRQ(CT32B1_IRQn); /* Enable both timer interrupts */ NVIC_EnableIRQ(CT32B0_IRQn); NVIC_EnableIRQ(CT32B1_IRQn); /* Wait for timers to generate interrupts (LEDs toggle in interrupt handlers) */ while (1) { __WFI(); } return 0; }
static void initHardware(void) { SystemCoreClockUpdate(); SysTick_Config(SystemCoreClock/1000); Board_Init(); Board_LED_Set(0, false); /* Timer */ Chip_TIMER_Init(LPC_TIMER1); Chip_TIMER_PrescaleSet(LPC_TIMER1, #ifdef lpc1769 Chip_Clock_GetPeripheralClockRate(SYSCTL_PCLK_TIMER1) / 1000000 - 1 #else Chip_Clock_GetRate(CLK_MX_TIMER1) / 1000000 - 1 #endif ); /* Match 0 (period) */ Chip_TIMER_MatchEnableInt(LPC_TIMER1, 0); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER1, 0); Chip_TIMER_StopOnMatchDisable(LPC_TIMER1, 0); Chip_TIMER_SetMatch(LPC_TIMER1, 0, 1000); /* Match 1 (duty) */ Chip_TIMER_MatchEnableInt(LPC_TIMER1, 1); Chip_TIMER_ResetOnMatchDisable(LPC_TIMER1, 1); Chip_TIMER_StopOnMatchDisable(LPC_TIMER1, 1); Chip_TIMER_SetMatch(LPC_TIMER1, 1, 100); Chip_TIMER_Reset(LPC_TIMER1); Chip_TIMER_Enable(LPC_TIMER1); NVIC_EnableIRQ(TIMER1_IRQn); }
void AVALON_PWM_Init(void) { /* System CLK 48MHz */ Chip_TIMER_Init(LPC_TIMER16_0); Chip_TIMER_Disable(LPC_TIMER16_0); /* CT16B0_MAT0/CT16B0_MAT1/CT16B0_MAT2 Init */ Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 8, IOCON_FUNC2 | IOCON_MODE_INACT); Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, IOCON_FUNC2 | IOCON_MODE_INACT); Chip_IOCON_PinMuxSet(LPC_IOCON, 1, 15, IOCON_FUNC2 | IOCON_MODE_INACT); /* CT16B0_MAT0 duty:50% */ Chip_TIMER_ExtMatchControlSet(LPC_TIMER16_0, 1, TIMER_EXTMATCH_TOGGLE, 0); Chip_TIMER_SetMatch(LPC_TIMER16_0, 0, DUTY_50); /* CT16B0_MAT1 duty:25% */ Chip_TIMER_ExtMatchControlSet(LPC_TIMER16_0, 1, TIMER_EXTMATCH_TOGGLE, 1); Chip_TIMER_SetMatch(LPC_TIMER16_0, 1, DUTY_25); /* CT16B0_MAT2 duty:10% */ Chip_TIMER_ExtMatchControlSet(LPC_TIMER16_0, 1, TIMER_EXTMATCH_TOGGLE, 2); Chip_TIMER_SetMatch(LPC_TIMER16_0, 2, DUTY_10); /* Prescale 0 */ Chip_TIMER_PrescaleSet(LPC_TIMER16_0, 0); /* PWM Period 800Hz */ Chip_TIMER_SetMatch(LPC_TIMER16_0, 3, DUTY_100); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_0, 3); /* CT16B0_MAT0/CT16B0_MAT1/CT16B0_MAT2 Enable */ LPC_TIMER16_0->PWMC = 0x7;//pwm Chip_TIMER_Enable(LPC_TIMER16_0); }
void init_runtime_stats_timer( void ) { Chip_TIMER_Init(LPC_TIMER3); Chip_TIMER_Reset(LPC_TIMER3); Chip_Clock_SetPCLKDiv(SYSCTL_PCLK_TIMER3, SYSCTL_CLKDIV_1); Chip_TIMER_PrescaleSet(LPC_TIMER3, 3200); Chip_TIMER_Enable(LPC_TIMER3); }
uint32_t PWMSetPeriod(uint8_t channel, uint32_t period) { if (channel > CHANNEL_C_TIMER_INDEX) { return 1; } if (eDVSMode != EDVS_MODE_INTERNAL && channel == 0) { return 1; // channel 0 taken for master/slave mode } LPC_TIMER_T * timer = halTimers[channel].timer; halTimers[channel].period = period; /** * If the period equal 0, the timer is disable and its outputs are set as GPIO and driven low. */ if (period == 0) { Chip_TIMER_DeInit(timer); //Stop the timer Chip_TIMER_SetMatch(timer, 2, 0); halTimers[channel].enabled[0] = DISABLE; halTimers[channel].enabled[1] = DISABLE; Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]); Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[0], halTimers[channel].pinGpio[0]); Chip_GPIO_SetPinOutLow(LPC_GPIO_PORT, halTimers[channel].portGpio[1], halTimers[channel].pinGpio[1]); Chip_SCU_PinMuxSet(halTimers[channel].port[0], halTimers[channel].pin[0], halTimers[channel].gpioMode[0]); Chip_SCU_PinMuxSet(halTimers[channel].port[1], halTimers[channel].pin[1], halTimers[channel].gpioMode[1]); } else { /** * The channel match 2 is used as the controller of the base frequency. * When there is a match on this channel, the timer is reset and the external match bit * is set to 1. * The M0 core is looking for this change and it sets the output of the channels to high. */ Chip_TIMER_Init(timer); Chip_TIMER_Disable(timer); Chip_TIMER_Reset(timer); /** * The Main clock is running at 192Mhz so set the Prescaler in order to have * a 1 Mhz timer. Timer_CLK = Main_CLK/ (PR+1) */ Chip_TIMER_PrescaleSet(timer, 191); Chip_TIMER_ResetOnMatchEnable(timer, 2); Chip_TIMER_StopOnMatchDisable(timer, 2); Chip_TIMER_MatchDisableInt(timer, 2); Chip_TIMER_SetMatch(timer, 2, period); //Reconfigure match channels! if (halTimers[channel].enabled[0]) { PWMSetWidth(channel, 0, halTimers[channel].witdh[0]); } if (halTimers[channel].enabled[1]) { PWMSetWidth(channel, 1, halTimers[channel].witdh[1]); } Chip_TIMER_ExtMatchControlSet(timer, 0, TIMER_EXTMATCH_SET, 2); // Clear interrupt pending timer->IR = 0xFFFFFFFF; Chip_TIMER_Enable(timer); } return 0; }
/* Initialize stopwatch */ void StopWatch_Init(void) { /* Use timer 1. Set prescaler to divide by 8 */ const uint32_t prescaleDivisor = 8; Chip_TIMER_Init(LPC_TIMER32_1); Chip_TIMER_PrescaleSet(LPC_TIMER32_1, prescaleDivisor - 1); Chip_TIMER_Enable(LPC_TIMER32_1); /* Pre-compute tick rate. */ ticksPerSecond = Chip_Clock_GetAsyncSysconClockRate() / prescaleDivisor; ticksPerMs = ticksPerSecond / 1000; ticksPerUs = ticksPerSecond / 1000000; }
void setup() { const uint32 system_clock_hz = Chip_Clock_GetSystemClockRate(); const uint32 prescale = system_clock_hz / 1000000; Chip_TIMER_Init(SYS_CLOCK_TIMER32); // Set prescaler for 1 usec/count. Chip_TIMER_PrescaleSet(SYS_CLOCK_TIMER32, prescale - 1); // Reset count Chip_TIMER_Reset(SYS_CLOCK_TIMER32); // Start counting. Chip_TIMER_Enable(SYS_CLOCK_TIMER32); }
void AVALON_PWM_Enable(void) { /* Prescale 0 */ Chip_TIMER_PrescaleSet(LPC_TIMER16_0, 0); /* PWM Period 800Hz */ Chip_TIMER_SetMatch(LPC_TIMER16_0, 3, DUTY_100); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER16_0, 3); /* CT16B0_MAT0/CT16B0_MAT1/CT16B0_MAT2 Enable */ LPC_TIMER16_0->PWMC = 0x7; Chip_TIMER_Enable(LPC_TIMER16_0); }
/** Configures the board hardware and chip peripherals for the demo's functionality. */ static void SetupHardware(void) { Board_Init(); USB_Init(FlashDisk_MS_Interface.Config.PortNumber, USB_MODE_Host); /* Hardware Initialization */ Board_Debug_Init(); /* Create a stdio stream for the serial port for stdin and stdout */ Serial_CreateStream(NULL); Chip_TIMER_Init(RUNTIME_TIMER); //Chip_TIMER_TIMER_SetCountClockSrc(RUNTIME_TIMER, TIMER_CAPSRC_RISING_PCLK, 0); Chip_TIMER_PrescaleSet(RUNTIME_TIMER, 0); }
/* Initialize stopwatch */ void StopWatch_Init(void) { /* Use timer 1. Set prescaler to divide by 8, should give ticks at 3.75 MHz. That gives a useable stopwatch measurement range of about 19 minutes (if system clock is running at 120 MHz). */ const uint32_t prescaleDivisor = 8; Chip_TIMER_Init(LPC_TIMER1); Chip_TIMER_PrescaleSet(LPC_TIMER1, prescaleDivisor - 1); Chip_TIMER_Enable(LPC_TIMER1); /* Pre-compute tick rate. Note that peripheral clock supplied to the timer includes a fixed divide by 4. */ ticksPerSecond = Chip_Clock_GetSystemClockRate() / prescaleDivisor / 4; ticksPerMs = ticksPerSecond / 1000; ticksPerUs = ticksPerSecond / 1000000; }
void setupTimer(void) { Chip_IOCON_PinMux(LPC_IOCON, 1, 28, 2, 3); Chip_GPIO_SetPinDIROutput(LPC_GPIO, 1, 28); Chip_TIMER_Init(LPC_TIMER0); Chip_TIMER_Reset(LPC_TIMER0); Chip_TIMER_PrescaleSet(LPC_TIMER0, 500); Chip_TIMER_SetMatch(LPC_TIMER0, 0, 16000); Chip_TIMER_ResetOnMatchEnable(LPC_TIMER0, 0); // Chip_TIMER_MatchEnableInt(LPC_TIMER0, 0); Chip_TIMER_ExtMatchControlSet(LPC_TIMER0, RESET, TIMER_EXTMATCH_TOGGLE, 0); Chip_TIMER_Enable(LPC_TIMER0); // NVIC_ClearPendingIRQ(TIMER0_IRQn); // NVIC_EnableIRQ(TIMER0_IRQn); }
void call_init (void) { transmit_call = false; Chip_TIMER_Init (LPC_TIMER32_0); Chip_TIMER_Reset (LPC_TIMER32_0); Chip_TIMER_MatchEnableInt (LPC_TIMER32_0, 0); Chip_TIMER_PrescaleSet (LPC_TIMER32_0, Chip_Clock_GetSystemClockRate ()); Chip_TIMER_SetMatch (LPC_TIMER32_0, 0, CALL_INTERVAL_SEC); Chip_TIMER_ResetOnMatchEnable (LPC_TIMER32_0, 0); Chip_TIMER_Enable (LPC_TIMER32_0); NVIC_ClearPendingIRQ (TIMER_32_0_IRQn); NVIC_EnableIRQ (TIMER_32_0_IRQn); }
void Board_TIMER_EnableTimerAsTimer(uint8_t timerNum, uint32_t presc,uint32_t matchValue,bool flagOnce) { // always using match0 int8_t match=0; LPC_TIMER_T* t = getTimerFomIndex(timerNum); Chip_TIMER_PrescaleSet(t, presc); Chip_TIMER_SetMatch(t, match, matchValue); Chip_TIMER_MatchEnableInt(t, match); // enable int for match 0 if(flagOnce==1) { Board_TIMER_DisableTimer(timerNum); Board_TIMER_SetTimerCounter(timerNum,0); Chip_TIMER_ResetOnMatchDisable(t, match); // reset count on match0 } else { Chip_TIMER_ResetOnMatchEnable(t, match); // reset count on match0 } Chip_TIMER_Enable(t); }
/* * Wind Speed translation : V = p*(2,25/t) * V: speed in mph * p: pulses per sampelperiod * t: sample period in sec */ void setupirq(){ DBG("Initialize Wind Cups...\n"); Chip_GPIOINT_Init(LPC_GPIOINT); Chip_GPIO_SetPinDIRInput(LPC_GPIO,2,13); Chip_GPIO_SetPinState(LPC_GPIO, 2, 13, true); Chip_IOCON_PinMux(LPC_IOCON, 2, 13, IOCON_MODE_PULLUP, IOCON_FUNC0); const uint32_t prescaleDivisor = 8; Chip_TIMER_Init(LPC_TIMER2); Chip_TIMER_PrescaleSet(LPC_TIMER2, prescaleDivisor - 1); Chip_TIMER_Enable(LPC_TIMER2); ticksPerSecond = Chip_Clock_GetSystemClockRate() / prescaleDivisor / 4; Chip_GPIOINT_SetIntFalling(LPC_GPIOINT, GPIOINT_PORT2, (1 << 13)); Chip_GPIOINT_ClearIntStatus(LPC_GPIOINT, GPIOINT_PORT2, (1 << 13)); NVIC_ClearPendingIRQ(EINT3_IRQn); NVIC_EnableIRQ(EINT3_IRQn); DBG("Initialize Wind Cups complete...\n"); }
void Board_TIMER_SetTimerPrescaler(uint8_t timerNum,uint32_t value) { Chip_TIMER_PrescaleSet(getTimerFomIndex(timerNum), value); }