今天试了PIC32系列,用的是MICROCHIP PIC32 START KIT系列的开发板DM320004,单片机型号是 PIC32MX795F512L ,测试的结果不错,在循环 100,000 次时,指示灯大约每秒切换一次。为了验证是不是因为计算同一个数值,计算过程给优化掉了,又改动了程序:
int main(void)
{
// Configure the device for maximum performance, but do not change the PBDIV clock divisor.
// Given the options, this function will change the program Flash wait states,
// RAM wait state and enable prefetch cache, but will not change the PBDIV.
// The PBDIV value is already set via the pragma FPBDIV option above.
SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
// LED setup
// Turn off leds before configuring the IO pin as output
mPORTDClearBits(BIT_0 | BIT_1 | BIT_2); // same as LATDCLR = 0x0007
// Set RD0, RD1 and RD2 as outputs
mPORTDSetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2 ); // same as TRISDCLR = 0x0007
//Initialize the DB_UTILS IO channel
DBINIT();
// Display a message using db_utils
DBPRINTF("Welcome to the PIC32 Blink Leds example. \n");
DBPRINTF("The build date and time is ... (" __DATE__ "," __TIME__ ")\n");
DBPRINTF("This example demonstrates a simple method to toggle LEDs. \n");
// endless loop
dbl_Cacu_Data = 1.1;
while(1)
{
iii = 10000000;
while (iii > 0){
dbl_Cacu_Data = atanf(3.1415926 / (float)iii); // 测试了sin(3.1415926 / (float)iii) 也是一样的快
iii --;
}
//DelayMs(100);
mPORTDToggleBits(BIT_0); // toggle LED0 (same as LATDINV = 0x0001)
//DelayMs(100);
//mPORTDToggleBits(BIT_1); // toggle LED1 (same as LATDINV = 0x0002)
//DelayMs(100);
//mPORTDToggleBits(BIT_2); // toggle LED2 (same as LATDINV = 0x0004)
}
return 0;
}
这样可以使每次计算的数值不同,使循环无法倍优化。
先后用了sin和atan测试,结果都是100000次一秒钟,不错,可以用来进行三维姿态反解计算一类的课题了。
评论