ATmega328P Versus attiny85

I think that I have run into as limitation when down scaling to production. I have a circuit that is running two servos and PWM a LED ( I.e. analogWrite - fading).
On the ATmega328P (Arduino Uno) the circuit and IDE sketch works correctly, but on the attiny85 (or attiny44) the servos.work but I cannot PWM the LED.
Is this due to the fact that the ATmega328P has 3 timers and the attiny only two?
Also, I have the Attiny running at 8mhz (instead of 1mhz - so I can get better resolution on my servos) versus the Uno that runs at 16mhz.

I found this post in which Nick Gammon says that it is possible:

Please, post your sketches for both ATmega328P and ATtiny85.

'm currently using an ATTINY44 (but have a ATTINY85 on order) I'm using PB2 (physical pin 5) for my LED PWM, and PB6 and PB7 for the servos. On the UNO I'm using pin 3 for the LED and 9 and 10 for the servos

I change port of my LED to PA7 (pin6) and lower servoA to PA5 (pin8) and servoB to Pa6 (pin7) and it is now fading the led but servos are acting glitchy...

I discovered that the glitchyness was cause by the softwareserial I had running so I disabled it and looks like things are running smoothy just by switching ports so that servos are running on PA6 and PA5 while LED is runing on PA7,


and


... should get you settled.

Pictures are from the Tinycore's Github page, by Spence Konde

@mbiasotti This is the core you should be using, in my opinion, if you are not already doing so. It has the best features and attempts to minimise the differences between atmega328 and ATtiny chips.

1 Like

Spence is on another next level. The different ATtinys, under one umbrella, with great features. Then on top of that, these pinout diagrams, it could be the work of a design studio.

First of all the servos can also be controlled without a timer, but using 2 different timers is excessive.

softwareSerial ? You understand people request you to post a code so they can see what else is in there.

Yes, this is what J'm currently using...

1 Like

@mbiasotti
Given below information on the functionalities of the PWM Modules of the ATTiny85 MCU. I have used the Digispark ATtiny85 Development Board (Fig-1, colone) running on internal PLL-ased 16 MHz clock. The PWM fading is observed on LEDs and the actual frequencies are not mesured.


Figure-1:

1. PWM Signals of ATTiny85 (Fig-2).


Figure-2:

3. By default, S1 is closed; so, when the following codes are executed 1953 Hz PWM signals (OC0A, OC0B) are generated by TC0 Module on DPin-0 (PB0) for and DPin-1 (PB1) respectively.

analogWrite(0, 8-bitDutyCycle); //tested ok OC0A
analogWrite(1, 8-bitDutyCycle); //tested ok OC0B

4. When the following codes are executed 62.5 kHz PWM signals (OC1B, OC1B/) are generated independently by TC1 Module on DPin-4 (PB4) for and DPin-3 (PB3) respectively.

analogWrite(4, 8-bitDutyCycle); //tested ok OC1B
analogWrite(3, 8-bitDutyCycle); //tested ok OC1B/

5. S1 of Fig-2 will be opened and S2 will be closed when the following code is executed. It is because:

Under ATTinyCore for the ATtiny85, analogWrite() defaults to Timer/Counter 0 (TC0). Timer/Counter 1 (TC1) can be used to generate a PWM signal (OC1A) on PB1/DPin-1 by register configuration as follows:

bitSet(TCCR1, PWM1A);    //PWM1A bit set to HIGH

As a result, TC1 based 62.5 kHz PWM signals (OC1A) will be routed to DPin-1 when the following code is executed.

analogWrite(1, 8-bitDutyCycle); //tested

I know that this isn't directly to your question but

The ATmega328 is the top of a pin-compatible line of AVR's that all have the same features but different amounts of flash, RAM and EEPROM. What runs on the 328 will run on any others if it fits and any of them can plug and play on a socketed Uno.

ATmega328 has 32K flash, 2K RAM, 1K EEPROM
ATmega168 has 16K flash, 1K RAM, 512B EEPROM
ATmega88 has 8K flash, 512B RAM, 256B EEPROM
ATmega48 has 4K flash, 256B RAM, 128B EEPROM

ATmega88 has half as much EEPROM as ATtiny85, but still 28 pins, UART, PWM, etc that a 328 has.

Just saying that it's possible to develop on a 328 and get a smaller bottle that if it fits will for sure runs the same code and wiring. AVR's run in "family" lines, the ATmega32 has 40 pins and 2 UARTs, for example.

The PWM programmimg mechanism of ATtiny85 is a bit different from that of ATmega328P.

Read post #1
"I think that I have run into as limitation when down scaling to production. I have a circuit that is running two servos and PWM a LED ( I.e. analogWrite - fading).
On the ATmega328P (Arduino Uno) the circuit and IDE sketch works correctly,"

Then read what I posted and figure out WHY I posted what I did, including the first line.