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

📄 calibrate.c

📁 基于cc1010的设计实例
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                    CHIPCON CC1010 EXAMPLE PROGRAM            *
 *      ***   + +   ***             REAL TIME CLOCK CALIBRATION              *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 * This program is used solely for calibrating the constants of the Real     *
 * Time Clock (RTC) module for different clock frequencies.                  *
 *                                                                           *
 * INSTRUCTIONS:                                                             *
 * The board to be used must have a serial interface and be running on the   *
 * desired clock frequency. Connect it to a terminal window on a PC using    *
 * the serial port with baudrate 38400.                                      *
 * Let the program run until the mean-values stabilize.                      *
 * Decrement the constant TIME_LOST_DURING_POWER_UP by the mean value for    *
 * power up. Decrement the constant TIME_LOST_DURING_POWER_DOWN by the mean  *
 * value for power down.                                                     *
 *                                                                           *
 * HOW IT WORKS:                                                             *
 * The CC1010 will power up or down every second using the hardware RTC      *
 * interrupt timer and check the values obtained from the RTC software       *
 * module.                                                                   *
 *****************************************************************************
 * Author:              OGR                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 *                                                                           *
 * $Log: calibrate.c,v $
 * Revision 1.1  2003/07/29 11:11:48  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/hal.h>
#include <chipcon/cul.h>
#include <stdio.h>

#define CLKFREQ 14746

#define PERIOD 1

bool first = TRUE; 
bool sleeping = FALSE;
ulong lastTime = 0;
long totalDriftPowerUp = 0;
long totalDriftPowerDown = 0;
word powerUps = 0;
word powerDowns = 0;

// This function is called every second.
// It powers the chip up or down.
// The software RTC is read and compared
// to the hardware RTC.
void measure() interrupt INUM_RTC {
	volatile ulong newTime = getTime();
	long diff;
	if (sleeping) {
		useXOSC();
	}
	RTCIF = 0;
	if (first) {
		first = FALSE;
		lastTime = newTime;
		sleeping = TRUE;
		useX32();
		return;
	}
	diff = newTime - lastTime - PERIOD*1000000;
	printf("%9lu   ",newTime);
	lastTime = newTime;
	if (sleeping) {
		++powerDowns;
		totalDriftPowerDown += diff;
		printf("POWER DOWN  last: %7ld   mean: %7ld\n",diff,totalDriftPowerDown/powerDowns);
		sleeping = FALSE;
	} else {
		++powerUps;
		totalDriftPowerUp += diff;
		printf("POWER UP    last: %7ld   mean: %7ld\n",diff,totalDriftPowerUp/powerUps);
		sleeping = TRUE;
		useX32();
	}
}


//Main function
int main(void){
	
	ulong teller = 0;

	X32_INPUT_SOURCE(X32_USING_CRYSTAL);
	X32_ENABLE(TRUE);

	//Turn off watchdog
    //(otherwise the CC1010 will reset after a predefined time)
    WDT_ENABLE(FALSE);

    // Set optimum settings for speed and low power consumption
    MEM_NO_WAIT_STATES();
    FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);

    //Setup UART0 with polled I/O
    UART0_SETUP(38400, CLKFREQ, UART_NO_PARITY | UART_RX_TX | UART_POLLED);

	halConfigRealTimeClock(PERIOD);

	RTstart();
    RTC_RUN(TRUE);

	while (1);

}

⌨️ 快捷键说明

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