External reference not works gere

Hi,
This sketch tested good when set: ADMUX |= 1 << REFS0;.
The LCD doesn't show when modified as:

ADMUX |= 0 << REFS0;
ADMUX |= 0 << REFS1;

why?
Thanks
Adam

#include <avr/io.h>
  #include <stdlib.h>
  #include <avr/interrupt.h>

  #include <LiquidCrystal.h>
  const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
  LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


  void setup ()
  {
  Serial.begin(9600);

  lcd.begin(16, 2);

  ADCSRA |= 1 << ADPS2;
  ADMUX |= 1 << ADLAR;
  ///// ADMUX |= 1 << REFS0;
  ADMUX |= 0 << REFS0;
  ADMUX |= 0 << REFS1;
  ADCSRA |= 1 << ADIE; //Enable interrupts function in ADC
  ADCSRA |= 1 << ADEN; //Turn on the ADC feature

  sei();   //Enable the global interrupts

  ADCSRA |= 1 << ADSC; //start the first conversion
  }

  ISR(ADC_vect)
  {

  char adcResult[4];  //LCD String variable declaration
  itoa(ADCH, adcResult, 10); //convert the ADC conversion result to a string

  }

  void loop ()
  {

  ADCSRA |= 1 << ADSC; //start the first conversion

  char adcResult[4];  //LCD String variable declaration
  itoa(ADCH, adcResult, 10); //convert the ADC conversion result to a string

  Serial.println("adcResult=");
  Serial.println(adcResult);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("adc="); // WAS :lcd.print("adcResult="); this made the 1602 can't show that in one line, it's why LCD 16x2 Automatic Scroll left

  lcd.print(adcResult);
  delay(200);
  }

Shift a zero any number of places, any direction, and it remains a zero.

1 Like

I like to set REFS0/REFS1 zero.
how should I do it please?

The usual way, by ANDing with the inverse of the bits.

Remember: AND
A B &
0 0 0
0 1 0
1 0 0
1 1 1

ADMUX &= ~(1<<REFS0)

Is this what you want? Shift the 1 to the proper spot, invert "~" to generate a mask where all 0's turn into 1 and the 1 you shifted turns into 0. Then use bitwise and "&" to set the REFS0 bit to zero.

It's easier if you use the following set bit and clear bit:
sbi(Register, which_bit_to_set)
cbi(register,whici_bit_to_clear)

1 Like

Hey! What happened to the tilde character?

Yikes - looks like my Windoze setup is wrong; I see ~ as - !

(Tilde shows as an elongated -)

Thanks.
Yes, i like to set : REFS0/REFS1 to 0 for use the external reference. I copied these two lines into my code seems the ADC didn't take a AREF?

I don't even know what board or MCU you're talking about, assuming you only have PROGRAMMING question, where you chose to post. Why not using the arduino way analogReference(EXTERNAL)?

Is your screen not displaying the swung dash correctly? Could be encoding issues. I see it just fine.

1 Like

Nope, I've borrowed my wife's W10 laptop which has just had a major update, and as I said, tilde shows as a wide '-'.

Bloody Micro$oft.

1 Like

Thanks.
I used: analogReference(EXTERNAL); and

 analogReference(EXTERNAL); // use AREF for reference
  ADMUX |= (0 << REFS0);        // Extern AREF
  ADMUX |= (0 << REFS1);

non of them work.
I used Arduino UNO

Oh I see, so less swinging more straightened. I get wrong character encoding if I use rpi on default British English. Bugs the hell out of me cause I can't type a C program due to the symbols are all switched up.

1 Like

What part of "a zero shifted in any direction by any number of places is still a zero" was so hard to understand?

1 Like

Could you not use BOTH analogReference() AND the next two lines?

1 Like

Thanks.
I did. no work.

Microsoft is not to be caught dead rendering beautiful symbols or icons in my experience.

1 Like

Thanks.
That code from here:

that was problem in there, but no answer.

I'm surprised the poster made it out of AVRfreaks alive with that code.

1 Like

Then maybe it's not just a programming problem. Could be your setup. You need to provide some photos and descriptions to go with the photos. Last time I used analogReference(EXTERNAL) in 2017 it was working fine. I hooked up the external reference and "working" meant something to me such as I got the expected voltage, not a volt more or less.

I don't know what your "no work" means. Tried to think but it hurts. Must be self explanatory to other people I think I'm just too stupid to comprehend.

1 Like

I just brought up a Notepad++ window on the W10 laptop, and tilde displays as expected.

I'll stick with Ubuntu.

1 Like