コード例 #1
0
ファイル: PID.c プロジェクト: KellyHwong/EMouse
void PID_Init_Timer(void) {
  uint32_t ui32SystemClock;
  SysCtlPeripheralEnable(PID_TIMER_PERIPH);
  //设置为周期性定时器
  TimerConfigure(PID_TIMER, TIMER_CFG_PERIODIC);
  //设置为系统时钟 50MHz
  TimerClockSourceSet(PID_TIMER, TIMER_CLOCK_SYSTEM);
  ui32SystemClock = SysCtlClockGet();
  //50,000-1就是1ms, 50-1就是1us
  TimerLoadSet(PID_TIMER, TIMER_A, ui32SystemClock / 1000 * PID_DELAY_TIME - 1);

  TimerIntRegister(PID_TIMER, TIMER_A, PIDTimerIntHandler);
  TimerIntClear(PID_TIMER, TIMER_TIMA_TIMEOUT);
  //开始计时
  TimerEnable(PID_TIMER, TIMER_A);
  //不允许处理中断(开始时开启)
  TimerIntDisable(PID_TIMER, TIMER_TIMA_TIMEOUT);
}
コード例 #2
0
ファイル: sht1x.c プロジェクト: zolkko/blumenplace-uc
/*
 * Initializes timer to trigger an overflow interrupt every 1/SHT1X_CLOCK_HZ seconds.
 * The function also configures uDMA to trigger timer's interrupt handler.
 *
 * If uDMA is enabled and its transaction is in progress it blocks normal interrupt
 * flow of the timer.
 */
void sht1x_timer_init(void)
{
	SysCtlPeripheralEnable(SHT1X_TIMER_PERIPH);

	IntDisable(SHT1X_TIMER_INTERRUPT);
	TimerIntDisable(SHT1X_TIMER_BASE, TIMER_TIMA_TIMEOUT);
	TimerDisable(SHT1X_TIMER_BASE, SHT1X_TIMER);

	TimerConfigure(SHT1X_TIMER_BASE, TIMER_CFG_A_PERIODIC);
	TimerPrescaleSet(SHT1X_TIMER_BASE, SHT1X_TIMER, 0);
	TimerClockSourceSet(SHT1X_TIMER_BASE, TIMER_CLOCK_SYSTEM);
	TimerLoadSet(SHT1X_TIMER_BASE, SHT1X_TIMER, SHT1X_CLK_NR);

	TimerDMAEventSet(SHT1X_TIMER_BASE, TIMER_DMA_TIMEOUT_A);

	TimerIntClear(SHT1X_TIMER_BASE, TIMER_TIMA_TIMEOUT);
	IntEnable(SHT1X_TIMER_INTERRUPT);
}