⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.c

📁 Kalman Filter PIC30F3011 testboard V3 源码
💻 C
字号:
/***********************************************************************
 *                                                                     *
 * This file contains the implementation of timer.h                    *
 *                                                                     *
 ***********************************************************************
 *                                                                     * 
 *    Author:         Tom Pycke                                        *
 *    Filename:       timer.c                                          *
 *    Date:           13/10/2007                                       *
 *    File Version:   1.00                                             *
 *    Other Files Required: timer.h                                    *
 *                          common.h                                   *
 *                                                                     *
 ***********************************************************************
 *                                                                     *
 * Other Comments:                                                     *
 *  Implements TIMER1 from dsPic to return time in seconds since last  *
 *  call.                                                              *
 *                                                                     *
 ***********************************************************************/
 
 
#include "common.h"

static const float ticks_per_second = (float)FCY;

void timer_init_ms()
{
	T1CONbits.TCS = 0;   // Internal clock (FOSC/4)
	T1CONbits.TCKPS = 0; // No prescaler
	T1CONbits.TON = 1;
	TMR1 = 0;            // Reset counter
}


void timer_reset()
{
	T1CONbits.TON = 0;
	TMR1 = 0;            // Reset counter
	T1CONbits.TON = 1;
}

/* 
 * Returns the time in seconds since the last call 
 * of this function (or last reset) 
 */
float timer_dt()
{
	float ticks = (float)TMR1;
	timer_reset();	
	return ticks/ticks_per_second;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -