+ Voltage on inputs

7 posts / 0 new
Author
Message
```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?

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?

Quote:
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 you want to measure greater voltage than Uref, use resistor divider.
Never connect more than 5V directly to ADC input.

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

```#include

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

while (1) //loop while 1
{
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.