speeduino / speeduino

Speeduino - Arduino based engine management
http://speeduino.com
GNU General Public License v2.0
1.37k stars 558 forks source link

Analog ISR mess MAP readings #69

Closed VitorBoss closed 7 months ago

VitorBoss commented 7 years ago

Unfortunately I don't have an engine running Speeduino yet, but I made some changes in the interrupt code on sensors.h.

ISR(ADC_vect)
{
  byte nChannel = ADMUX & 0x07;
  int result = ADCL | (ADCH << 8);

  BIT_CLEAR(ADCSRA, ADEN); //Disable ADC for Changing Channel (see chapter 26.5 of datasheet)

  #if defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__)
    if (nChannel==7) { ADMUX = 0x40; }
  #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    if(ADCSRB & 0x08) { nChannel += 8; }  //8 to 15
    if(nChannel == 15)
    {
      ADMUX = 0x40; //channel 0
      ADCSRB = 0x00; //clear MUX5 bit
    }
    else if (nChannel == 7) //channel 7
    {
      ADMUX = 0x40;
      ADCSRB = 0x08; //Set MUX5 bit
    }
  #endif
    else { ADMUX++; }
  AnChannel[nChannel] = result;

  BIT_SET(ADCSRA, ADEN); //Enable ADC
}
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/42065511-analog-isr-mess-map-readings?utm_campaign=plugin&utm_content=tracker%2F706250&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F706250&utm_medium=issues&utm_source=github).
noisymime commented 7 months ago

Closing as analog ISR is now working since f80a8aa218fb71ba87317de89b78eada4bb89211