Go Down

Topic: ATTINY45 ADC1 PROBLEM (Read 841 times) previous topic - next topic

123tcpip

I'm having a play with the ATtiny45 and can program and make it do what i want to do but I have a problem where I can't read ADC1, A1
Using the following code I can change the flash speed of the LED to prove I can read the inputs.
I can read ADC3 & 2 But not 1
I tried defining it as PB2  & A1(wont compile)

Am I being missing something, I've tried several Atiny45 in case it's duff chip

// (Ain0 (D 5) PB5  1|    |8  Vcc
// (Ain3 (D 3) PB3  2|    |7  PB2 (D 2)  Ain1 (Voltsin
// (Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1 (LED)
//                 GND  4|    |5  PB0 (D 0) pwm0
//                           +----+

Here my test code
const int greenPin =  PB1;      // the number of the LED pin
const int VoltsIn  =  1;      // the number of the Volts In pin
int ADCIN;


void setup() {
  // set the digital pin as output:

  pinMode(greenPin, OUTPUT);
  pinMode(VoltsIn, INPUT); 

}
void loop()
{
    ADCIN = analogRead(VoltsIn)  ;
  digitalWrite(greenPin, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(ADCIN);               // wait for  ADC Value
  digitalWrite(greenPin, LOW);    // turn the LED off by making the voltage LOW
  delay(ADCIN);               // wait for  ADC Value
}

Thanks if anyone can point me in the right direction

123tcpip

After some more investigation I have found the problem but don't know the answer.
It appears that PB1 & 1 (aka ADC1,PB2) are the same pin when I program.

With the code below the LED is very very  faint but does flash in line with the ADC1 voltage.

More confusing as soon as a define the ADC pin as one of the other 3 ADCs the LED flashes at full brightness.

even more confusing is I can flash the LED by addressing it as either PB1 or just 1.
(If I try to define pins as D1 or A1 I get a compile error)

Are physical pins 6 & 7 tied internally?

Any thoughts

Erni

#2
Nov 19, 2012, 02:38 pm Last Edit: Nov 19, 2012, 02:50 pm by Erni Reason: 1
There is a thread about this topic:

http://arduino.cc/forum/index.php/topic,124139.0.html

The analogRead are refered by the ADC number

Physical pin 7,  Analog #1
Physical pin 2,  Analog #3
Physical pin 3, Anallog #2

The 100nF capacitor between Vcc and ground are important when using the DAC

I tried your code and got these results:
If you remove this line, the LED will blink with normal strenght
  pinMode(VoltsIn, INPUT); 


Code: [Select]

2
3
4
5
5
6
4
5
4
4
5
6
11
28
44
84
132
199
210
216
216
236
276
334
368
383
392
401
428
470
573
650
1022

123tcpip

Erin

Thanks for the response.
Before I saw your reply I removed the line making Voltsin an input and this fixed the issue but I thought it was good practice to declare inputs and outputs?
I had already looked at the thread you highlighted and its helped a little but I'm still unclear why I can't define ADC1 (1) as an input but I can the other 3 ADCs (0,2,3)

is this a bug in the ATtiny library or do i never need to define inputs?

Rob


PaulS

Quote
I thought it was good practice to declare inputs and outputs?

It is. For pins that can be either. For analog pins that can only be INPUT, it isn't necessary (and can actually cause problems because pinMode knows nothing about the existence of analog pins).

Erni

If you refer to the pin as A1 insted of just 1, it works:

const int VoltsIn  =  A1;      // the number of the Volts In pin

Maybe it is somthing about both pins are called 1 ?

123tcpip

PaulS

Again thanks for the response.
I was going off of this sheet which showed the ATtiny45 A1 could also be D2 (input or output) so I assumed I had to define it, or am I missing the point which is quite probable  :)


123tcpip

Erni

Using the ATtiny support library I'm using you can't define pins as A1,D1 etc just 1,2,etc or PB1,2, etc.

https://github.com/damellis/attiny/tree/Arduino1

So it's my understanding they are defined when you analogRead(1,2,3,4) as per the analogue pinouts below



Like most people here I'm learning as I go, but things I've done with the Uno board don't seem to work with the ATtiny, i just assume the library is not as mature.

fungus


i just assume the library is not as mature.


Very likely.

The ADC converter is really easy to program directly though. Just pull the source out of the library, grab a datasheet and follow it through.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Erni

123tcpip
Ahaaa, we are using different cores, I use this

http://code.google.com/p/arduino-tiny/

It is considerer more stable and error free, and it is more easy to get help, as it is maintained by Coding Badly on this forum

Go Up