Arduino Forum

Using Arduino => Microcontrollers => Topic started by: mpcz on Oct 02, 2017, 09:48 am

Title: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 02, 2017, 09:48 am
How to switch clock to 128 kHz or less? (target = minimum consumption).
I have Arduino IDE 1.8.2 + programmer with ATTINY44 + MPU TINY85.

http://www.ispshop.cz/index.php?main_page=product_info&cPath=78&products_id=647

I need to activate clock 128 kHz or less on ATTINY85 (or other mini ATMEL).
Is it possible to activate 128 kHz on this configuration?
Thank you for your help.
mpcz , 02.oct.2017
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: BJHenry on Oct 02, 2017, 10:21 am
This would probably be a good way to start...
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 02, 2017, 02:05 pm
BJHenry: thanks, yes, that's beauty ...
In my IDE there is no choice board: ATTINY ....
Need more installation? How Please?
Thank you.
mpcz, 02.oct.2017
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: hansibull on Oct 02, 2017, 02:44 pm
https://github.com/SpenceKonde/ATTinyCore (https://github.com/SpenceKonde/ATTinyCore)
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: DrAzzy on Oct 02, 2017, 05:58 pm
Unfortunately, my core still won't get him support for 128khz operation - I don't have any speeds lower than 1mhz in the list.

With some ISP programmers, there are issues with programming when the target chip is running at a very low speed, because the programmer needs to enter a low speed mode, and this mode isn't well exercised (due to very limited interest in low clock speeds) and doesn't work correctly on some programmers (and in some cases, it depends on the firmware version on the programmer - for example, in some versions of the USBAsp firmware, it needs to get told to use low speed mode by avrdude, in others it uses a jumper on the board, and in others it auto-detects it... I think, at least - I haven't played with low speed mode). It's a mess, and the use cases for such low speed operation are limited - usually you can get comparable power consumption with proper use of sleep mode and a higher clock speed.

Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: Johnny010 on Oct 02, 2017, 09:41 pm
This is already sounding like an XY problem.

What are you actually trying to achieve...like the end goal?

 

Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 02, 2017, 10:11 pm
Support for IDE ATTINY85 / 128 kHz was successful.
Unfortunately, the delay () command does not work. Here the program is blocked.
Is command "delay()" in 128kHz mode operational?
Thanks, mpcz, 02.oct.2017

p.s. (target = minimum consumption, no current peaks over 300 microA).
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: DrAzzy on Oct 02, 2017, 10:14 pm
Support for IDE ATTINY85 / 128 kHz was successful.
Unfortunately, the delay () command does not work. Here the program is blocked.
Is command "delay()" in 128kHz mode operational?
Thanks, mpcz, 02.oct.2017

p.s. (target = minimum consumption, no current peaks over 300 microA).
What core are you using?
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: BJHenry on Oct 03, 2017, 02:54 am
Unfortunately, my core still won't get him support for 128khz operation - I don't have any speeds lower than 1mhz in the list.

With some ISP programmers, there are issues with programming when the target chip is running at a very low speed, because the programmer needs to enter a low speed mode, and this mode isn't well exercised (due to very limited interest in low clock speeds) and doesn't work correctly on some programmers (and in some cases, it depends on the firmware version on the programmer - for example, in some versions of the USBAsp firmware, it needs to get told to use low speed mode by avrdude, in others it uses a jumper on the board, and in others it auto-detects it... I think, at least - I haven't played with low speed mode). It's a mess, and the use cases for such low speed operation are limited - usually you can get comparable power consumption with proper use of sleep mode and a higher clock speed.


Your core is the only one I have installed and is what I used for hat screenshot- or do you mean that the frequency isn't well supported even though it is on the list?
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: Smajdalf on Oct 03, 2017, 08:27 am
Note that often you get more power savings by fast clock and using sleep as much as possible.
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 07, 2017, 08:35 am
Hello,
I have a question:
what consumption in microA has ATMEL TINY85 or similar running at 16 kHz, 3 or 5V?
All unneeded off. Important, NO sleep mode!
Please, only verified data.
Thanks, mpcz, 07.10.2017
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: uxomm on Oct 08, 2017, 02:22 am
what consumption in microA has ATMEL TINY85 or similar running at 16 kHz, 3 or 5V?
16kHz?
Do you really mean 16 Kilohertz? Or do you mean 16MHz (Megahertz)?
Let' assume it is 16MHz.

The question is not to answer easily.
There are two types of ATtiny85. The "normal" ATtiny85 and ATtiny85V
See the working range (form the datasheet):
Quote
ATtiny85V: 0 - 4 MHz @ 1.8 - 5.5V, 0 - 10 MHz @ 2.7 - 5.5V
ATtiny85: 0 - 10 MHz @ 2.7 - 5.5V, 0 - 20 MHz @ 4.5 - 5.5V
You may notice: it may not work with 16MHz at 3 Volts.

And even if it does not really make sense, I made some measurements with ATtiny85 and ATtiny85V lying around. Just to get an idea of the consumption.
With an empty sketch like this:
Code: [Select]
void setup() { }
void loop() { }

And nothing connected but a decoupling cap (100nF).

Here are the results:
ATtiny85
1MHz* @ 3V: 1.0mA
1MHz @ 5V: 3.6mA
8MHz @ 3V: 3.7mA
8MHz @ 5V: 8.1mA

ATtiny85V
1MHz @ 3V: 0.9mA
1MHz @ 5V: 2.7mA
8MHz @ 3V: 3.6mA
8MHz @ 5V: 7.5mA

Maybe not exactly the answer you asked for, but...

----------------------
*) all clock speeds are internal clock
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 08, 2017, 09:13 am
Thank you for your response.
I have TINY85, internal 128kHz (kilohertz), divided clock at 16 kHz, about 300 microA.
I have the same, very short code on PIC 16FXXXX. Consumption of 25 microA (not sleep!).
Does anyone have a setup procedure for ATTINYxxx for similar consumption? (minimal clock, off all unnecessary, minimal frequency accuracy requirements).
Thanks.
mpcz, 08.10.2017
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: Smajdalf on Oct 08, 2017, 02:07 pm
ATTiny should have <200uA current consumption with internal 128kHz without prescaler even at 5V. Are you sure everything (including BOD, ADC etc.) is properly disabled? If using Arduino core a timer is probably running to keep millis. Also make sure all pins are either Vcc or GND (or digital buffering is disabled via DIDR0).
Also try to make something timed (blink a LED) to confirm you are not running from the 8MHz oscillator. If you have prescaler 8 (to get 16kHz from 128kHz) it would mean 1MHz running from main oscillator. Typical power consumption @1.8V@1MHz is 300uA.
But all of that are Datasheet values, I don't have Tiny85 except for Digispark board. And there are the LDO and USB voltage translator increasing current drain.
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: uxomm on Oct 08, 2017, 04:06 pm
As mentioned already: You need a "special" programmer to program the ATtiny with low speeds (like 128 kHz). Not every programmer can do this. I have 3 different ISP programmers and none of them can work with 128 kHz. But cases for low speed operation are pretty limited.

See also answer #4

And: http://gammon.com.au/power (http://gammon.com.au/power)

Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 16, 2017, 06:28 am
Hello,
upload to TINY85:

avrdude -B250 -c usbasp -p t85 -U lfuse:w:0x04:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m ....

The base frequency is reduced. 8x division does not work.
Where is the error?
Thanks, mpcz, 16.oct.2017
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: Smajdalf on Oct 16, 2017, 01:51 pm
Maybe you chande main clock prescaler in your code?
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 16, 2017, 01:57 pm
Yes, the change in code "clock/8" works OK.
I need a change of "frequency and divider" via FUSE.
mpcz, 16.oct.2017
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: Smajdalf on Oct 16, 2017, 02:03 pm
The fuse sets prescaler to divide by 8. If you change it via code later the value from fuse is overwritten. I.e. if it is set by fuse to 8 and you set it to 8 too you get total prescaling 8 (~16kHz), not 64 (~2kHz). Isn't this your problem?
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 16, 2017, 02:10 pm
Sorry, I do not understand.
I set fuses:
avrdude -B250 -c usbasp -p t85 -U lfuse:w:0x04:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
The code is empty. Frequency is 128k, not 16kHz.
What is wrong?
Thank, mpcz, 16.oct.2017
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: Smajdalf on Oct 16, 2017, 02:15 pm
Are you sure the code is empty? Are you sure no core/bootloader is present that sests the prescaler to 1? Try to add
-e
command line option to the avrdude command to erase possible remnants from the chip.
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: DrAzzy on Oct 16, 2017, 04:53 pm
How do you know that it's running at 128khz?
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: mpcz on Oct 16, 2017, 09:02 pm
I have an ocsiloscope attached to pin # 3, there is an output clock.
mpcz, 16.oct.2017
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: Smajdalf on Oct 16, 2017, 09:32 pm
How do you know the code is empty? Did you erase the chip? Try to read flash to be sure it is empty.
Title: Re: ATMEL ATTINY85 - How to switch clock to 128 kHz or less?
Post by: DrAzzy on Oct 16, 2017, 09:33 pm
Sanity check...

Upload blink to it via ICSP, compiled for 128khz. Does it blink for 1 second or for 8 seconds?

I agree with your assessment though, it should be outputting - and running at - 16khz!

I would also consider trying to set the prescaler from the application (or at least read it out and blink an LED that many times, or something...)