Go Down

Topic: Arduino translated to AVR? (Read 13 times) previous topic - next topic

bperrybap


To resolve these sync errors (not related to auto reset)
wouldn't it be easier to just bump the RX buffer size in HardwareSerial down in the core code
to avoid all these RX buffering issues?


The solution is much simpler than that: Change heartbeat to blink-without-delay.  I am sad to say I am not joking.  Because of the way both sides work (avrdude sends then waits; ArduinoISP waits, buffers, then writes) a bigger buffer is really not necessary.  I've used a modified ArduinoISP, without problems, at 9600, 19200, 250K baud and 125K, 250K, 1M SPI bitrates.


With ArduinoISP there are actually two levels of buffering. One by the HardwareSerial ISR and then one in the sketch.
It all depends on how the sketch code is written as to whether a larger ISR buffer is needed or whether a sketch buffer is needed.
Currently there is a very realtime need to process the data from the ISR buffer and move it into the sketch buffer
because the ISR buffer is not large enough to hold the full 128 byte avrdude page size being used.
When the ISR buffer gets large enough, the realtime need to drain the ISR buffer into a sketch buffer goes away.

There are two ways to solve the buffering issue:
- re-buffer the rx data in the sketch and ensure the sketch has no latencies large enough cause data loss
- make the ISR buffer large enough to hold the full avrdude data page.

The reason I said it might be "easier" to bump the ISR buffer size is that this eliminates any realtime needs in the sketch
to pull rx data from the ISR buffer.
This could make it easier for less technical folks to modify the code to add things like status indicators or whatever.
They could then do all kinds of things that are somewhat time consuming and not cause data to be lost
including using the existing heartbeat() function that stalls the CPU for 20ms at time.

It was the "lazy man's" approach to solving the problem without having to change/modify the sketch code.


It sure would be nice if the HardwareSerial library could let you easily set or override the existing
RX buffer size.

--- bill

Coding Badly

#46
Jun 14, 2012, 02:21 am Last Edit: Jun 14, 2012, 02:27 am by Coding Badly Reason: 1

I agree with everything you've written.  Control over the receive buffer size would certainly be helpful.

But, a bigger buffer would not have helped with this particular problem (the one reported by @Drc3p0).  The sign-on is a maximum of six bytes and is the first message sent by avrdude.  The current buffer is large enough to hold everything sent.  The delay introduces a race condition that, in this case, leads to a loss of synchronization.  It's just dumb luck that the sketch is so generally reliable.

Drc3p0



Does this version work any better?



Yes!!  It works!!

thank you so so much for your help.

Drc3p0

One more question... Is there a reference chart for the sketch size limitations for the different attiny's?  I'm hoping to use an attiny45v for a particular sketch i've written, but I don't know what the size limitation is.  I also know that there's 2 different versions of the attiny45v.  Does an attiny reference chart exist?

Coding Badly

#49
Jun 14, 2012, 08:37 pm Last Edit: Jun 14, 2012, 08:44 pm by Coding Badly Reason: 1
Quote
Yes!!  It works!!  thank you so so much for your help.


Excellent!  You are welcome!

One more question... Is there a reference chart for the sketch size limitations for the different attiny's?


The most reliable source is the "datasheet".  This is how I get Atmel datasheets...

• https://www.google.com/
• Enter the full processor model: attiny45v in your case
• Restrict the search to the Atmel site: site:atmel.com
• A link to the datasheet is often on the first page...
   http://www.atmel.com/Images/doc2586.pdf

Memory sizes are on the first page but in an annoying format...

2/4/8K is the size given for Flash
• On the right side, past the vertical line, is a list of models: ATtiny25/V  ATtiny45/V  ATtiny85/V
• The ATtiny45/V is second in the list so the second number (4) is the total Flash (in K)
• An Uno has about 32K of Flash available so the ATtiny45/V has 8 times less storage for code

128/256/512 is the size given for SRAM
• The second number, 256, is the storage available for data (in bytes)
• An Uno has 2K of SRAM available so the ATtiny45/V has 8 times less storage for data

Quote
I'm hoping to use an attiny45v for a particular sketch i've written, but I don't know what the size limitation is.


When you Verify (compile) your sketch, something like this is displayed in the status window...

  Binary sketch size: 304 bytes (of a 4,096 byte maximum)

If the "binary sketch size" is less than 4096, there is a high probability the code will fit.  If the size is a bit over 4096, there may be some things you can do to whittle it down to 4096.

Determining if the data will fit often has to be done by-hand.  The task is made more time consuming by the fact that "static SRAM" is not included in the status.

Quote
I also know that there's 2 different versions of the attiny45v.  Does an attiny reference chart exist?


I'm not aware of a chart highlighting the differences (but such a thing would certainly be nice). 

"Speed grades" ("V" versus non-"V") are also on the first page of the datasheet and they are also in an annoying format...

Speed Grade
– ATtiny25V/45V/85V: 0 – 4 MHz @ 1.8 - 5.5V, 0 - 10 MHz @ 2.7 - 5.5V
– ATtiny25/45/85: 0 – 10 MHz @ 2.7 - 5.5V, 0 - 20 MHz @ 4.5 - 5.5V

Basically, the "V" model can operate at a lower voltage (as low as 1.8 volts) but the maximum speed is limited to 10MHz.  If your application will be battery powered, the "V" model is an excellent choice.

Drc3p0

The IC I want seems like it might be discontinued?  it says there's only 24 left and none on order.  hmmm.  My main thing is that I need at least 3 PWM outputs.  the attiny85v only has 2, so I was going to go with the attiny84v.... http://www.mouser.com/ProductDetail/Atmel/ATTINY84V-10PU/?qs=x9Fa6eo0USnynhfIznoQQA%3d%3d

any suggestions?

Coding Badly

The IC I want seems like it might be discontinued?  it says there's only 24 left and none on order.  hmmm.  


Naw.  That's the way production goes with Atmel's DIP processors.  They make a big production run, wait for inventory to reach a certain (very low) level, then schedule the next production run.  From scheduled production to actual delivery seems to take several weeks to a few months.  The "V" processors (ATtiny85V and family; ATtiny84V and family) seem to be on an especially slow track.  You just have to purchase about a six month supply when you can.  

If inventory on the processor you want is at 24 I suggest making a decision within two days.  The last time I was in that position I waited too long and had to purchase at a higher price.  Be sure to check http://www.digikey.com and http://avnetexpress.avnet.com.  Every once in a while one of the three big vendors will have a "can't resist" low price.

Quote
My main thing is that I need at least 3 PWM outputs.  the attiny85v only has 2,


Nope.  It has three.

Quote
so I was going to go with the attiny84v.... http://www.mouser.com/ProductDetail/Atmel/ATTINY84V-10PU/?qs=x9Fa6eo0USnynhfIznoQQA%3d%3d


Let's see... the t84 has four PWM outputs.

Quote
any suggestions?


For general use, you really can't go wrong with either processor.  I use the t85 when I can and the t84 when I need more pins.  Other than that, any member of either family is a good choice.

Osgeld

looking on findchips.com (great site btw) digikey has almost 1000 of them, verical has like 5150 of them for a great price but you got to get them in lumps of 50
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

Drc3p0

#53
Jun 15, 2012, 09:08 pm Last Edit: Jun 15, 2012, 09:17 pm by Drc3p0 Reason: 1
I was hoping to get the price break at 25 IC's.  If I can figure out how to use the attiny85v then i'd much rather just go that route!



Nope.  It has three.



I'll have to check the data sheet... I've been referencing the hi-low tech page about the attiny's, which lists only 2 PWM outputs for pinout image http://hlt.media.mit.edu/?p=1229

Drc3p0

The datasheet states that the attiny45/85v has 2 High Frequency PWM Outputs with Separate Output Compare Registers
http://www.atmel.com/Images/2586s.pdf

Is there a hidden 3rd PWM output? 

Coding Badly

The datasheet states that the attiny45/85v has 2 High Frequency PWM Outputs with Separate Output Compare Registers http://www.atmel.com/Images/2586s.pdf
Is there a hidden 3rd PWM output? 


I warned you about that page.   ;)

Quote
8-bit Timer/Counter with Prescaler and Two PWM Channels

8-bit High Speed Timer/Counter with Separate Prescaler
• 2 High Frequency PWM Outputs with Separate Output Compare Registers


One timer with two PWM channels and a second timer with 2 high frequency PWM outputs for a total of four.  Unfortunately, two of the outputs are on the same physical pin so only three outputs can be active at any one time. 

Atmel AVR datasheets are filled with subtlety.  You have to check "1. Pin Configurations" to determine that two of the outputs overlap (look for pin labels that start with "OC").


Nope.  It has three.

I'll have to check the data sheet... I've been referencing the hi-low tech page about the attiny's, which lists only 2 PWM outputs for pinout image


Alessandro Saporetti's core had support for two PWM outputs.  I believe the diagram and documentation are from his core.

The hardware (essentially) has three PWM outputs and the Tiny Core support supports all three.  I have no idea if the current HLT core has support for two or three.

Drc3p0

I am going to be controlling a RGB LED Via PWM so how would I be able to control all three outputs at the same time?  What pins would be used for PWM?  I am trying to understand your explanation

Coding Badly


The PWM pins are...

PB4, physical pin 3, digital pin 4, third pin down on the left side
PB0, physical pin 5, digital pin 0, fourth pin down on the right side
PB1, physical pin 6, digital pin 1, third pin down on the right side

Basically, add a (PWM) label to the pin just above GND on the diagram you posted...




Just like on a typical Arduino board, analogWrite is used to change the PWM output...

Code: [Select]
analogWrite( 0, 127 );
analogWrite( 1, 127 );
analogWrite( 4, 127 );


Drc3p0

I'll definitely utilize the attiny85v vs. the attiny84v, now that I know that the extra PWM pin is available.  I find it odd though that it isn't clearly stated though.

once again, Thank you for your help!

Coding Badly


You are welcome!  I hope your project goes well!

Go Up