| /*---------------------------------------------------------------------------------------------------------*/ /*  Main Function                                                                                          */
 /*---------------------------------------------------------------------------------------------------------*/
 int32_t main(void)
 {
 uint32_t i, CalTime;
 
 PIDS.Kp = 0.4;
 PIDS.Ki = 0.4;
 PIDS.Kd = 0;
 /* Target value*/
 target = 500;
 /* Inital value */
 ival = 0;
 /* Initial value and target value error */
 ee = target - ival;
 
 /* Unlock protected registers */
 SYS_UnlockReg();
 
 /* Init System, peripheral clock and multi-function I/O */
 SYS_Init();
 
 /* Lock protected registers */
 SYS_LockReg();
 
 /* Init UART for printf */
 UART_Init();
 
 /* Init TIMER0 for performance comparing */
 TIMER_Open(TIMER0, TIMER_CONTINUOUS_MODE, 1);
 
 TIMER_Start(TIMER0);
 
 /************************* DSP PID ******************************/
 /* Initial DSP PID controller function*/
 arm_pid_init_f32(&PIDS,0);
 
 /* Calculate PID controller function 100 times*/
 for(i = 1; i < 100; i++)
 {
 output[i] = arm_pid_f32(&PIDS,ee);
 ee = target-output[i-1];
 }
 
 TIMER_Close(TIMER0);
 CalTime = TIMER_GetCounter(TIMER0);
 printf("\nDSP PID: It took %d HXT clocks\n", CalTime);
 
 /********************** Software PID ****************************/
 /* Re-Initialization TIMER0 for performance comparing */
 TIMER_Open(TIMER0, TIMER_CONTINUOUS_MODE, 1);
 
 TIMER_Start(TIMER0);
 
 /* Calculate PID controller function 100 times*/
 for(i = 1; i < 100; i++)
 {
 output[i] = PID(ee);
 ee = target-output[i-1];
 }
 
 TIMER_Close(TIMER0);
 CalTime = TIMER_GetCounter(TIMER0);
 printf("Software PID: It took %d HXT clocks\n", CalTime);
 
 while(1);
 }
 
 
 |