|
@@ -2798,23 +2798,133 @@ void Temperature::tick() {
|
2798
|
2798
|
if ((do_buttons ^= true)) ui.update_buttons();
|
2799
|
2799
|
|
2800
|
2800
|
/**
|
2801
|
|
- * One sensor is sampled on every other call of the ISR.
|
2802
|
|
- * Each sensor is read 16 (OVERSAMPLENR) times, taking the average.
|
|
2801
|
+ * On each call to the ISR one sensor is Sampled and
|
|
2802
|
+ * the next sensor is Prepared.
|
2803
|
2803
|
*
|
2804
|
|
- * On each Prepare pass, ADC is started for a sensor pin.
|
2805
|
|
- * On the next pass, the ADC value is read and accumulated.
|
|
2804
|
+ * Sensors are read 16 (OVERSAMPLENR) times and the
|
|
2805
|
+ * final reading takes the average.
|
2806
|
2806
|
*
|
2807
|
|
- * This gives each ADC 0.9765ms to charge up.
|
|
2807
|
+ * Extra do-nothing passes may exist when there are
|
|
2808
|
+ * only a few sensors. This is set by MIN_ADC_ISR_LOOPS.
|
|
2809
|
+ *
|
|
2810
|
+ * The timing of this ISR gives ADCs 0.9765ms to charge up.
|
2808
|
2811
|
*/
|
2809
|
|
- #define ACCUMULATE_ADC(obj) do{ \
|
2810
|
|
- if (!HAL_ADC_READY()) next_sensor_state = adc_sensor_state; \
|
2811
|
|
- else obj.sample(HAL_READ_ADC()); \
|
|
2812
|
+ #define ACCUMULATE_ADC(obj) do{ \
|
|
2813
|
+ if (HAL_ADC_READY()) \
|
|
2814
|
+ obj.sample(HAL_READ_ADC()); \
|
|
2815
|
+ else \
|
|
2816
|
+ next_sensor_state = adc_sensor_state; \
|
2812
|
2817
|
}while(0)
|
2813
|
2818
|
|
2814
|
|
- ADCSensorState next_sensor_state = adc_sensor_state < SensorsReady ? (ADCSensorState)(int(adc_sensor_state) + 1) : StartSampling;
|
|
2819
|
+ #define NEXT_ENUM(A) (typeof(A))(int(A) + 1)
|
|
2820
|
+ #define NEXT_ADC_STATE(N) ((N) >= SensorsReady ? StartSampling : NEXT_ENUM(N))
|
|
2821
|
+
|
|
2822
|
+ // Assume the machine will go on to the next state
|
|
2823
|
+ ADCSensorState next_sensor_state = NEXT_ADC_STATE(adc_sensor_state);
|
|
2824
|
+
|
|
2825
|
+ switch (adc_sensor_state) {
|
|
2826
|
+
|
|
2827
|
+ default: break;
|
|
2828
|
+
|
|
2829
|
+ #if HAS_TEMP_ADC_0
|
|
2830
|
+ case MeasureTemp_0: ACCUMULATE_ADC(temp_hotend[0]); break;
|
|
2831
|
+ #endif
|
|
2832
|
+ #if HAS_HEATED_BED
|
|
2833
|
+ case MeasureTemp_BED: ACCUMULATE_ADC(temp_bed); break;
|
|
2834
|
+ #endif
|
|
2835
|
+ #if HAS_TEMP_CHAMBER
|
|
2836
|
+ case MeasureTemp_CHAMBER: ACCUMULATE_ADC(temp_chamber); break;
|
|
2837
|
+ #endif
|
|
2838
|
+ #if HAS_TEMP_PROBE
|
|
2839
|
+ case MeasureTemp_PROBE: ACCUMULATE_ADC(temp_probe); break;
|
|
2840
|
+ #endif
|
|
2841
|
+ #if HAS_TEMP_ADC_1
|
|
2842
|
+ case MeasureTemp_1: ACCUMULATE_ADC(temp_hotend[1]); break;
|
|
2843
|
+ #endif
|
|
2844
|
+ #if HAS_TEMP_ADC_2
|
|
2845
|
+ case MeasureTemp_2: ACCUMULATE_ADC(temp_hotend[2]); break;
|
|
2846
|
+ #endif
|
|
2847
|
+ #if HAS_TEMP_ADC_3
|
|
2848
|
+ case MeasureTemp_3: ACCUMULATE_ADC(temp_hotend[3]); break;
|
|
2849
|
+ #endif
|
|
2850
|
+ #if HAS_TEMP_ADC_4
|
|
2851
|
+ case MeasureTemp_4: ACCUMULATE_ADC(temp_hotend[4]); break;
|
|
2852
|
+ #endif
|
|
2853
|
+ #if HAS_TEMP_ADC_5
|
|
2854
|
+ case MeasureTemp_5: ACCUMULATE_ADC(temp_hotend[5]); break;
|
|
2855
|
+ #endif
|
|
2856
|
+ #if HAS_TEMP_ADC_6
|
|
2857
|
+ case MeasureTemp_6: ACCUMULATE_ADC(temp_hotend[6]); break;
|
|
2858
|
+ #endif
|
|
2859
|
+ #if HAS_TEMP_ADC_7
|
|
2860
|
+ case MeasureTemp_7: ACCUMULATE_ADC(temp_hotend[7]); break;
|
|
2861
|
+ #endif
|
|
2862
|
+
|
|
2863
|
+ #if ENABLED(FILAMENT_WIDTH_SENSOR)
|
|
2864
|
+ case Measure_FILWIDTH:
|
|
2865
|
+ if (HAL_ADC_READY())
|
|
2866
|
+ filwidth.accumulate(HAL_READ_ADC());
|
|
2867
|
+ else
|
|
2868
|
+ next_sensor_state = adc_sensor_state; // redo this state
|
|
2869
|
+ break;
|
|
2870
|
+ #endif
|
|
2871
|
+
|
|
2872
|
+ #if HAS_JOY_ADC_X
|
|
2873
|
+ case MeasureJoy_X: ACCUMULATE_ADC(joystick.x); break;
|
|
2874
|
+ #endif
|
|
2875
|
+ #if HAS_JOY_ADC_Y
|
|
2876
|
+ case MeasureJoy_Y: ACCUMULATE_ADC(joystick.y); break;
|
|
2877
|
+ #endif
|
|
2878
|
+ #if HAS_JOY_ADC_Z
|
|
2879
|
+ case MeasureJoy_Z: ACCUMULATE_ADC(joystick.z); break;
|
|
2880
|
+ #endif
|
|
2881
|
+
|
|
2882
|
+ #if HAS_ADC_BUTTONS
|
|
2883
|
+ #ifndef ADC_BUTTON_DEBOUNCE_DELAY
|
|
2884
|
+ #define ADC_BUTTON_DEBOUNCE_DELAY 16
|
|
2885
|
+ #endif
|
|
2886
|
+ case Measure_ADC_KEY: {
|
|
2887
|
+ if (HAL_ADC_READY()) {
|
|
2888
|
+ if (ADCKey_count < ADC_BUTTON_DEBOUNCE_DELAY) {
|
|
2889
|
+ raw_ADCKey_value = HAL_READ_ADC();
|
|
2890
|
+ if (raw_ADCKey_value <= (HAL_ADC_RANGE) * 900UL / 1024UL) {
|
|
2891
|
+ NOMORE(current_ADCKey_raw, raw_ADCKey_value);
|
|
2892
|
+ ADCKey_count++;
|
|
2893
|
+ }
|
|
2894
|
+ else { // ADC Key release
|
|
2895
|
+ if (ADCKey_count > 0) {
|
|
2896
|
+ if (ADCKey_pressed) {
|
|
2897
|
+ ADCKey_count = 0;
|
|
2898
|
+ current_ADCKey_raw = HAL_ADC_RANGE;
|
|
2899
|
+ }
|
|
2900
|
+ else
|
|
2901
|
+ ADCKey_count++;
|
|
2902
|
+ }
|
|
2903
|
+ else
|
|
2904
|
+ ADCKey_pressed = false;
|
|
2905
|
+ }
|
|
2906
|
+ if (ADCKey_count == ADC_BUTTON_DEBOUNCE_DELAY) ADCKey_pressed = true;
|
|
2907
|
+ }
|
|
2908
|
+ }
|
|
2909
|
+ else
|
|
2910
|
+ next_sensor_state = adc_sensor_state; // redo this state
|
|
2911
|
+
|
|
2912
|
+ } break;
|
|
2913
|
+
|
|
2914
|
+ #endif // HAS_ADC_BUTTONS
|
|
2915
|
+
|
|
2916
|
+ } // switch(adc_sensor_state)
|
|
2917
|
+
|
|
2918
|
+ // Go to the next state (may be unchanged)
|
|
2919
|
+ adc_sensor_state = next_sensor_state;
|
|
2920
|
+
|
|
2921
|
+ // Assume that the state advances
|
|
2922
|
+ next_sensor_state = NEXT_ADC_STATE(adc_sensor_state);
|
2815
|
2923
|
|
2816
|
2924
|
switch (adc_sensor_state) {
|
2817
|
2925
|
|
|
2926
|
+ default: break;
|
|
2927
|
+
|
2818
|
2928
|
case SensorsReady: {
|
2819
|
2929
|
// All sensors have been read. Stay in this state for a few
|
2820
|
2930
|
// ISRs to save on calls to temp update/checking code below.
|
|
@@ -2824,128 +2934,72 @@ void Temperature::tick() {
|
2824
|
2934
|
if (delay_count == 0) delay_count = extra_loops; // Init this delay
|
2825
|
2935
|
if (--delay_count) // While delaying...
|
2826
|
2936
|
next_sensor_state = SensorsReady; // retain this state (else, next state will be 0)
|
2827
|
|
- break;
|
|
2937
|
+ break; // No fallthru
|
2828
|
2938
|
}
|
2829
|
2939
|
else {
|
2830
|
|
- adc_sensor_state = StartSampling; // Fall-through to start sampling
|
2831
|
|
- next_sensor_state = (ADCSensorState)(int(StartSampling) + 1);
|
|
2940
|
+ adc_sensor_state = StartSampling; // Fall through to count up oversamples
|
|
2941
|
+ next_sensor_state = NEXT_ENUM(StartSampling); // and possibly send the final readings.
|
2832
|
2942
|
}
|
2833
|
2943
|
}
|
|
2944
|
+ // fallthru
|
2834
|
2945
|
|
2835
|
2946
|
case StartSampling: // Start of sampling loops. Do updates/checks.
|
2836
|
|
- if (++temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256) = 164ms.
|
|
2947
|
+ if (++temp_count >= OVERSAMPLENR) { // 10 * 16 * 1 / (16000000 / 64 / 256) = 164ms.
|
2837
|
2948
|
temp_count = 0;
|
2838
|
2949
|
readings_ready();
|
2839
|
2950
|
}
|
2840
|
|
- break;
|
|
2951
|
+ adc_sensor_state = NEXT_ENUM(StartSampling); // Do one Prepare phase before exiting
|
|
2952
|
+ next_sensor_state = NEXT_ENUM(adc_sensor_state); // Also update the next state
|
|
2953
|
+ // fallthru
|
2841
|
2954
|
|
2842
|
2955
|
#if HAS_TEMP_ADC_0
|
2843
|
|
- case PrepareTemp_0: HAL_START_ADC(TEMP_0_PIN); break;
|
2844
|
|
- case MeasureTemp_0: ACCUMULATE_ADC(temp_hotend[0]); break;
|
|
2956
|
+ case PrepareTemp_0: HAL_START_ADC(TEMP_0_PIN); break;
|
2845
|
2957
|
#endif
|
2846
|
|
-
|
2847
|
2958
|
#if HAS_HEATED_BED
|
2848
|
|
- case PrepareTemp_BED: HAL_START_ADC(TEMP_BED_PIN); break;
|
2849
|
|
- case MeasureTemp_BED: ACCUMULATE_ADC(temp_bed); break;
|
|
2959
|
+ case PrepareTemp_BED: HAL_START_ADC(TEMP_BED_PIN); break;
|
2850
|
2960
|
#endif
|
2851
|
|
-
|
2852
|
2961
|
#if HAS_TEMP_CHAMBER
|
2853
|
2962
|
case PrepareTemp_CHAMBER: HAL_START_ADC(TEMP_CHAMBER_PIN); break;
|
2854
|
|
- case MeasureTemp_CHAMBER: ACCUMULATE_ADC(temp_chamber); break;
|
2855
|
2963
|
#endif
|
2856
|
|
-
|
2857
|
2964
|
#if HAS_TEMP_PROBE
|
2858
|
|
- case PrepareTemp_PROBE: HAL_START_ADC(TEMP_PROBE_PIN); break;
|
2859
|
|
- case MeasureTemp_PROBE: ACCUMULATE_ADC(temp_probe); break;
|
|
2965
|
+ case PrepareTemp_PROBE: HAL_START_ADC(TEMP_PROBE_PIN); break;
|
2860
|
2966
|
#endif
|
2861
|
|
-
|
2862
|
2967
|
#if HAS_TEMP_ADC_1
|
2863
|
|
- case PrepareTemp_1: HAL_START_ADC(TEMP_1_PIN); break;
|
2864
|
|
- case MeasureTemp_1: ACCUMULATE_ADC(temp_hotend[1]); break;
|
|
2968
|
+ case PrepareTemp_1: HAL_START_ADC(TEMP_1_PIN); break;
|
2865
|
2969
|
#endif
|
2866
|
|
-
|
2867
|
2970
|
#if HAS_TEMP_ADC_2
|
2868
|
|
- case PrepareTemp_2: HAL_START_ADC(TEMP_2_PIN); break;
|
2869
|
|
- case MeasureTemp_2: ACCUMULATE_ADC(temp_hotend[2]); break;
|
|
2971
|
+ case PrepareTemp_2: HAL_START_ADC(TEMP_2_PIN); break;
|
2870
|
2972
|
#endif
|
2871
|
|
-
|
2872
|
2973
|
#if HAS_TEMP_ADC_3
|
2873
|
|
- case PrepareTemp_3: HAL_START_ADC(TEMP_3_PIN); break;
|
2874
|
|
- case MeasureTemp_3: ACCUMULATE_ADC(temp_hotend[3]); break;
|
|
2974
|
+ case PrepareTemp_3: HAL_START_ADC(TEMP_3_PIN); break;
|
2875
|
2975
|
#endif
|
2876
|
|
-
|
2877
|
2976
|
#if HAS_TEMP_ADC_4
|
2878
|
|
- case PrepareTemp_4: HAL_START_ADC(TEMP_4_PIN); break;
|
2879
|
|
- case MeasureTemp_4: ACCUMULATE_ADC(temp_hotend[4]); break;
|
|
2977
|
+ case PrepareTemp_4: HAL_START_ADC(TEMP_4_PIN); break;
|
2880
|
2978
|
#endif
|
2881
|
|
-
|
2882
|
2979
|
#if HAS_TEMP_ADC_5
|
2883
|
|
- case PrepareTemp_5: HAL_START_ADC(TEMP_5_PIN); break;
|
2884
|
|
- case MeasureTemp_5: ACCUMULATE_ADC(temp_hotend[5]); break;
|
|
2980
|
+ case PrepareTemp_5: HAL_START_ADC(TEMP_5_PIN); break;
|
2885
|
2981
|
#endif
|
2886
|
|
-
|
2887
|
2982
|
#if HAS_TEMP_ADC_6
|
2888
|
|
- case PrepareTemp_6: HAL_START_ADC(TEMP_6_PIN); break;
|
2889
|
|
- case MeasureTemp_6: ACCUMULATE_ADC(temp_hotend[6]); break;
|
|
2983
|
+ case PrepareTemp_6: HAL_START_ADC(TEMP_6_PIN); break;
|
2890
|
2984
|
#endif
|
2891
|
|
-
|
2892
|
2985
|
#if HAS_TEMP_ADC_7
|
2893
|
|
- case PrepareTemp_7: HAL_START_ADC(TEMP_7_PIN); break;
|
2894
|
|
- case MeasureTemp_7: ACCUMULATE_ADC(temp_hotend[7]); break;
|
|
2986
|
+ case PrepareTemp_7: HAL_START_ADC(TEMP_7_PIN); break;
|
2895
|
2987
|
#endif
|
2896
|
|
-
|
2897
|
2988
|
#if ENABLED(FILAMENT_WIDTH_SENSOR)
|
2898
|
|
- case Prepare_FILWIDTH: HAL_START_ADC(FILWIDTH_PIN); break;
|
2899
|
|
- case Measure_FILWIDTH:
|
2900
|
|
- if (!HAL_ADC_READY())
|
2901
|
|
- next_sensor_state = adc_sensor_state; // redo this state
|
2902
|
|
- else
|
2903
|
|
- filwidth.accumulate(HAL_READ_ADC());
|
2904
|
|
- break;
|
|
2989
|
+ case Prepare_FILWIDTH: HAL_START_ADC(FILWIDTH_PIN); break;
|
2905
|
2990
|
#endif
|
2906
|
|
-
|
2907
|
2991
|
#if HAS_JOY_ADC_X
|
2908
|
|
- case PrepareJoy_X: HAL_START_ADC(JOY_X_PIN); break;
|
2909
|
|
- case MeasureJoy_X: ACCUMULATE_ADC(joystick.x); break;
|
|
2992
|
+ case PrepareJoy_X: HAL_START_ADC(JOY_X_PIN); break;
|
2910
|
2993
|
#endif
|
2911
|
|
-
|
2912
|
2994
|
#if HAS_JOY_ADC_Y
|
2913
|
|
- case PrepareJoy_Y: HAL_START_ADC(JOY_Y_PIN); break;
|
2914
|
|
- case MeasureJoy_Y: ACCUMULATE_ADC(joystick.y); break;
|
|
2995
|
+ case PrepareJoy_Y: HAL_START_ADC(JOY_Y_PIN); break;
|
2915
|
2996
|
#endif
|
2916
|
|
-
|
2917
|
2997
|
#if HAS_JOY_ADC_Z
|
2918
|
|
- case PrepareJoy_Z: HAL_START_ADC(JOY_Z_PIN); break;
|
2919
|
|
- case MeasureJoy_Z: ACCUMULATE_ADC(joystick.z); break;
|
|
2998
|
+ case PrepareJoy_Z: HAL_START_ADC(JOY_Z_PIN); break;
|
2920
|
2999
|
#endif
|
2921
|
|
-
|
2922
|
3000
|
#if HAS_ADC_BUTTONS
|
2923
|
|
- #ifndef ADC_BUTTON_DEBOUNCE_DELAY
|
2924
|
|
- #define ADC_BUTTON_DEBOUNCE_DELAY 16
|
2925
|
|
- #endif
|
2926
|
|
- case Prepare_ADC_KEY: HAL_START_ADC(ADC_KEYPAD_PIN); break;
|
2927
|
|
- case Measure_ADC_KEY:
|
2928
|
|
- if (!HAL_ADC_READY())
|
2929
|
|
- next_sensor_state = adc_sensor_state; // redo this state
|
2930
|
|
- else if (ADCKey_count < ADC_BUTTON_DEBOUNCE_DELAY) {
|
2931
|
|
- raw_ADCKey_value = HAL_READ_ADC();
|
2932
|
|
- if (raw_ADCKey_value <= 900UL * HAL_ADC_RANGE / 1024UL) {
|
2933
|
|
- NOMORE(current_ADCKey_raw, raw_ADCKey_value);
|
2934
|
|
- ADCKey_count++;
|
2935
|
|
- }
|
2936
|
|
- else { //ADC Key release
|
2937
|
|
- if (ADCKey_count > 0) ADCKey_count++; else ADCKey_pressed = false;
|
2938
|
|
- if (ADCKey_pressed) {
|
2939
|
|
- ADCKey_count = 0;
|
2940
|
|
- current_ADCKey_raw = HAL_ADC_RANGE;
|
2941
|
|
- }
|
2942
|
|
- }
|
2943
|
|
- }
|
2944
|
|
- if (ADCKey_count == ADC_BUTTON_DEBOUNCE_DELAY) ADCKey_pressed = true;
|
2945
|
|
- break;
|
2946
|
|
- #endif // HAS_ADC_BUTTONS
|
2947
|
|
-
|
2948
|
|
- case StartupDelay: break;
|
|
3001
|
+ case Prepare_ADC_KEY: HAL_START_ADC(ADC_KEYPAD_PIN); break;
|
|
3002
|
+ #endif
|
2949
|
3003
|
|
2950
|
3004
|
} // switch(adc_sensor_state)
|
2951
|
3005
|
|