Re: Marlin 2 bugfix & Filament Durchmesser 06. April 2020 12:05 |
Registrierungsdatum: 4 Jahre zuvor Beiträge: 24 |
void Temperature::tick() { ... /** * One sensor is sampled on every other call of the ISR. * Each sensor is read 16 (OVERSAMPLENR) times, taking the average. * * On each Prepare pass, ADC is started for a sensor pin. * On the next pass, the ADC value is read and accumulated. * * This gives each ADC 0.9765ms to charge up. */ #define ACCUMULATE_ADC(obj) do{ \ if (!HAL_ADC_READY()) next_sensor_state = adc_sensor_state; \ else obj.sample(HAL_READ_ADC()); \ }while(0) ADCSensorState next_sensor_state = adc_sensor_state < SensorsReady ? (ADCSensorState)(int(adc_sensor_state) + 1) : StartSampling; switch (adc_sensor_state) { case SensorsReady: { // All sensors have been read. Stay in this state for a few // ISRs to save on calls to temp update/checking code below. constexpr int8_t extra_loops = MIN_ADC_ISR_LOOPS - (int8_t)SensorsReady; static uint8_t delay_count = 0; if (extra_loops > 0) { if (delay_count == 0) delay_count = extra_loops; // Init this delay if (--delay_count) // While delaying... next_sensor_state = SensorsReady; // retain this state (else, next state will be 0) break; } else { adc_sensor_state = StartSampling; // Fall-through to start sampling next_sensor_state = (ADCSensorState)(int(StartSampling) + 1); } } case StartSampling: // Start of sampling loops. Do updates/checks. if (++temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256) = 164ms. temp_count = 0; readings_ready(); } break; ...... #if ENABLED(FILAMENT_WIDTH_SENSOR) case Prepare_FILWIDTH: HAL_START_ADC(FILWIDTH_PIN); break; case Measure_FILWIDTH: if (!HAL_ADC_READY()) next_sensor_state = adc_sensor_state; // redo this state else filwidth.accumulate(HAL_READ_ADC()); break; #endif ...... void Temperature::readings_ready() { // Update the raw values if they've been read. Else we could be updating them during reading. if (!raw_temps_ready) update_raw_temperatures(); // Filament Sensor - can be read any time since IIR filtering is used #if ENABLED(FILAMENT_WIDTH_SENSOR) filwidth.reading_ready(); #endif
The ATmega datasheet also cautions against switching analog pins in close temporal proximity to making A/D readings (analogRead) on other analog pins. This can cause electrical noise and introduce jitter in the analog system. It may be desirable, after manipulating analog pins (in digital mode), to add a short delay before using analogRead() to read other analog pins.
Re: Marlin 2 bugfix & Filament Durchmesser 06. April 2020 14:52 |
Registrierungsdatum: 9 Jahre zuvor Beiträge: 1.610 |
// Apply a single ADC reading to the raw value static void accumulate(const uint16_t adc) { if (adc > 102) // Ignore ADC under 0.5 volts accum += (uint32_t(adc) << 7) - (accum >> 7);
Re: Marlin 2 bugfix & Filament Durchmesser 07. April 2020 15:26 |
Registrierungsdatum: 4 Jahre zuvor Beiträge: 24 |
Re: Marlin 2 bugfix & Filament Durchmesser 07. April 2020 17:07 |
Registrierungsdatum: 9 Jahre zuvor Beiträge: 1.610 |