|
@@ -852,25 +852,34 @@ float junction_deviation = 0.1;
|
852
|
852
|
block->nominal_rate = ceil(block->step_event_count * inverse_second); // (step/sec) Always > 0
|
853
|
853
|
|
854
|
854
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
|
855
|
+ static float filwidth_e_count = 0, filwidth_delay_dist = 0;
|
|
856
|
+
|
855
|
857
|
//FMM update ring buffer used for delay with filament measurements
|
856
|
|
- if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && delay_index2 > -1) { //only for extruder with filament sensor and if ring buffer is initialized
|
|
858
|
+ if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index2 >= 0) { //only for extruder with filament sensor and if ring buffer is initialized
|
|
859
|
+
|
|
860
|
+ const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
|
|
861
|
+
|
|
862
|
+ // increment counters with next move in e axis
|
|
863
|
+ filwidth_e_count += delta_mm[E_AXIS];
|
|
864
|
+ filwidth_delay_dist += delta_mm[E_AXIS];
|
857
|
865
|
|
858
|
|
- const int MMD = MAX_MEASUREMENT_DELAY + 1, MMD10 = MMD * 10;
|
|
866
|
+ // Only get new measurements on forward E movement
|
|
867
|
+ if (filwidth_e_count > 0.0001) {
|
859
|
868
|
|
860
|
|
- delay_dist += delta_mm[E_AXIS]; // increment counter with next move in e axis
|
861
|
|
- while (delay_dist >= MMD10) delay_dist -= MMD10; // loop around the buffer
|
862
|
|
- while (delay_dist < 0) delay_dist += MMD10;
|
|
869
|
+ // Loop the delay distance counter (modulus by the mm length)
|
|
870
|
+ while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
|
863
|
871
|
|
864
|
|
- delay_index1 = delay_dist / 10.0; // calculate index
|
865
|
|
- delay_index1 = constrain(delay_index1, 0, MAX_MEASUREMENT_DELAY); // (already constrained above)
|
|
872
|
+ // Convert into an index into the measurement array
|
|
873
|
+ filwidth_delay_index1 = (int)(filwidth_delay_dist / 10.0 + 0.0001);
|
866
|
874
|
|
867
|
|
- if (delay_index1 != delay_index2) { // moved index
|
868
|
|
- int8_t meas_sample = widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
|
869
|
|
- while (delay_index1 != delay_index2) {
|
870
|
|
- // Increment and loop around buffer
|
871
|
|
- if (++delay_index2 >= MMD) delay_index2 -= MMD;
|
872
|
|
- delay_index2 = constrain(delay_index2, 0, MAX_MEASUREMENT_DELAY);
|
873
|
|
- measurement_delay[delay_index2] = meas_sample;
|
|
875
|
+ // If the index has changed (must have gone forward)...
|
|
876
|
+ if (filwidth_delay_index1 != filwidth_delay_index2) {
|
|
877
|
+ filwidth_e_count = 0; // Reset the E movement counter
|
|
878
|
+ int8_t meas_sample = widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
|
|
879
|
+ do {
|
|
880
|
+ filwidth_delay_index2 = (filwidth_delay_index2 + 1) % MMD_CM; // The next unused slot
|
|
881
|
+ measurement_delay[filwidth_delay_index2] = meas_sample; // Store the measurement
|
|
882
|
+ } while (filwidth_delay_index1 != filwidth_delay_index2); // More slots to fill?
|
874
|
883
|
}
|
875
|
884
|
}
|
876
|
885
|
}
|