+ Voltage on inputs

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
if(ADCH > 255)		//If ADCH >  (64x10mv = 2.55v) then Port Bit 0 and 2 are on.
      { 
         PORTB |= (1 << 0); // Turn on Port Bit 0 
		 PORTB &= ~(1 << 1); // Turn off Port Bit 1
      } 

      else 
      {  
        PORTB &= ~(1 << 0); // Turn off Port Bit 0
		PORTB |= (1 << 1); // Turn on Port Bit 1
     } 

Given the code above, why do I not get a response when I apply a positive voltage? I put 5v on the input yet I don't get a response, however if I write the following code:

if(ADCH < 175)		//If ADCH >  (64x10mv = 1.75v) then Port Bit 0 and 2 are on.
      { 
         PORTB |= (1 << 0); // Turn on Port Bit 0 
		 PORTB &= ~(1 << 1); // Turn off Port Bit 1
      } 

      else 
      {  
        PORTB &= ~(1 << 0); // Turn off Port Bit 0
		PORTB |= (1 << 1); // Turn on Port Bit 1
     } 

And drop the voltage below 1.75v volts it responds, I'm guessing my problem is some where in the conversion, but I don't quite understand why. My Vref is 2.56v, any ideas? Is my V-ref causing this problem? If I set my v-ref to 5v and then would the first set of logic work since the max value is 5v?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a theory on why this could be happening, my attiny85 is set for 8-bit resolution, that means 256x10mv = 2.56v, which is vref, now I changed vref to 5v, however its still in 8-bit resolution, would that still be limiting me to 2.56v max value due to register size restrictions? Aka I can't read anything above 2.56v because the register is set at 8 bits?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
if(ADCH > 255)
ADCH is 8-bit register, its value can never be greater than 255.

In case Uref=2.56V
ADCH = 255 for measured voltage >= 2.56V.
So to detect U>2.56V use

Quote:
if(ADCH > 254)
If you want to measure greater voltage than Uref, use resistor divider.
Never connect more than 5V directly to ADC input.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have the ADC result right-justifiied (ADLAR bit = 0, default) then ADCH can never exceed 0x03. Perhaps that is part of your problem?

You can exceed AREF, as long as you don't also exceed AVcc. The specs say clearly that the ADC will read full scale for any input greater than AREF.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include       

int main(void) 
{ 
     DDRB = 0b00000011;   //Sets Port Bit 0 as output

     ADCSRA |= (1 << ADPS2) | (1 << ADPS1);      //ADC Prescalar set to 64 - 125kHz@8MHz 


	 ADMUX |= (1 << MUX0);
     ADCSRA |= (1 << ADEN);  // Enable ADC 

  while (1) //loop while 1
  { 
  ADCSRA |= (1 <<ADSC);	//Starts ADC conversion for single ended mode
  while (ADCSRA & (1 << ADSC) );	// 
 if(ADCH > 253)		//If ADCH >  (64x10mv = 2.53v) then Port Bit 0 and 2 are on.
      { 
         PORTB |= (1 << 0); // Turn on Port Bit 0 
		 PORTB &= ~(1 << 1); // Turn off Port Bit 1
      } 

      else 
      {  
        PORTB &= ~(1 << 0); // Turn off Port Bit 0
		PORTB |= (1 << 1); // Turn on Port Bit 1
     } 
  } 
} 

This is the code that I have set up in the tiny85, I am putting a positive voltage on the hall sensor and I get no response, yet if I do the oppose and write if(adch < 175) then when I reverse the polarity of the magnet and use it to pull the voltage low on the hall sensor it works, but if(adch > 253) has no affect what so ever when I apply voltage greater than 2.50v. and I know the voltage rises because I read the output on it with my meter and the pulling it low works. Any more suggestions? I have also tried it with ADLAR = 1 as suggested by the tutorials on setting up ADC's, but to no avail.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Otherwise, ADCL must be read first, then ADCH."

In order to read 10-bit precision, would I write if(ADCL > 255) and it will automatically read ADCH? If that is not the case, how would I write an if state to read from both H and L for the full value?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I figured it out, never minde :-)