/* Setting Divisor Frequency PWM on 9.6, 4.8, 1.2 MHz CPU 0x01 divisor is 1 37500, 18750, 4687 Hz 0x02 divisor is 8 4687, 2344, 586 Hz 0x03 divisor is 64 586, 293, 73 Hz 0x04 divisor is 256 146, 73, 18 Hz 0x05 divisor is 1024 36, 17, 5 Hz */ TCCR0B = TCCR0B & 0b11111000 | 0x02; // 0x02 divisor is 8 586 Hz
However, the millis and micros functions are based on counting timer-counter overflows, and this will be affected by changing the prescaler.Also note that there are two PWM modes, fast and phase correct. The core files set fast mode by default. If you switch to phase-correct [TCCR0A = _BV(WGM00);] the frequency is halved. (Actually 256/510.)Actual output frequencies will not be exactly as listed in the ATtiny13a manual. 10% slower is not uncommon. If you need an exact frequency output, you'll need an external clock.
I've also been meaning to have a look at using CLKPR as a runtime reference instead of F_CPU during compilation. Would be nice to switch speeds on-the-fly and still retain some timing functionality, at least in ms.With a 256 prescaler (37.5kHz) each clock cycle is 26.66us, so an ASM loop using 38 clocks would return after 1013.33us, which is close enough given the chip tolerances. Repeating the loop 256/CLKPR times would give the same 1ms regardless of operating frequency. (9 to choose from and no fuses to worry about!)Seems fairly simple if using the internal 9.6MHz oscillator, and not much more complex with an external clock. (Adjust for that with F_CPU at compile time.)Downside is that it's not going to work with us delays, but millis() and micros() might be possible with some work. The upside is that it would offer a lot of different PWM frequencies (20 I think) from 37.5kHz right down to 0.07Hz
However, a strange recurring feature for all my atmega chips
I'm not sure i understand you completely. This installation is only for ATtiny13 and has nothing to do with atmega mcu (they use a settings that is in a different location).Can you explain it more clearly.What programmer you use?
2. Are you sure your configuration option "attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)" works as expected? In my case IDE says it is missing "upload.tool=arduino:avrdude" and ".bootloader.tool=arduino:avrdude". However, having added those I must have locked my ATtiny13, it does not respond anymore.
avrdude -p attiny13 -P usb -c usbtiny -tuF
avrdude -p attiny13 -P usb -c arduino -tuF
2. Are you sure your configuration option "attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)" works as expected? In my case IDE says it is missing "upload.tool=arduino:avrdude" and ".bootloader.tool=arduino:avrdude". However, having added those I must have locked my ATtiny13, it does not respond anymore.P.S. May I take some more time to read the whole thread? I definitely must not be the only one to try this 128KHz option
## Overall avrdude defaults; suitable for ~/.avrduderc#default_parallel = "lpt1";default_serial = "com1";# default_bitclock = 2.5;default_bitclock = 50;
ArduinoasISP will not work at these very slow speeds.
As I have no other programmer, but Arduino Nano as ArduinoISP, does that mean I technically can *not* repair that 128KHz issue?