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