Go Down

Topic: Arduino Tiny (Read 64 times) previous topic - next topic

MGeo

#60
Jun 20, 2011, 12:26 pm Last Edit: Jun 21, 2011, 11:11 am by MGeo Reason: 1
Quote
Have you had any problems with it?  Made any changes?  Thought of any enhancements you'd like added?


No problems once I added pull-ups :smiley-red:

On enhancements, I would love to add onReceive and onRequest to slave lib but am not up the curve on C++ arduino enough to get very far.  I would love to help though.

For core enhancement, it would be nice to have a TinyDebugSerial Rx to go with the Tx.

I think having a full function I2C slave on ATTiny platform would be killer for the Arduino Tiny platform...big Arduino running I2C master code, and little ATTinyXXs running I2C slave code on a network of sensors, actuators and what not.

What do you say?

Best Regards,
George

BrainBooster

#61
Jun 20, 2011, 01:51 pm Last Edit: Jun 20, 2011, 08:28 pm by BrainBooster Reason: 1
...i'd like to have a MCU pinout cheathsheet with drawings and pin to pin equivalence between arduino and the other tiny dwarfs :)

Edit: i forgot it :P
here you will find the modded core files
http://www.gioblu.com/components/com_agora/img/members/15/tiny.rar

Coding Badly

On enhancements, I would love to add onReceive and onRequest to slave lib


Got it.

Quote
I would love to help though.


Careful.  You may end up with a homework assignment.

Quote
For core enhancement, it would be nice to have a TinyDebugSerial Rx to go with the Tx.


TinyDebugSerial was meant to be very small so it could be used with the memory constraint processors (ATtiny25, ATtiny2313, etcetera) and leave plenty of room for "large" applications on the "bigger" processors (ATtiny85, ATtiny84).  Receive roughly triples the size of a software serial implementation and I've had good luck with NewSoftwareSerial on the "bigger" processors so adding receive is fairly low on the priority list.   ;)

Have you tried NewSoftwareSerial?

What sort of data are you hoping to receive?  Debugging commands?

Quote
I think having a full function I2C slave on ATTiny platform would be killer for the Arduino Tiny platform...big Arduino running I2C master code, and little ATTinyXXs running I2C slave code on a network of sensors, actuators and what not.


For tiny slaves, what about using 1-Wire instead of I2C?  Do you have a need for high-speed communications?

Quote
What do you say?


I'm wrapping up a new version of Arduion ISP that should make tiny work much less painful and adding digital*Fast functions to the core for the ATtiny85 processor.  After that, I plan to add hardware support for servos.  At some point, I'll bring the core in line with Arduino 1.0.  I guess after that I can take a stab at I2C callbacks.

Coding Badly

...i'd like to have a MCU pinout cheathsheet with drawings and pin to pin equivalence between arduino and the other tiny dwarfs :)


How do the Arduino folks make their pin-out diagrams?

Quote
Edit: i forgot it :P


Which?  The pin-out diagrams?

Quote
here you will find the modded core files  http://www.gioblu.com/components/com_agora/img/members/15/tiny.rar


Modified to support ATtiny4313 processors?

BrainBooster

#64
Jun 22, 2011, 08:55 am Last Edit: Jun 22, 2011, 08:58 am by BrainBooster Reason: 1
Yes , i forgot to give the link for the modded core files :P
the above link pointing to the rar file contain the tiny core files  Modified to support ATtiny4313 processors.

Coding Badly


MGeo

#66
Jun 22, 2011, 11:47 am Last Edit: Jun 22, 2011, 11:56 am by MGeo Reason: 1

Have you tried NewSoftwareSerial?


No, I will now though.

Quote
For tiny slaves, what about using 1-Wire instead of I2C?  Do you have a need for high-speed communications?


Yes I am looking for high speed comm, half-duplex for sensor/actuator network.  I2C works but with low pin count packages it would be nice to get down to a single wire if it is possible.  Comm is all command / respond so half-duplex would seem ok.  On thinking about your suggestion, 1-Wire looks like it may be ideal but I can find little on 1-Wire slave, only 1-Wire master.  Seems Dallas/Maxim tries to prevent slaves as proprietary.  I don't think they can own the concept of a single bi-directional wire.  Maybe OpenOneWire, based on AVR274 (www.atmel.com/dyn/resources/prod_documents/AVR274.pdf)?
[/quote]

BrainBooster

@MGeo, mcu and clock of your project?

MGeo


@MGeo, mcu and clock of your project?



ATtiny85, ATTiny45 at 8 MHz internal osc, ATTiny2313 at 16MHz xtal

BrainBooster

#69
Jun 22, 2011, 08:28 pm Last Edit: Jun 23, 2011, 05:04 pm by BrainBooster Reason: 1
with newsoftwareserial, and the attiny85  at 8mhz, the uart could not work, if so...
in the NewSoftSerial.cpp file , search the line:
void NewSoftSerial::enable_timer0(bool enable)
and then change this
Code: [Select]

{

  if (enable)

#if defined(__AVR_ATmega8__)

    sbi(TIMSK, TOIE0);

#else

    sbi(TIMSK0, TOIE0);

#endif

  else

#if defined(__AVR_ATmega8__)

    cbi(TIMSK, TOIE0);

#else

    cbi(TIMSK0, TOIE0);

#endif

}


in this
Code: [Select]

{

  if (enable)

    sbi(TIMSK, TOIE0);

  else

    cbi(TIMSK, TOIE0);

}

and then it should work.
hope this help :)

Bobnova

#70
Jul 27, 2011, 08:08 am Last Edit: Jul 27, 2011, 08:24 am by Bobnova Reason: 1
Finally had a chance to play with timer1, this thing is cool!

It took me a while to get it to turn on, there are some obscure bits in some obscure registers that have to be set in obscure ways.
Once that was taken care of (thank you AVR-Freaks search feature) I was able to get down to business dragging the frequencies I want out of the thing.
There are at least four factors to the output frequency, they're listed below in no special order:

1) MCU clock speed.  Not that hard to change, but say goodbye to millis accuracy.
2) Peripheral clock speed, I think there are only two options here.  I don't really know though.  I went with high speed.
3) Clock Select bits in TCCR1.  These change both timer1 PWM outputs.  No real downside, but they go in fairly large notches speed wise.
4) TOP value stored in OCR1C, this is where the PWM timer stops counting up.  Normal is 255, if you set TOP to 127 you get 2x the PWM frequency.  Downside here (they're everywhere!) is that resolution decreases, there are only 128 possible settings from 0 to 127, as opposed to 256 for 0-255.

Below is some simple code that brings both timer1 PWM outputs from 0 through TOP (think 0-255 in normal land) at 25khz and then at 4.9kz, then 25khz, etc.  Some of the comments are from the AVR-Freaks forum, just as a heads up.
Code: [Select]
void setup(){
 for (int x = 0 ; x < 6 ; x++){
   pinMode(x,OUTPUT);
 }
/* Configure PWM  -- feq. 125KHz */
  PLLCSR |= ((1<<PLLE) ); /* Enable PLL */
   {
     unsigned char counter;
     
     /* Wait at least 100 us for PLL to stabilize */
     for(counter = 0; counter < 250; counter++)
     {
        asm("nop"); /* Each NOP should take 500 ns -- MCU Clock at 2MHz */
     }
  }
  while(bit_is_clear(PLLCSR,PLOCK)) ; /* Wait for PLL to lock (approx. 100ms) */
  PLLCSR |= (1<<PCKE); /* Set PLL as PWM clock source */
 



//The following for 4.9khz
//  OCR1C = 205; /* TOP value -- PWM with 256 bits of resolution */
// TCCR1 |= ((1<<PWM1A) | (1<<COM1A1) | (0<<CS13) | (1<<CS12) | (1<<CS11) | (1<<CS10));
 
    //The following for 25khz
 OCR1C = 160; // TOP value -- 160 at 0101
 TCCR1 |= ((1<<PWM1A) | (1<<COM1A1) | (0<<CS13) | (1<<CS12) | (0<<CS11) | (1<<CS10));

   
  GTCCR |= ((1<<PWM1B) | (1<<COM1B1)); //This turns on channel 2, on PB4


}

void loop(){
for (int x = 0 ; x < OCR1C; x++){
 OCR1A = x; //pin 1
 OCR1B = x; //pin 4
   if (x == 0){
     delay(800);
   }
 delay(30);
 }
 delay(800);
 OCR1C = 205;
 TCCR1 = 0x00;  //I don't know why, but the line below cannot write 0's, only 1's.  Hence I have to clear TCCR1 before re-writing.
 TCCR1 |= ((1<<PWM1A) | (1<<COM1A1) | (0<<CS13) | (1<<CS12) | (1<<CS11) | (1<<CS10));
 for (int x = 0 ; x < OCR1C; x++){
   OCR1A = x; //pin 1
   OCR1B = x; //pin 4
   if (x == 0){
     delay(800);
   }
   delay(30);
 }
 delay(800);
 OCR1C = 160;
 TCCR1 = 0x00; //I don't know why, but the line below cannot write 0's, only 1's.  Hence I have to clear TCCR1 before re-writing.
 TCCR1 |= ((1<<PWM1A) | (1<<COM1A1) | (0<<CS13) | (1<<CS12) | (0<<CS11) | (1<<CS10));
}


For unknown reasons I have to clear TCCR1 before the |etc. mode of changing bits works, as mentioned in the comments.

Thanks for aiming me at Timer1 Coding Badly, now that I have it (vaguely) figured out I don't have to muck with millis and/or manually trial and error calibrating OSCCAL for 6.5mhz operation!

EDIT:
This uses Coding Badly's core.  No clue whether it works elsewhere.

robbo

This is really cool stuff people!

I've been able to program some atTiny85s using ArduinoISP and the http://hlt.media.mit.edu/wiki/pmwiki.php?n=Main.ArduinoATtiny4585  core.

I'm looking to "upgrade" to the Arduino Tiny base since it looks like the shared work is headed in a direction more aligned with what I'm trying to do.

Initially I'd like to use 3 PWM channels to control an RGB LED.  When looking at the tinyX5 core set, there are two timers, both of which can drive PWM outputs.  Only timer0 can do phase correct PWM.  That's ok, for LED brightness control phase is not a problem.  So I should be able to use both timers, and theoretically have 4 PWM outputs, but...

It looks like the PWM outputs of the two timers overlap.  Pin 6 has OC0B, pin5 has both OC0A and OC1A, pin 3 has OC1B.  Sharing OC0A and OC1A on pin 5 is unfortunate if you want more PWM outputs :-)


Has anyone else experimented with more PWM channels on the tinyX5 series?

thanks,
Robbo

Bobnova

Three is about it for the ATtiny85 I believe.  Not 100% positive on that.
Three however is quite doable, and is exactly how many you need for an RGBLED.

The attiny2313 says it has four PWM channels, I haven't looked at the datasheet to see whether some overlap though.

buzzdavidson

@Codingbadly: just a side note, but this is now my favorite way of developing apps for the Tiny.  Excellent work, and wholehearted thanks for sharing.  It's really enabled me to make a lot more crazy devices with my tinys without having to resort to AVR studio.

Coding Badly

Quote
When looking at the tinyX5 core set, there are two timers


Yup.

Quote
both of which can drive PWM outputs


Yup.

Quote
Only timer0 can do phase correct PWM


Yup.  By default, the Tiny Core is configured with two phase correct outputs and one fast output.  There is a compile-time option to switch to one phase and two fast.

Quote
It looks like the PWM outputs of the two timers overlap


Yup.  And I vaguely recall that you can have both outputs enabled creating a rather strange situation.  The Tiny Core, however, only enables one of the outputs.

Quote
if you want more PWM outputs


I suspect this could be ported to the '85 processor allowing (low frequency) PWM on all the pins...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1268806013

Quote
Has anyone else experimented with more PWM channels on the tinyX5 series?


More than what?  Two?  Three?  Four?

Quote
The attiny2313 says it has four PWM channels


Yup.

Quote
whether some overlap


Nope.  Four outputs.


Go Up