Skip to content

channel change bug in ADC_vect #1

@HamishB

Description

@HamishB

Hi,

a patch by trevorshannon exists in the sparkfun comments, after years of being known the bug is still present (but unreported :) so it would be nice to have it finally fixed.

https://www.sparkfun.com/products/10537

quote:

i didn’t see enough noise to make this ‘unusable’ but i did see some strange jumps every once in a while. for example, for one sample, x would increase a lot while z would simultaneously decrease a lot. suspicious…

taking into account what others have already mentioned, i made the following change to the firmware (sorry for pseudo code) and i seem to have eliminated those random jumps.

ISR(ADC_vect){
 cli();
 if (!channelChanged){
  do the normal ADC_vect
  channelChanged = true;
 }
 else{
  store ADCL and ADCH in a temporary variable
  channelChanged = false;
 }
 sei();
}

someone else added:

I managed to do something similar to this, but I don’t understand why the ADCL and ADCH are stored in a temporary variable in the “else” block. Are you using that temporary variable somewhere in the code? Shouldn’t the values be discarded? That’s what I did and the strange jumps are gone.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions