0
\$\begingroup\$

I'm new the ATtiny series of Atmel MCUs and I've been trying to build a DC-DC boost converter with an ATtiny85-20PU recently.

To get started I've been trying to control the brightness of two LEDs by mapping the readings obtained using two 1k potentiometers. However only one LED responded and the other LED stays OFF the whole time.

So I did a minimal test and found out that whenever I try to use PB4 or PB2 to obtain an analogRead, it doesn't work for some reason. I'm able to get an analogRead only from PB3. The datasheet says that PB2, PB3 and PB4 are ADC channels

I'm using my Arduino UNO as ISP to program the ATtiny85 and I'm uploading the code using the Arduino IDE. I've tried looking up the datasheet and I was particularly going through the data given on the ADC unit and tried using the following.

According to the datasheet,

17.13.1 ADMUX – ADC Multiplexer Selection Register

• Bits 3:0 – MUX[3:0]: Analog Channel and Gain Selection Bits

The value of these bits selects which combination of analog inputs are connected to the ADC.

So I tried including this in my setup,

ADMUX |= (6<<MUX0); #  this was  the bit configuration given for using PB3 and PB4 as the input channels

but had no luck.

This is my code:

int feedbackPin = 2; //Using 2 or 4 won't work.Only 3 works
int gatePin2 = 1;

void setup() {

pinMode(feedbackPin,INPUT);
pinMode(gatePin2,OUTPUT);

}

void loop() {

int v1 = analogRead(feedbackPin);
int del2 = map(v1,0,1023,0,255);
  analogWrite(gatePin2,del2);

}

I would appreciate any help in setting up the two analogReads correctly.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

The analog and digital pin numbers are not the same.

PB3 is analog pin 3, that's why it works.

PB2 is analog pin 1.

PB4 is analog pin 2.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.