Show Posts
Pages: [1] 2 3 ... 7
1  Using Arduino / Programming Questions / Re: Function() vs Speed on: March 11, 2012, 01:00:39 pm
I give up....
2  Using Arduino / Programming Questions / Re: Function() vs Speed on: March 11, 2012, 12:44:10 pm
The evidence is in numerous books.  My experience working with assembler dates back to the early 80's with 6502 and Z80.  

You only have a limited number of registers, when you run out of registers, this doesn't mean you can't call any functions, it simply switches to the stack.  Go read some books or search online.

Like-wise, if you nest to many function calls you will run out of stack space and encounter a stack overflow.

Quote
If too many, those that don't fit are passed on the stack.

This might be useful: http://en.wikipedia.org/wiki/Calling_convention
3  Using Arduino / Programming Questions / Re: malloc(), realloc().. the dark side powerful it is on: March 11, 2012, 08:01:31 am
I'm not sure why, I always thought it was something odd about Microsofts C compiler on the PC...but I've since encountered the same problem with gcc on Linux and also with C compilers on QNX.
4  Using Arduino / Programming Questions / Re: Function() vs Speed on: March 11, 2012, 05:16:16 am
Registers are only used when available which depends entirely on what else the CPU is doing at the time, at all other times the stack is used, so you should not rely on the use of registers, but you should factor the stack into your operation as this is the worst case senario.

5  Using Arduino / Programming Questions / Re: Help with Ajax on Arduino on: March 11, 2012, 05:11:24 am
The MS ActiveX object is created on the client in script, your client would need to be running on a MS Windows host in order to create the ActiveX object...which is one very good reason for exploring the IFRAME method further, the second method isn't limited to MS Window clients and should world for other platforms.

6  Using Arduino / Programming Questions / Re: malloc(), realloc().. the dark side powerful it is on: March 11, 2012, 04:12:31 am
A common problem with dynamic memory allocation is fragmentation, for example when your application starts, the system has say 8K available....you then allocated 1K for your own uses, after your down you free that area of memory.  Unfortunately you don't get back the 8K you start with, but two areas 7K and 1K, both freely available but you can no longer allocate 8K of memory as it isn't available as a contiguous block.

Over time the memory becomes very fragmented, you still have 8K free, but in lots of small blocks that are not allocatable in one large block.  This was a common problem on PC's.  Not sure about Arduino, haven't tried it.

Years agao I wrote a control system that was used 24/7 and initially it suffered from this problem where eventually it would fail as it ran out of memory.  So I removed use of malloc, calloc and realloc and instead implement my own system.

This would allocate a large block of memory at application start-up then divide it up as required using my own versions of malloc and free.  The advantage of this was that I could get back entire blocks of memory without the fragmentation.

If fragmentation is a problem on Arduino then it should be quite straight forward to implement this kind of memory management.
7  Using Arduino / Programming Questions / Re: Function() vs Speed on: March 11, 2012, 03:45:31 am
Having an understanding of how things work at the assembly level is always useful.  Compilers can introduce problems, especially when optimizations are enabled.  

Also, when talking about the compiler, remember the job of the compiler is to produce native machine code that the processor understands.  The way a function is called and the way parameters are pushed and popped onto and off the stack are not compiler issues, it comes down to the way the processor works. 
8  Using Arduino / Programming Questions / Re: Function() vs Speed on: March 11, 2012, 03:33:13 am
The way the stack is used is pretty basic stuff, looking at the prototype for delay its simply:

void delay(unsigned long);

Which as I said would imply the parmeter delay is pushed onto the stack along with the program counter.  The context of the application has to be stored somewhere before it jumps into the function.  

http://en.wikipedia.org/wiki/Call_stack

This is a well documented fact.

I cannot speak for the code the Arduino compiler generates, however this is exactly how every other C compiler I've used works.
9  Using Arduino / Programming Questions / Re: Function() vs Speed on: March 11, 2012, 03:05:57 am
When a function is called the program counter and any parameters to pass to the function are pushed onto the stack.  The parameters are then popped off the stack for the function.

When you exit the function the program counter is popped off the stack.  The overhead depends on how many parameters you are passing to the function, you can improve this by passing parameters as pointers, wrap up all your parameters into an object or structure and pass a pointer to that.

Using an inline definately has it's uses, it effectively turns your function into a macro and removes all the stack operations, however if the function is called from many different places I wouldn't use inline, just try to optimize the function and its parameters.
10  Using Arduino / Programming Questions / Re: Help with Ajax on Arduino on: March 11, 2012, 02:55:49 am
If you want retries then you will have to implement that yourself in script.  I have some scripts I wrote a year or so ago that allow you to queue and monitor message transactions, these are all coded in Javascript.

The MS ActiveX Ajax object is a pretty simple beast.
11  Using Arduino / Programming Questions / Re: Help with Ajax on Arduino on: March 10, 2012, 05:22:24 am
Ok, if you have the web-server source, then you don't need PHP.

The AJAX request is just the same as any other client request, you just handle it and respond to it in the same way you would for a page request, the only difference is in the content.  For a normal page you would return a text document, for AJAX you return either XML or JSON.

So for example your request could be http://IP of Arduino/?req=1

req is just a name I've given to the parameter but it could be whatever you like, the value 1 is anything you want too.

Notice in the URL there is no mention of anyfile, it isn't required since you are going to handle the response in the web-server.  Normally if you were using PHP, then it is the PHP file that would respond to the client request.

A GET request is the type of request you make when you type an address into a web-browser, the alternative is a POST which is normally used for sending larger amounts of data from the client to the server.

GET's are limited in length to the maxium size allowed for a URL, normally 255 bytes.

12  Using Arduino / Programming Questions / Re: Help with Ajax on Arduino on: March 10, 2012, 04:52:52 am
As I said, I'm not familiar with the Arduino Web-Server.

AJAX is a way of allowing your clients to make Asynchronus requests to the web-server and the server to send responses to the client in the background without requiring a complete refresh of the page.

Does your application need to make use of AJAX or can you simply use http GET requests?  A get request is just the URL of the web-server with a specific page and optionally some paramaters.

The choice of platform depends on scale and the number of clients, if you are going to have quite a few clients then I would suggest that Arduino is not the right platform to host the web-server, however if its just a 1 to 1, and you aren't requesting to much, then it should be fine.

There are other techniques for performing the same type of access as that acheived with AJAX, you can get a similiar effect just using a hidden iFRAME in your document and a script to change the source document, however I haven't used this method.
13  Using Arduino / Programming Questions / Re: Help with Ajax on Arduino on: March 10, 2012, 04:37:56 am
I don't know much about the Arduino web-server, but I do know quite a lot about internet related technologies and about AJAX.  If you want to run php on an Arduino platform then you would need a binary that will execute on the Arduino platform.  Source is available for PHP but if it hasn't already been adapted for use on an Arduino, then I'm afraid you are looking at a pretty big job to make it function.

PHP is just used to execute a script on the web-server to allow you to create dynamic responses, you could just as easily use a CGI script written in C that returns what you want.

The X in AJAX stands for XML, however the response doesn't have to be in XML, I now use JSON for my server responses, the reasoning for this is JSON is much more compact than XML and can be interpret by the client as a Javascript object, its also a lot leaner than XML.

The AJAX request is just a HTTP get or post request.

Hope this helps.
14  Using Arduino / Programming Questions / Re: How many analog outputs? on: March 04, 2012, 03:14:29 pm
That could be true...my timers all use a single interrupt:

Code:
TCNT2 = 0x00;
OCR2A = 250;         // 1 ms @ Fosc = 16 MHz
TCCR2A = 0x02;          // WGM: No wave generation
TCCR2B = 0x04;          // START Timer, prescaler = 64
TIMSK2 = (1 << TOIE2);  // Enable interrupt when Timer reaches OCRA

I'll have a look at the source to see if there is a conflict.

Thank you,
15  Using Arduino / Programming Questions / Re: How many analog outputs? on: March 04, 2012, 03:04:42 pm
I'm using an Arduino Uno 3 and I read from the reference:

Quote
this function works on pins 3, 5, 6, 9, 10, and 11

However, I can confirm that I have it working on 9, 10 but not 11.

Actually, I can see what is happening on 12 and 13...its just switching on and off like a digital output, presumably at 0 and 255.

But for some reason 11 isn't working.
Pages: [1] 2 3 ... 7