Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 19
61  Using Arduino / Programming Questions / Re: Generating single timer interrupt on: November 03, 2013, 12:07:34 am
What you do is set the OCR value for your desired delay, set your pin high, enable OCIE interrupt for your timer, the ISR is called after the delay in the ISR,, set pin low, then disable OCIE for your timer
62  Using Arduino / Programming Questions / Re: Arduino Ethernet webserver page login. on: November 02, 2013, 11:57:02 pm
You can lookup w3c protocol spec for http 1.1 under basic authentication and implement the spec.

Check out my code

https://github.com/d0ughb0y/Chauvet16/blob/master/Network.ino

Look at check_auth function

I am using TinyWebserver but you can adapt that code to work with your own webserver  code.

The login is configured in config.h and comments there tell you how to set it up.



63  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 02, 2013, 11:37:28 pm
BTW, do you remember how much time a call to the arduino sin function take?

Not only do I not remember, I never knew!

Sorry, that question was meant for Rob, and he mentions this right away in his link.

Today I did some investigations in a lookup function for sin(x).  Sin(x) takes approx 120 micros and I wanted more speed, and I knew the price was precision.

64  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 02, 2013, 08:23:54 pm
come to think of it, I can probably just map the whole function into a table, and maybe lower the resolution down to 255 or even 128 from 360. That will be a 255 (or 128) byte lookup table though.

Be careful. Depending on which Arduino board you are using, tables like this can quickly run you out of SRAM. I had two 100-byte lookup tables once, and then I decided to increase the resolution to 256-bytes each, and my program started crashing because it was running out of SRAM. You might want to look into using the progmem() keyword and its associated functions if you are working on a board with not much SRAM (Uno, for example) and have many large tables.

That's  right. I figured I actually only need a resolution of  30, so I actually only need a 30 byte array. I'm using a mega and currently have over 3k free ram.

BTW, do you remember how much time a call to the arduino sin function take?
65  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 02, 2013, 11:36:49 am
come to think of it, I can probably just map the whole function into a table, and maybe lower the resolution down to 255 or even 128 from 360. That will be a 255 (or 128) byte lookup table though.
66  Using Arduino / General Electronics / Re: 3 Solenoid valves on: November 02, 2013, 11:11:25 am
Is there a PVC version? As I'm going to pass saltwater through it.

Thanks.
67  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 02, 2013, 10:35:58 am
did some  "integer sin " exploarations here - http://forum.arduino.cc/index.php?topic=69723.0 -
might be useful

@doughboy
Can you tell more about the goal and how your code looks like (post it) . Probably we can help optimizing.


interesting. actually, if I use sin, it will be simpler, since this is for 8 bit pwm, I only work with values up to 255. I can divide the cycle into 360 resolution (1 degree can be as low as 2ms, since pwm freq is 490hz), and as high as 28ms.

the formula is (using degrees instead of radians). since isin does the %360, I can pass in the 16bit parameter as is.
value = 128 + 127 * isin(degree);
 value is unsigned 8 bit

do you see a way to optimize your function for this usage?  perhaps return as signed integer (-255 to 255) without dividing by 255, and do the /255 outside the function to make it truly floating point free? or as in earlier discussion, will the compiler  optimize the code into all integer operation?

68  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 01, 2013, 05:06:32 pm
I'm doing waveform generation. right now my code does not have floating point operation, but there might be a need for one sine function call, does not have to be done on every single interrupt, but has to be done at some interval, so I guess "a lot" was not the right choice of words.

69  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 01, 2013, 03:31:48 pm
looks like its optimized for size

http://forum.arduino.cc/index.php/topic,86810.0.html

I guess I'm splitting hairs here at this point.
maybe when I end up needing to make a lot of floating point operations inside an ISR, then I will have to revisit this.
70  Using Arduino / Programming Questions / Re: No satisfactory place to define variables? on: November 01, 2013, 03:25:16 pm
It ought not to be too difficult (within the size limitations of Arduino code) to devise a scheme for the names of variables so that the chances of accidentally using the same name in two places is nil for all practical purposes.

You would think, and yet...

ok, it seems to me this whole thread is solving the wrong problem then. the problem is between keyboard and chair.

local variable using the same name as global is perfectly valid, user needs to be aware of scoping rules.
71  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 01, 2013, 03:16:05 pm
true.

is arduino compiler set to optimize for speed or for size?

if it is optimized for size, where do I switch it to optimize for speed.
72  Using Arduino / Programming Questions / Re: No satisfactory place to define variables? on: November 01, 2013, 12:20:12 pm
Question to qwerty99 : Are you writing Large Complex Programs for the Arduino - or is it just 3-5 pages worth of code?

Principles are good, and Practical equally so - each has their strength and weaknesses defined by the enviroment. Or, as others are conveying - keep in mind that for a small (realitivly speaking) microprogram you do not need to adhere to the strictest programming practices.

We could have the same discussion on modularizing into seperate files, classes, libraries and so on.

quite true.
we always see people running into problems in arduino brag how they work in this and that project.

as to the suggestion to move variables into a class, wouldn't that class still need to be instantiated as a global ? its still the same issue, just wrapped in a class.
73  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 01, 2013, 12:10:34 pm
strange, if I call another function passing the array index number so the called function will just access the array directly via the index (array is volatile global ), the compiled size is 66 bytes larger.
my original code is to pass &myarray  to the function, then the function accesses the field as myarray->field1
changing to pass i as parameter, then the function access via myarray.field1 resulted in a larger compiled size.
74  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 01, 2013, 11:51:04 am
yeah its hard to tell.

I suppose if the generated code size is exactly the same, that means there is no difference.

On my actual program, using myarray.field1 generated a smaller code size, but not by much. 3156 to 3148.

I'm assuming that is 8 extra machine code instruction?
let's say it is. This is on 4 PWM timer interrupt service routines that get called once every 1024us each (each of the 4 ISR is invoked once every 1024us). I suppose that is not significant difference to worry about.
75  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 01, 2013, 11:06:51 am
obj-dump outputs the assembler code right?

another question is.

if I have something like

   x = a->fld1+2;
   y= a->fld1/2;
and so on...

would it be more efficient to just do

i = a->fld1;
x=i+2;
y=i/2;

I suppose looking at the assembler code will give me the answer, but I ask here in case someone knows the answer already.
thanks

Pages: 1 ... 3 4 [5] 6 7 ... 19