Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADC improvement & fix #1314

Merged
merged 7 commits into from
Nov 10, 2022
Merged

Conversation

rds76
Copy link
Contributor

@rds76 rds76 commented Nov 9, 2022

Description:

  • bugfix
  • improvement:
    • option to add additional reading for better accuracy
    • calibration constant
    • option to publish at least at defined interval

Checklist:

  • The pull request is done against the latest development branch
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • I accept the DCO.

int sum_val = val;
if (NumberOfReadingsADC > 1) { // add extra measurement for accuracy
for (int i=1; i<NumberOfReadingsADC; i++){
delay(7);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to average the accuracy without having a blocking delay() ? I'm afraid about the impacts on the main loop and on other modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, its just 7ms per read so for recommended 10 reads its 70ms in total (still optional) and guess delay actually yields every ms. Btw check RFB, theres is delay in loop on sending as well
Currently I'm running that (10 readings) with RF and DS1820 temp sensor with no issues so far...
Maybe we can short the delay to 1ms or remove it at all and also add one dummy analogRead as its recommended for 8266:

the reliability of the readings can be significantly improved by discarding an initial reading and then averaging the results

I'm afraid average values across loops adds another noise for already poor ADC in 8266 so better to read all in once

@rds76
Copy link
Contributor Author

rds76 commented Nov 9, 2022

updated PR, readings are much more consistent without delay in adcread loop (prolly caused by yield() in delay() creating noise)
with 1ms delay

house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":368,"adc_reads":10,"adc_sum":3680,"mvolt_scaled":1140}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":368,"adc_reads":10,"adc_sum":3681,"mvolt_scaled":1141}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":368,"adc_reads":10,"adc_sum":3684,"mvolt_scaled":1142}
house/OpenMQTTGateway/ADCtoMQTT {"adc":368,"adc_reads":10,"adc_sum":3683,"mvolt_scaled":1141}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}

no delay

house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}
house/OpenMQTTGateway/ADCtoMQTT {"adc":363,"adc_reads":10,"adc_sum":3630,"mvolt_scaled":1125}

@1technophile
Copy link
Owner

Thanks!

@1technophile 1technophile merged commit d392964 into 1technophile:development Nov 10, 2022
@rds76 rds76 mentioned this pull request Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants