Arduino Tiny

Bobnova:
I'm definitely down for playing with the high speed timer

Excellent!

if that can get me 20-25khz pwm on two pins (and separate duty cycles on the two pins),

Timer 1 is very PWM versatile so i'd be very surprised if you could not get what you want.

I've been trying to convince the 328 to do it, but I'm missing something.

Timer 1 will do it. I think you need to use "mode 14". Search for a topic about 10 KHz PWM and "Coding Badly" and "ICR1". I vaguely recall helping two people so there may be two topics.

Thanks for the specifics on that. Now I have something to play with while I wait for a couple $0.50 10mhz oscillators to show up (I need to make a digikey order anyway).

If you do play with the 85 / timer 1, please follow-up with your experience. I've wanted to play with the various esoteric ATtiny timers. They are definitely interesting critters. I'd really like to here about your experience with it.

The OSCCAL datasheet page says that using OSCCAL to get >8.8mhz operation isn't recommended as it doesn't give the EEPROM enough time to write correctly in some cases

Got it. Thanks.

Also, a general thank you! for creating the port in the first place and jumping in to help us with odd stuff like this. It's appreciated!

You are welcome!

I'd have downloaded Arduino Tiny sooner had I known it was so easy to install and use! Is there any reason not to use

attiny85at1.upload.using=arduino:usbtinyisp

in the boards.txt file? I tried it, and it seems to work just fine, but I thought I'd ask...

Arduino Tiny ... so easy to install and use!

I agree!

Is there any reason not to use...

The "arduino:" part tells the IDE to use the common / shared /IDE "programmers.txt" file. So, no problem at all.

I found the thread you were talking about, it looks like if I can make it work in the tiny (the thread was about a 168 or 328) I can have pretty much any PWM speed I want! The key is that there is another different register that the TOP count value can be compared to, one that isn't the duty cycle register for the other PWM output.
I'm hoping the tiny85 can do it also, that'd be perfect!

Haven't had a chance to play with it, I did get the prototype fan controller perfboarded though. Might have some time this weekend.
Whenever I do get a chance I will definitely report in with what I find!

[quote author=Coding Badly link=topic=51984.msg450383#msg450383 date=1306358257]
If you're willing to learn about a new type of timer, timer 1 may give you what you need without resorting to a 10 MHz clock speed. Timer 1 was built for high-speed PWM.

If you decide experiment with timer 1...

• Locate and open the "core_build_options.h" header file

• Change the INITIALIZE_SECONDARY_TIMERS #define to be "0" (without the quotes)

• In the ATtiny85 section, change the TIMER_TO_USE_FOR_MILLIS #define to be "0" (without the quotes)

• Timer 1 is now free to use as you please.[/quote]
Did this, my PWM frequency doubled to 31.something khz, slightly higher than needed but not badly.
My millis are toooootally out to lunch, I get about the same debounceness with it set to 1500 millis as I used to with 30, so around 50 times as many millis per second, maybe 60ish. This isn't really a problem, as that debounce routine is literally the only place I use millis, and delay isn't used at all.
It got rid of the whine in one of two fans tested so far, I call it a success!
(Oddly, millis behaves the same way regardless of whether I upload it with the board set to attiny85@8mhz or @1mhz, something weird there. Doesn't make a difference to me, but it's strange)

EDIT:
I spent some time with OSCCAL, and got myself an absolutely perfect 25.5khz signal. It's running the core at 6.5-6.6mhz, right around the ATTINY15 compatibility speed amusingly enough.

My millis are toooootally out to lunch,

How strange. I know I tested millis on timer 0. I think I even started with millis on timer 0. I must have failed a final check after some modification.

What did you end up using for the processor clock? Internal 8 MHz?

I created an issue...
http://code.google.com/p/arduino-tiny/issues/detail?id=2

It got rid of the whine in one of two fans tested so far, I call it a success!

Excellent!

(Oddly, millis behaves the same way regardless of whether I upload it with the board set to attiny85@8mhz or @1mhz, something weird there. Doesn't make a difference to me, but it's strange)

Do you mean without changing the fuse settings? (Without performing a Burn Bootloader?)

EDIT: I spent some time with OSCCAL, and got myself an absolutely perfect 25.5khz signal. It's running the core at 6.5-6.6mhz, right around the ATTINY15 compatibility speed amusingly enough.

All the benefits of an ATtiny15 without those painful limitations!

First a disclaimer, I'm on Ubuntu 11.4, I don't know if that changes things or not.

Fuses are (manually) set to 8mhz internal operation, using the burn-bootload function wouldn't change them for some reason. I haven't gone back and tried again as I've been working on other issues.
Now I have a decent stack of attiny85s I'll start playing with a fresh one and see what happens at some point here.

Yes, selecting 1mhz and 8mhz without burning a bootloader or manually changing fuses and then re-uploading an identical sketch doesn't change the behavior of millis.

Bobnova:
First a disclaimer, I'm on Ubuntu 11.4, I don't know if that changes things or not.

It may. There is problem with the AVR GCC compiler on Linux. I vaguely recall that delay was effected but I don't remember any mention of millis. You may want to spend a few minutes searching the forum. If you do find the the culprit, please report back. My suspicion is that it is a bug in the core.

Fuses are (manually) set to 8mhz internal operation, using the burn-bootload function wouldn't change them for some reason.

Bummer. I love being able to do that. I switched a processor to 1 MHz just a few minutes ago.

Yes, selecting 1mhz and 8mhz without burning a bootloader or manually changing fuses and then re-uploading an identical sketch doesn't change the behavior of millis.

That is strange. I suspect curiosity will get the better of me and I'll end up working on it over the weekend. I'll let you know if I have any more questions.

I'll fire up windows7 and play with the bootoader and millis stuff sometime this weekend and report in.

Coding Badly,

Is there any documentation, example or post to point me to on using TinyDebugSerial?

If it matters, I will be using it with my Pololu USB Programmer as a serial monitor?

Thanks,
George

MGeo:
Is there any documentation, example or post to point me to on using TinyDebugSerial?

TinyDebugSerial is a write-only software serial implementation. It is meant to be a drop-in replacement for Serial. No one has complained about it so I assume it really is a drop-in replacement. So, any Arduino Serial examples should compile and run just as they do for other processors.

There is usage information here...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285218245/25#25

Some information about the ATtiny2313 processor and TinyDebugSerial here...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285218245/26#26

This is important for saving precious SRAM or if you plan to use a crystal on your Tiny processor...

If it matters, I will be using it with my Pololu USB Programmer as a serial monitor?

Nice! You will be able to keep your terminal application running and connected while you upload! I am a big fan of the Pololu USB Programmer!

Ok so I've found timer1 in the datasheet and have starting digging in. This looks very promising!
The only question I have at the moment is, how can I change just some of the bits in a control register byte?
For instance, say I want to (in the middle of a sketch) change the last four bits of TCCR1, and not the first four bits, how do I do this?

Armed with that knowledge, I think this project of mine (including changing PWM speed within the sketch) is not only doable, but fairly easy.

What I typically do so the intent is crystal clear...

TCCR1 =
( TCCR1 & ( (1 << CTC1) | (1 << PWM1A) | (1 << COM1A1) | (1 << COM1A0) ) ) // Strip the first four bits
| // Merge with the next four bits
( (0 << CS13) | (0 << CS12) | (1 << CS11) | (0 << CS10) ); // Last four bits

Coding Badly,

Slowly working on TinyDebugSerial.

A clarification please. From http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1285218245/25#25
"Serial transmit pin is PB3 / pin 3. Basically, the transmit pin is the first I/O pin in the upper-left corner. " I soldered up pin 3 in my TinyDuino and tried it but no joy. I assigned pin 2 to as output to power a diagnostic LED as well.

Checking the data sheet, PB3 is pin 2 and is the first I/O pin in the upper left corner (not counting /RESET, which can be used for I/O if you want it bad enough?). This means the pin 2 LED output assignment was stomping on TinyDebugSerial.

So... I am switching to pin 2, and modifed the test sketch to what is attached below. Did I get all this correct? Want to clarify so others can follow.

/*

ATMEL ATTINY45/ARDUINO:
                  +--\/--+
 Ain0 (D5) PB5  1 |      | 8  VCC
 Ain3 (D3) PB3  2 |      | 7  PB2 (D2) Ain1 INT0
 Ain2 (D4) PB4  3 |      | 6  PB1 (D1) pwm1
           GND  4 |      | 5  PB0 (D0) pwm0
                  +------+

*/ 

#define LED_PIN           4                     // ATtiny Pin 3 (D4)

void setup(){
  pinMode(LED_PIN,OUTPUT);                      // for general DEBUG use
  LED_Blink(LED_PIN,2);                         // show it's alive
  Serial.begin(9600);
}

void loop() {
  int test = 0x31;
  Serial.println( F("This string only consumes Flash.") );
  Serial.print(test);
}

// LED blinker for status
void LED_Blink(byte pin, byte times){
  for (byte i=0; i< times; i++){
    digitalWrite(pin,LOW);
    delay (1000);
    digitalWrite(pin,HIGH);
    delay (1000);
  }
}

Thanks again for all the help,
George

Argh! I hate that the Arduino folks called them "pins". Why not use the Latin word instead (acus)? Then Ancient Romans would be the only ones confused!

Serial transmit pin is PB3 / Arduino pin 3 / DIP package pin 2. Basically, the transmit pin is the first I/O pin in the upper-left corner.

Did I get all this correct?

Looks like it.

Works like a charm. Not having to close the terminal window for each download is much better, and I can use any terminal or serial application I want.

I put a socketed ATTiny85, decouple cap and ICP connector on a proto-board so I can plug it into my breadboard. Now known as Tinyduino (is that taken?). So at this point I have I2C slave working and now have a nice serial dubug port thanks to excellent Arduino Tiny core and Pololu USB. Time for next phase of project.

what about to add the Attiny4313 support to Tiny core ? ( attiny2313 bigger brother )
are you planning to do it?

(deleted)

Works like a charm.

Excellent!

Not having to close the terminal window for each download is much better, and I can use any terminal or serial application I want.

That alone makes the Pololu Programmer worth the money.

I put a socketed ATTiny85, decouple cap and ICP connector on a proto-board so I can plug it into my breadboard.

Nice.

Two things I've found that work well...

  1. Teensy (with pins) + (modified) Arduino ISP + small bread board + ATtiny85. It's nice simple / single project prototyping tool.

  2. Male pins on the the Pololu Programmer (+5V, GND, RX, TX, A, B). It can then be inserted onto the edge of a breadboard.

Now known as Tinyduino (is that taken?).

Seems familiar but that's probably because of all the *duino names!

So at this point I have I2C slave working

With the library BroHogan published?

I like the little board.

what about to add the Attiny4313 support to Tiny core ? ( attiny2313 bigger brother ) are you planning to do it?

A look at the migrating document...

...reveals there really is no significant difference between the two.

The Tiny Core has support for the ATtiny2313.

Have you tried programming the 4313 using one of the 2313 selections?