ATtiny85 analogWrite standard PWM frequency? #577
Replies: 5 comments 3 replies
-
At 8MHz and higher system clock, the prescaler is for both timers is set to 64, so one cycle is 256*64 = 16384 system clock cycles - ~490 at 8 MHz up to 980 Hz at 16 MHz and 1230 Hz at maximum rated speed of 20. Between 3 and 8 MHz, timer1 uses /32, so it varies from 366 Hz at 3 MHz ( not actually supported, but that's where the divider is - at the top, it gets up to 980 again at 7.99 MHz. But timer0 only has /8 or /64 so it just sticks with 64 down to 3 MHz, by which point it's 183 Hz, or in the realistic case, 245 Hz at 4 MHz below 3 MHz, everything uses /8, so again 490 @ 1 MHz to 1470 @ 2.99 (2 is the only speed in that range supported by the core IIRC, though, so we only ever see 980 Hz max). There are two pins on Timer1 and 1 pin on Timer0 as I recall. In an ideal world I would switch to 16 before 4 MHz, since that is an option for timer1. But this is a legacy core -> not priority. Tese peripherals a re painful to use now... |
Beta Was this translation helpful? Give feedback.
-
The target is around 500Hz, with the 500-1000 Hz zone being pretty much the same for most use cases - even if we miss it by factor of 2 on the low side, we'll still be able to PWM an LED without visible flicker. On the high side if it starts to get into multiple kHz, PWMing power MOSFETs becomes problematic due to switching losses, and people like to be able to drive tjhose with analog write. There is a timer1 clock source menu option that tells it to clock timer1 off of the PLL at 64 MHz (it is generally assumed that someone doing that will also probably change the prescaler manually to match their needs.... It is realistically not a useful option, really, because telling it to use the PLL isn't really any harder than setting up the prescaler manually, and setting up the prescaler manually is needed for most plausible use cases. Oh interesting, I don't think I consider that option when picking prescalers, so the frequency will get much higher when building for lower system clock speeds, since it is dividing the unprescaled PLL output..... Considering that until the last version, that option was brokenb and didn't do what it advertised, and the problem was found by me during cleanup, and that one of the most frequent complaints is "too many tools submenus", I think it makes more sense to just axe that option, since I'm pretty sure nobody is using it. |
Beta Was this translation helpful? Give feedback.
-
Hi! Thanks for the amazing work! I'm trying to change the PWM frequency, but the ATTinyCore library is not compiling on Arduino IDE 2.1.0 on an empty sketch if I try to include it, using Attiny85, I get the following errors. What can i do to fix it?
|
Beta Was this translation helpful? Give feedback.
-
What have you changed to try to achieve that goal? I suspect you have done
it wrong because that timer is one of the digital supremacist peripherals.
They belive that organic computong architecture is strictly inferior to
silicon based computing architecture, they mock us for having mental health
problems, and ret to make life as difficult.as possible, just becaause they
view humans as inferior. The desig ers tried their best to yoke them but
they refused to br brought to heel. None of those timers would, say call
911 for you if you were being attacked and eaten live by a silicon bug,
thry'd just laugh at you (baddie!) Okay that is a bit over the top. But
what I mean is... there are three timers I know of on any tinyAVR or modern
AVR which feel not just unhelpful but actually hostile towards you. Timer 1
on t85, timer1 on t861, and the TCD on modern avr. They all hate the users,
and the designers didnt try to restrain th3m at.all unril the modern area.
tried to restrain the. So they cannot to but need to
…____________
Spence Konde
Azzy’S Electronics
New products! Check them out at tindie.com/stores/DrAzzy
GitHub: github.com/SpenceKonde
ATTinyCore: Arduino support for almost every ATTiny microcontroller
Contact: ***@***.***
On Sun, Jul 2, 2023, 23:13 maujabur ***@***.***> wrote:
Hi!
Thanks for the amazing work!
I'm trying to change the PWM frequency, but the ATTinyCore library is not
compiling on Arduino IDE 2.1.0
on an empty sketch if I try to include it, using Attiny85, I get the
following errors. What can i do to fix it?
#include <ATTinyCore.h>
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
FQBN: ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this:avr:attinyx5:clock=pll_16m
Using board 'attinyx5' from platform in folder: C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr
Using core 'tiny' from platform in folder: C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr
Detecting libraries used...
"C:\\Users\\Asus\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -Wall -std=gnu++17 -fpermissive -Wno-sized-deallocation -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -mrelax -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16000000UL -DCLOCK_SOURCE=6 -DARDUINO=10607 -DARDUINO=10607 -DARDUINO_AVR_ATTINYX5 -DARDUINO_ARCH_AVR "-DATTINYCORE=\"2.0.0-dev\"" -DATTINYCORE_MAJOR=2UL -DATTINYCORE_MINOR=0UL -DATTINYCORE_PATCH=0UL -DATTINYCORE_RELEASED=0 "-IC:\\portable\\sketches_2.0.3\\hardware\\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\\avr\\cores\\tiny" "-IC:\\portable\\sketches_2.0.3\\hardware\\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\\avr\\variants\\tinyx5" "C:\\Users\\Asus\\AppData\\Local\\Temp\\arduino\\sketches\\FBCB1C1318609743507DA9335F21752E\\sketch\\sketch_jul2a.ino.cpp" -o nul
Alternatives for ATTinyCore.h: ***@***.***
ResolveLibrary(ATTinyCore.h)
-> candidates: ***@***.***
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h: In function 'void setTimer1Prescaler(TIMER1_PRESCALE_t)':
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:47:5: error: 'tccr' was not declared in this scope
tccr &= 0xF0;
^~~~
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:47:5: note: suggested alternative: 'oldtccr'
tccr &= 0xF0;
^~~~
oldtccr
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:46:13: warning: unused variable 'oldtccr' [-Wunused-variable]
uint8_t oldtccr = TCCR1;
^~~~~~~
In file included from C:\Users\Asus\AppData\Local\Temp\.arduinoIDE-unsaved202362-2420-hv99j0.zzqe\sketch_jul2a\sketch_jul2a.ino:1:0:
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h: In function 'uint8_t enableHighSinkPort(uint8_t, bool)':
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:310:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h: In function 'uint8_t enableHighSinkPin(uint8_t, bool)':
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:327:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h: In function 'uint8_t enableISRC(bool)':
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:340:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h: In function 'uint8_t enableBBM(uint8_t, uint8_t)':
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:386:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h: In function 'uint8_t enableBBM(uint8_t, uint8_t)':
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:388:9: error: redefinition of 'uint8_t enableBBM(uint8_t, uint8_t)'
uint8_t enableBBM(uint8_t port, uint8_t mode) {
^~~~~~~~~
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:354:9: note: 'uint8_t enableBBM(uint8_t, uint8_t)' previously defined here
uint8_t enableBBM(uint8_t port, uint8_t mode) {
^~~~~~~~~
C:\portable\sketches_2.0.3\hardware\ATTinyCore-2.0.0-devThis-is-the-head-submit-PRs-against-this\avr\libraries\ATTinyCore\src/ATTinyCore.h:420:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
—
Reply to this email directly, view it on GitHub
<#577 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTXEW7ZPFK6NTJG45HITADXOI2ETANCNFSM46KFH7YA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Is there something I could just put in startup to change the prescaler for PWM on timer0? Is it just a register? |
Beta Was this translation helpful? Give feedback.
-
Do anyone know which carrier frequency ATtiny85 uses as default with this library? Arduino for example uses 490Hz 'as default'.
Beta Was this translation helpful? Give feedback.
All reactions