Pages: [1]   Go Down
Author Topic: Newbie questions  (Read 6738 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm a long-time PIC user and I write in both ASM and PICBasic Pro.  I'm used to dealing very close to the hardware, and the abstraction makes me feel uneasy.  I need to read the ATMEL datasheets, but before I do, I would like to ask the following questions:

What libraries make use of all the hardware functions of the chip?
I'm mostly concerned with the serial port, SPI port, I2C and PWM.  Are they hardware, or bit-banged?

How much overhead does Sketch add?  For example, most PicBasic Pro functions are about 80% as fast as pure assembly.

What is the instruction cycle time of the Atmel chips?  For example, a PIC runs at 200nSec/instruction.

What is the interrupt latency?  Also, how many interrupt priority levels are there?

Or - if someone could point me to a (hopefully single) source for the above information, I would be most appreciative.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm mostly concerned with the serial port, SPI port, I2C and PWM.  Are they hardware, or bit-banged?
There are hardware and software implementations of serial communication and PWM, at least. SPI and I2C may be bit-bangable, but they are supported in hardware, for specific pins.

Quote
How much overhead does Sketch add?
Depends on the sketch, the OS (which typically defines the compiler in use), and the compiler optimizations selected (hard-coded, that is).

Quote
What is the instruction cycle time of the Atmel chips?
Depends on the clock speed, which is typically 16MHz, so each instruction takes 62.5 nano-seconds.

Quote
Or - if someone could point me to a (hopefully single) source for the above information, I would be most appreciative.
Well, that would be the ATMEL data sheets that you don't want to read.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I appreciate the answers that you gave, and I'm looking at the 2560 datasheet right now.  

In "PIC - land", I use a lot of interrupts, so the interrupt latency is important.  If I write an ISRs in ASM, I have only 20-30 cycles of overhead.  If I write my ISRs in PicBasic, that increases to over 100. I can't figure out how much overhead that Sketch adds.  Is there an answer somewhere?

Also, PicBasic creates macros that then call the Microchip assembler, so it produces an ASM file.  If you want to know what the compiler is doing, you can look at the created ASM file.  I don't see anything like that in Sketch.  Is there a way I can see the actual instructions being programmed into the ATMEL?

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Also, PicBasic creates macros that then call the Microchip assembler, so it produces an ASM file.  If you want to know what the compiler is doing, you can look at the created ASM file.  I don't see anything like that in Sketch.  Is there a way I can see the actual instructions being programmed into the ATMEL?

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207951658/2
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240652220
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1193790150
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1241117308

Some keywords to facilitate the search: "avr-dump", "temp" (as in the temporary directory), "hex".
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you.  That is one more step.  I have to say that while the level of abstraction that Sketch provides is very nice, it I am a bit uneasy about what is really going on.  I have seen compilers generate really  messy code.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


The GCC-AVR compiler does a very good job.  I have yet to see it do anything outright stupid.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have another question.  In the PIC world, I use interrupts heavily. I need timer interrupts, serial port interrupts, and I2C interrupts (since my uC is an I2C slave).  I can't sit in a loop and wait for a particular event to happen.

I have searched the forum, and I can't find any good explanation of how to use interrupts in Sketch.
 
I see that the 2560 (which I'm using) has vectored interrupts.  That is great, but is the compiler smart enough to use them?  And if not, is there a work-around?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I can't find any good explanation of how to use interrupts in Sketch.
Have you looked at this page?
http://arduino.cc/en/Reference/HomePage
Specifically, the sections on attachInterrupt, detachInterrupt, interrupts, and noInterrupts.

These are useful for external interrupts. The search field and button at the top of each page also finds lots of useful information on interrupts.
Quote
I have searched the forum, and I can't find any good explanation of how to use interrupts in Sketch.
I didn't have any problem finding stuff.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I looked at that, but I don't need EXTERNAL interrupts, I need INTERNAL interrupts.  I suppose I could go into the libraries and modify them, but I would think that others have the same problems I do.  I have to monitor the RPM of 9 fan tachometers at once.  Currently, (in a PIC), I have a 200uSec timer interrupt that scans the tachometer input pins, XORs them with the last reading and increments 9 different counters - 1 for each bit position changed.  After a half-second, I read the counters, multiply them by a constant and come up with the fan RPMs - and start all over again.  I have to do that simultaneously with running 10 channels of A/D and receiving, processing and responding to SNMP packets coming in at 115Kbaud from a Lantronix MatchPortAR, AND responding to telnet packets coming in at 115Kbaud from the MatchPort's second serial port.

I do that presently with a PIC18F8723 running at 40Mhz.  I am considering moving to ATMEL parts, but I want to make certain that the hardware and software tools are easy to learn and use before I spend a lot of time.  

So far, I have found lots of neat examples for Arduinos, but easy, fast interrupts are a must, and I can't see many examples using them.  I'll keep looking for awhile before I give up.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Search the core files for "ISR" and "SIGNAL".  "wiring.c" is a good place to start.  That's where the core comes to life.

Search the internet for...
http://www.google.com/search?q=gcc+avr+interrupt

You'll probably need some inline assembly...
http://www.google.com/search?q=gcc+avr+inline+assembly

More reference...
http://www.avrfreaks.net/

When all else fails...
http://www.atmel.com/
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for all your help.  Maybe someday I'll be able to contribute to the libraries.

I'm still amazed, though - there is so much Arduino code out there to do all sorts of things - and very little of it is interrupt-driven.  
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16517
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
and very little of it is interrupt-driven.

A lot of interrupt details are hidden under the hood in the Arduino core libraries. The arduino core library supports a lot of the internal AVR hardware features using interrupts, but the user doesn't have to even be aware of it.

 So even a very simple sketch, it if uses say the harware serial commands, is using interrupts but it's transparent to the user.

Lefty
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So it is handling the buffers, the timeouts and all that?

If I have a routine that looks for serial input, and I have a really long DELAY statement, will it capture long strings while it is in the DELAY period?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I have a routine that looks for serial input, and I have a really long DELAY statement, will it capture long strings while it is in the DELAY period?
You really need to be careful about using pronouns with no referent. Will what capture long strings while what is in the delay period?

Incoming serial data will be collected and added to the buffer, even while the Arduino is in delay() function call. However, the serial buffer size is limited to 128 characters. After the buffer is full, additional serial data will be lost.

As for the delays, there are far better ways to let the Arduino do things later than wasting time in a delay().
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I get it.  You correctly guessed my question.  

But is there a resource that explains things like how many bytes are in various buffers, and what the interrupt priorities are? And if I have to clear the interrupt flags before I invoke the interrupt? And if they are automatically cleared when the ISR is exited. And what the interrupt latency is?  

You get the idea.
Logged

Pages: [1]   Go Up
Jump to: