pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


comp-cap: Move |filtered_duration = 0|
Posted by Anonymous on Wed 23rd Oct 2019 12:30
raw | new post
modification of post by Anonymous (view diff)

  1. diff --git a/ptxdist/local_src/ecu01-comp-cap/mmc_imp.c b/ptxdist/local_src/ecu01-comp-cap/mmc_imp.c
  2. index 42d913d..187afe4 100644
  3. --- a/ptxdist/local_src/ecu01-comp-cap/mmc_imp.c
  4. +++ b/ptxdist/local_src/ecu01-comp-cap/mmc_imp.c
  5. @@ -171,221 +171,222 @@ int qa_mmc_calc( struct qa_mmc_dev *dev )
  6.     read_unlock_irqrestore(&cc_phaseL->lock, flags);
  7.  
  8.     // copy right values
  9.     flags = 0;
  10.     read_lock_irqsave(&cc_phaseR->lock, flags);
  11.     for (i=0;i < MAX_VALUE_CNT_QA; i++) {
  12.        t_phase_R_tmp[i] =  cc_phaseR->value_aul[i]-i_overflow;
  13.     }
  14.     read_unlock_irqrestore(&cc_phaseR->lock, flags);
  15.  
  16.     // calculate durations from tmp arrays
  17.  
  18.     for (i=0;i < MAX_VALUE_CNT_QA-1 ;i++) {
  19.        t_periode_duartion[i] = t_periode_tmp[i]-t_periode_tmp[i+1];
  20.        t_phase_L_duartion[i] = t_phase_L_tmp[i]-t_phase_L_tmp[i+1];
  21.        t_phase_R_duartion[i] = t_phase_R_tmp[i]-t_phase_R_tmp[i+1];
  22.     }
  23.  
  24.     // Clean all ISR buffers if 16 old values exist and if the newest is older than 1 second
  25.  
  26.     if(t_periode_tmp[16] != 0){  // There are at least 16 ref values
  27.  
  28.        // read current time and correct it by i_overflow, too
  29.        get_cnt_value(dev->cc_dev_Ref, &cnt_value);
  30.        timer_now = cnt_value - i_overflow;
  31.  
  32.        // test if newest value in rev value is older than 1 second
  33.        if ( ( timer_now - t_periode_tmp[0] ) > TIMER_SPEED) {
  34.  
  35.            // Clear ref values
  36.           flags = 0;
  37.           read_lock_irqsave(&cc_phaseRef->lock, flags);
  38.           for (i=0;i < MAX_VALUE_CNT_QA; i++) {
  39.              cc_phaseRef->value_aul[i] =  0;
  40.           }
  41.           read_unlock_irqrestore(&cc_phaseRef->lock, flags);
  42.  
  43.           // Clear left values
  44.           flags = 0;
  45.           read_lock_irqsave(&cc_phaseL->lock, flags);
  46.           for (i=0;i < MAX_VALUE_CNT_QA; i++) {
  47.              cc_phaseL->value_aul[i] =  0;
  48.           }
  49.           read_unlock_irqrestore(&cc_phaseL->lock, flags);
  50.  
  51.           // Clear right values
  52.           flags = 0;
  53.           read_lock_irqsave(&cc_phaseR->lock, flags);
  54.           for (i=0;i < MAX_VALUE_CNT_QA; i++) {
  55.             cc_phaseR->value_aul[i] =  0;
  56.           }
  57.           read_unlock_irqrestore(&cc_phaseR->lock, flags);
  58.  
  59.        }
  60.     }
  61.  
  62.     if(t_periode_tmp[16] != 0){  // There are at least 16 ref values
  63.  
  64.        // be carefull not to chgen the order of that sequence. l_periode_duartion is used for left and right, too
  65.        // at the end l_periode_duartion must have the value of the ref signal!
  66.  
  67.        // mean value of right values
  68.        l_periode_duartion = 0;
  69.        for (i=0;i < 12 ;i++) {
  70.           l_periode_duartion += t_phase_R_duartion[i];
  71.        }
  72.        l_periode_duartion /= 12;
  73.        // if duration is 0 there were no signals captured. This is an error
  74.        if(l_periode_duartion == 0) i_mmc_error |= 0x4;
  75.  
  76.        // mean value of left values
  77.        l_periode_duartion = 0;
  78.        for (i=0;i < 12 ;i++) {
  79.          l_periode_duartion += t_phase_L_duartion[i];
  80.        }
  81.        l_periode_duartion /= 12;
  82.        // if duration is 0 there were no signals captured. This is an error
  83.        if(l_periode_duartion == 0) i_mmc_error |= 0x2;
  84.  
  85.        // mean value of ref values
  86.        l_periode_duartion = 0;
  87.        for (i=0;i < 12 ;i++) {
  88.          l_periode_duartion += t_periode_duartion[i];
  89.        }
  90.        l_periode_duartion /= 12;
  91.        // if duration is 0 there were no signals captured.  This is an error
  92.        if(l_periode_duartion == 0) i_mmc_error |= 0x1;
  93.        // if duration is longer than 100 ms the frequencey of pulses is less than 10 Hz.  This is an error
  94.        if(l_periode_duartion > MAX_MMC_PERIODE_DELAY) i_mmc_error |= 0x8;
  95.  
  96. +      filtered_duration = 0;
  97. +
  98.        // Filter to eliminate values much longer than average or much shorter than everage.  
  99.        // To prevent side effects activate filter only if L and R signal are not present
  100.        // Interrupt from these signals should be preventet by disabling them if the bridge from Pin C3 to C4
  101.        // is installed for FAG Sensors
  102.  
  103.        if ( 0x6 == (i_mmc_error & 0x6) ) {
  104.  
  105.          // There are 2 cases for shorter period than before
  106.          // 1. Normal: The periode decereased because the speed raised.
  107.          //            In this case all values in the array change their values and are close together.
  108.          //            The average over all 12 values will be fine.
  109.          // 2. Error: We got one or more additional interrupts.
  110.          //           in this case we get one periode with is at less than half in value and on period
  111.          //           which is more than half in value. But the sum of both is nearly the correct period.
  112.          // Therefore we compare the values in the array to 0,8 * ul_periode_tmp which is the last average
  113.          // If the additional interrupt is close to the real signal pulse, one of both values will pass the filter.
  114.          // but if the additional interrupts is somewhere in the middle or if the is more than one additonal interrupt,
  115.          // all additional periods are too short to pass the filter.
  116.  
  117.          const unsigned int l_periode_duartion_min = ul_periode_tmp*8/10;
  118.  
  119.          // There are 2 cases for longer periods than before
  120.          // 1. Normal: The periode increased because the speed reduced.
  121.          //            In this case all values in the array change their values and are close together.
  122.          //            The average over all 12 values will be fine.
  123.          // 2. Error: We lost one or more interrupts. We get periods with are at least double of correct value.
  124.          //           If only 1 interrupts is lost the mean value over all changes is wrong by an factor of only 13 / 12 = 1,08.
  125.          //           Using this new mean value as reference seems not practical.
  126.          // If nothing passes the filter, the total average over all 12 values is used.
  127.          // This average might leed to a speed too low if we lose interrupts. But in the next cycle this average
  128.          // is rather close to the new values in the array.
  129.          // Therefore we compare the values in the array to 1,5 * ul_periode_tmp which is the last average
  130.  
  131.          const unsigned int l_periode_duartion_max = ul_periode_tmp*15/10;
  132.  
  133.          unsigned int j   = 0;
  134.          unsigned int rej = 0;
  135.  
  136.          ++filter_cnt;
  137.  
  138. -        filtered_duration = 0;
  139.  
  140.          for(i=0; i< 12; i++) {
  141.            if((t_periode_duartion[i] > l_periode_duartion_min) && (t_periode_duartion[i] < l_periode_duartion_max)) {
  142.              filtered_duration += t_periode_duartion[i];
  143.                 ++j;
  144.            } else {
  145.                 //printk("CC filter (%0x) rejected: %x, mean: %x\n", filter_cnt, t_periode_duartion[i], l_periode_duartion);
  146.             rej += t_periode_duartion[i];
  147.           }
  148.      }
  149.  
  150.         if(j != 0) {     // at least one value passed the filter
  151.                 filtered_duration /= j;
  152.         }
  153.  
  154.         // sum up 1 for each active filtering
  155.         if(j!=12) {
  156.                 ++filter_rej;
  157.                 rej /= (12-j);
  158.                 //printk("CC filter (%0x) rejected %d values: filtered: %x mean: %x (min: %x, max: %x) last: %x, rej_mean: %x\n", filter_cnt, 12-j, filtered_duration, l_periode_duartion, l_periode_duartion_min, l_periode_duartion_max, ul_periode_tmp, rej);
  159.         }
  160.        }
  161.  
  162.        // Wenn das Filter einen Wert berechnet und nicht alles verwirft, dann wird der gefilterte Wert benutzt.
  163.        // Ansonsten wird der Mittelwert ?ber alle Werte verwendet.
  164.  
  165.        dev->ioc.durationRef = filtered_duration ? filtered_duration : l_periode_duartion;
  166.  
  167.        // Falls kein Fehler anliegt, berechne die Phasenverschiebungen
  168.        if(!(i_mmc_error & 0x9) ) {
  169.           // Falls PhaseL anliegt, berechne Phasenverschiebung left
  170.           if(!(i_mmc_error & 0x2) ) {
  171.              dev->ioc.phaseL = GetPhaseShift(t_periode_tmp, t_phase_L_tmp, MAX_VALUE_CNT_QA, l_periode_duartion);
  172.           }
  173.           // Falls Phasenverschiebung 0 ist, liegt keine PhaseL an => Fehler
  174.           if (!(dev->ioc.phaseL))
  175.              i_mmc_error |= 0x2;
  176.  
  177.           // Falls PhaseR anliegt, berechne Phasenverschiebung right
  178.           if(!(i_mmc_error & 0x4) ) {
  179.              dev->ioc.phaseR = GetPhaseShift(t_periode_tmp, t_phase_R_tmp, MAX_VALUE_CNT_QA, l_periode_duartion);
  180.           }
  181.           // Falls Phasenverschiebung 0 ist, liegt keine PhaseR an => Fehler
  182.           if (!(dev->ioc.phaseR))
  183.              i_mmc_error |= 0x4;
  184.        }
  185.  
  186.     }
  187.     else {  
  188.        i_mmc_error |= 0x8;   // There are less than 16 ref values
  189.     }
  190.  
  191.     if( i_mmc_error == 0x7)  // Was bedeutet das?
  192.        i_mmc_error = 0xf;
  193.  
  194.     if( i_mmc_error &  0x1)
  195.        i_mmc_error |= 0x8;  // Was bedeutet das?
  196.  
  197.     // if Left is missing, stick to old value
  198.     if(dev->ioc.phaseL)
  199.        ul_phase_L_tmp = dev->ioc.phaseL;
  200.     else
  201.        dev->ioc.phaseL = ul_phase_L_tmp;
  202.  
  203.     // if Right is missing, stick to old value
  204.     if(dev->ioc.phaseR)
  205.        ul_phase_R_tmp = dev->ioc.phaseR;
  206.     else
  207.        dev->ioc.phaseR = ul_phase_R_tmp;
  208.  
  209.     // if ref is missing, stick to old value
  210.     if(dev->ioc.durationRef)
  211.        ul_periode_tmp = dev->ioc.durationRef;
  212.     else
  213.        dev->ioc.durationRef = ul_periode_tmp;
  214.  
  215.     dev->ioc.mmcError = i_mmc_error;
  216.  
  217.     get_counter(dev->cc_dev_Ref, &(dev->ioc.RefCnt));
  218.     dev->ioc.RefError = filter_rej;
  219.     struct cc_stat value;
  220.     get_isr_error_value(dev->cc_dev_Ref, &(value));
  221.  
  222.     dev->ioc.IsrTolerCnt = value.isr_toler_cnt;
  223.     dev->ioc.IsrMaxDelay = value.isr_max_delay;
  224.     dev->ioc.IsrAvgDelay = value.isr_avg_delay;
  225.     dev->ioc.IsrDelayCov = value.isr_delay_cov;
  226.  
  227.     //printk(iode_duartion[i] > l_periode_duartion_min) && (t_periode_duartion[i] < l_periode_duartion_max)) {

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at