求高手解释一下。我现在要做一个测高频的频率计,需要用到1ms的延时,测这1ms的脉冲个数,但是计出的结果有很大误差,我怀疑是内部的DCO晶振不准
是不是launchpad不能外接晶振?怎么计到比较准的频率?我用得是DCO 8MHz频率,我的延时程序如下:
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
此帖出自
小平头技术问答
- #include
- void main(void)
- {
- WDTCTL = WDTPW +WDTHOLD; // Stop Watchdog Timer
- if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
- {
- while(1); // If calibration constants erased
- // do not load, trap CPU!!
- }
- //1Mhz
- BCSCTL1 = CALBC1_1MHZ; // Set range
- DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation */
- /* //8Mhz
- BCSCTL1 = CALBC1_8MHZ; // Set range
- DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
- /* //12Mhz
- BCSCTL1 = CALBC1_12MHZ; // Set range
- DCOCTL = CALDCO_12MHZ; // Set DCO step + modulation*/
- /* //16Mhz
- BCSCTL1 = CALBC1_16MHZ; // Set range
- DCOCTL = CALDCO_16MHZ; // Set DCO step + modulation*/
- P1DIR |= 0x13; // P1.0,1 and P1.4 outputs
- P1SEL |= 0x11; // P1.0,4 ACLK, SMCLK output
- while(1)
- {
- P1OUT |= 0x02; // P1.1 = 1
- P1OUT &= ~0x02; // P1.1 = 0
- }
- }
复制代码我试下来,8M的更准一些6楼的应该没有包含头文件所以出错了
其实这些东西在TI产品页面的Code Example里面都有的
一周热门 更多>