0
\$\begingroup\$

I am trying to use an Attiny45 as an Arduino such as here http://www.forkrobotics.com/2012/04/run-arduino-code-on-an-attiny/ using the Arduino-tiny cores. Now according to the diagram on the site pin D0, D1, D3 and D4 should have 8bit PWM capabilities but while testing with an LED only D4 works correctly, D3 goes completely on or completely off and D0 and D1 flicker while not completely on or off. I know the tutorial is for the Attiny85 but as far as I can determine the only differnce between it and the 45 should be RAM and flash storage. Also the 8bit is derived from the retailers website which states that there should in fact be 6 8-bit PWM channels https://za.rs-online.com/web/p/microcontrollers/6962614 Do any of you have any idea what could be causing this?

The code is just a version of Blink modified to switch between 100% and 50% duty cycle rather than on or off:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 3;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  //digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  analogWrite(led, 255);
  delay(1000);               // wait for a second
  //digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  analogWrite(led, 127);
  delay(1000);               // wait for a second
}
\$\endgroup\$
4
  • \$\begingroup\$ Post your code. \$\endgroup\$
    – Mels
    Commented Nov 20, 2013 at 15:01
  • \$\begingroup\$ @Mels ok I have \$\endgroup\$
    – Gerharddc
    Commented Nov 20, 2013 at 15:05
  • \$\begingroup\$ Last time I checked, which is admittedly quite a while ago, not all Arduino commands and libraries were supported on ATtiny's. I have never seen a definite list of supported functions. For size, just check the number of bytes your programmer writes, it shouldn't exceed some 4096 bytes or so. \$\endgroup\$
    – jippie
    Commented Nov 20, 2013 at 17:04
  • \$\begingroup\$ @jippie thanks for the info but that does not really help me \$\endgroup\$
    – Gerharddc
    Commented Nov 20, 2013 at 18:14

1 Answer 1

1
\$\begingroup\$

The ATTiny25/45/85 have three PWM pins, but AFAIK the HLT group's Arduino core only exposes two. There's an entire thread on this subject over on the Arduino forums: http://forums.adafruit.com/viewtopic.php?f=24&t=23937

The datasheet is your go-to reference for these issues. There's a lot of misinformation posted on vendor sites. Learning how to read the datasheets for these devices is an extremely valuable skill. The datasheet is here: http://www.atmel.com/images/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf

Note: there is also a bug in earlier revisions of the ATTiny45 (prior to Rev. D) that prevents PWM from working properly on pins 3 and 6 (OC1B, OC0B) if PWM is not also enabled on pin 5 (OC0A).

\$\endgroup\$
1
  • \$\begingroup\$ Ok thanks, so my only option will be to run my own pwm from a timer? \$\endgroup\$
    – Gerharddc
    Commented Nov 21, 2013 at 3:27

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.