analogWrite PWM frequencies on ATTiny85

Hi group. I am having a problem with frequencies measured on an ATTiny85 with an oscilloscope using the AnalogWrite command. I have the ATTiny running at 1 MHz internal clock and I measure an output frequency of about 491 Hz on the PB0 and PB1 outputs (physical pins 5 and 6.) I would have expected the output frequency to be 1/8 that frequency or about 61 Hz. Here is the configuration I am using (I'm trying to be as complete as possible in the configuration description):

  1. Arduino 1.85 on a Windows 7 machine.
  2. I am using the ATTiny core by Spence Konde at: GitHub - SpenceKonde/ATTinyCore: Arduino core for ATtiny 1634, 828, x313, x4, x41, x5, x61, x7 and x8
  3. I set up the bootloader for the following configuration:
    Board: ATTiny 25/45/85
    Timer 1 clock: CPU
    Chip: Attiny85
    Clock: 1MHz internal
    Save EEPROM: EEPROM retained
    LTO: Disabled
    B.O.D. level: B.O.D. enabled (1.8V)

For an 8 MHz processor, the output frequency should be 8MHz divided by prescalar value of 64, divided by 256 (8 bit counter running in fast PWM mode) or 488.2 Hz.

The ATTiny is behaving as though it is using an 8 MHz internal clock instead of a 1 MHz internal clock or the ATTiny core is using a different prescalar value than an Arduino Unu ior Nano? I need help tracking down why the PWM frequencies ar not as expected for a 1 MHz internal clock. My application require a PWM frequency in the range of 100-150 Hz. I am reluctant to start writing registers directly without first understanding what's going on.

Thanks for your help.

Forgot to say it's an ATTiny85V as it has to operate down to 2 volts. That's one of the reasons for operating at 1 MHz. I used an Arduino Nano for the programmer using the Arduino ISP code and Programmer: Arduino as ISP.

Could be a stupid question, but you never know: did you burn the fuses? Are you 100% certain that it is operating at 1 MHz? (You can test this by uploading blink, and seeing if it takes 1 second to blink, or 1/8 s.)

If it is running at 1 MHz, I can only guess that the ATTiny core you're using changes the prescaler depending on the F_CPU value. You can easily find that in the source code of the core.


I verified that the timers work correctly. The millis() command works properly. I'll take a look at the core source code. Thanks!

I'll take a look at the core source code. Thanks!

Or just have your program print out the contents of all relevant registers. Guess with an ATTiny85 you might have to use SoftwareSerial and a TTL Serial to USB Converter.

I am reluctant to start writing registers directly without first understanding what's going on.

Why? You can't hurt anything by experimenting with it. Have your program change the pre-scaler setting and observe the results.

Update: I realized I was using the incorrect programmer but problem still not solved. I was using Arduino as ISP and submenu: Arduino as ISP. I believe I should have used: Programmer: Arduino as ISP and submenu: Arduino as ISP(ATTinyCore). Note that I have a 20K pullup on the ATTiny85 reset to +5V.

Well, when I tried burning the bootloader, for the first time, I got an error message:

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x10 and some other protocol error messages when using verbose during upload.

I tried burning the bootloader a second time with no changes in hardware configuration. This time I got no errors. Using verbose during upload,

It read and verified efuses O.K. :

Writing and reading of efuse written and verified.
writing and reading of hfuse written and verified.
Writing and reading of ifuse written and verified.

so the fuses are definitely burned.

But when I upload and run mu program, the PWM outputs are still at about 488 hz. It's still acting as though the processor is running at 8 MHz, not 1 MHz. Need to investigate further.

So I discovered that an unprogrammed ATTiny85 comes from the factory with a default 1 MHz clock. I confirmed this by taking a new ATTiny 85 and uploading my program without burning any fuses. The Analog Write command generates output pulse rate of about 488 Hz.