Go Down

Topic: Attiny 2313 analogWrite not working on pins 12 and 13 (Read 233 times) previous topic - next topic

fadecomic

According to the datasheet, pins 11, 12, and 13 are PWM pins on the Attiny 2313. However, analogWrite() only seems to work on 11. If I vary the value written using analogWrite from 0 to 255, the LEDs on pins 12 and 13 only flash on at the end.

I am using ATTinyCore to program the chip, and I've tested the chip with other simple programs, all of which seem to work as planned. Is this expected behavior? If not, why are pins 12 and 13 not functioning as PWM pins?

BJHenry

Because of the limited flash space on those chips, Timer1 isn't initiated by default. There are more details here, but the relevant part is below:
Quote
Initialize Secondard Timers option

When an Arduino sketch runs, prior to Setup() being called, a hidden init() function is called to set up the hardware. One of the things it does is configure the timers. Timer0 (used for millis) is always configured, but on the x313 series, due to the extremely limited flash, it is optional whether to initialize Timer1. If Timer1 is not initialized, Tone() and PWM on pins 12 and 13 will not work.

fadecomic

Aw, man, I looked at those docs, too. I didn't realize there were other docs beyond the main one. Thanks.

DrAzzy

Aw, man, I looked at those docs, too. I didn't realize there were other docs beyond the main one. Thanks.
sigh....

Quote
ATtinyCore Universal
This core supports the following processors - essentially every ATtiny processor that makes sense to use with Arduino. Click the processor name for part-specific information:
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up