Changeset 1329 for applications

Show
Ignore:
Timestamp:
04/13/11 12:16:50 (13 years ago)
Author:
smidl
Message:

correct rounding in Choleski

Location:
applications/pmsm/simulator_zdenek/ekf_example
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp

    r1326 r1329  
    542542                        else 
    543543                */       
    544                 if (tmp_sum>0) 
    545                         *respom++=(tmp_sum+(1<<14)-1)>>15; 
    546                 else  
    547                         *respom++=(tmp_sum-(1<<14)+1)>>15; 
     544                *respom++=(tmp_sum+(1<<14))>>15; 
    548545                 
    549546                        tmp_sum=0; 
     
    597594                                        tau=((int32)c**A_kj-(int32)s**Ch_ki)>>14; 
    598595                                        tmp_long=(int32)s**A_kj+(int32)c**Ch_ki; 
    599                                         if (tmp_long>(1<<28)) //q14 + q15 
    600                                                 *Ch_ki = (1<<14)-1; 
     596                                        if (tmp_long>(1<<29)) //q14 + q14 
     597                                                *Ch_ki = (1<<15)-1; 
    601598                                        else  
    602599                                                *Ch_ki=tmp_long>>14; 
     
    741738                        //            alpha+=((long)sigma*sigma)>>15; 
    742739                        tmp_long=((int32)alpha<<15)+(((int32)sigma*sigma)<<(30-2*qCh)); 
    743                         if (tmp_long>0) 
    744                                 alpha=(tmp_long+(1<<14)-1)>>15;                         // vyssi presnost 
    745                         else 
    746                                 alpha=(tmp_long-(1<<14)+1)>>15;                         // vyssi presnost 
     740                        alpha=(tmp_long+(1<<14))>>15;                           // vyssi presnost 
    747741                                         
    748742                        //            gamma= qsqrt(((long)alpha*beta));                          // verze pro DSP 
     
    769763                                //                w_i+=((long)tau*sigma)>>15; 
    770764                                tmp_long = ((int32)*w_i<<15)+((int32)tau*sigma<<(30-2*qCh)); 
    771                                 /*if (tmp_long>0) 
    772                                         *w_i=(tmp_long+(1<<14)-1)>>15; 
    773                                 else  
    774                                         *w_i=(tmp_long-(1<<14)+1)>>15; 
    775                                 */ *w_i=(tmp_long)>>15; 
     765                                *w_i=(tmp_long+(1<<14))>>15; 
    776766                                 
    777767                                w_i++; 
     
    789779                        w_i++; 
    790780                } 
    791                 printf("Kg: %d %d\n",w[0],w[1]); 
    792         } 
    793 } 
    794  
     781        } 
     782} 
     783 
  • applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.h

    r1321 r1329  
    1616#define qCh 14 
    1717 
    18 #define int16 int //short 
    19 #define int32 long //int 
     18#define int16 short 
     19#define int32 int 
    2020 
    2121/* Matrix multiply Full matrix by upper diagonal matrix with unit diagonal; */