Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 19
61  Using Arduino / Programming Questions / Re: How speed up timers Arduino-UNO or Due (for 1...10 usec. pulse generation) on: November 03, 2013, 05:06:35 pm
try this on MEGA to get 0.5us 50% duty cycle pulse (2mhz)
for UNO, change PB5 to PB1
Code:
void setup() {
DDRB |= _BV(PB5);
TCCR1A=0;
TCCR1B=0;
TCCR1A |= _BV(WGM11);
TCCR1B |= _BV(WGM13)|_BV(CS10);
OCR1A = 2;
ICR1=4;
TCCR1A |= _BV(COM1A1);
}

void loop() {

}

PWM output is on Digital pin 9 for UNO, and pin11 for MEGA

this is the waveform



You you want a really high frequency, you can make the arduino timer use an external clock instead of the arduino 16mhz clock.

I think this is the simplest solution to what you need.
62  Using Arduino / Programming Questions / Re: How speed up timers Arduino-UNO or Due (for 1...10 usec. pulse generation) on: November 03, 2013, 04:05:06 pm
a correction to my correction. The UNO can do modes 10 and 11 as well on the 16 bit tmer register.

do you need a shorter period (higher frequency) or a higher resolution?
the default arduino library analogWrite pwm is 8 bit resolution at 490hz.

you  can do 16 bit pwm resolution but at 122hz, or 2 bit pwm resolution at 2.6mhz on the 16bit timer registers
see pages 128-129 of Atmega328 datasheet

it is just a few lines of code to do it.
63  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 03, 2013, 03:32:02 pm
thanks. this technique is perfect for ISR code use.

64  Using Arduino / Programming Questions / Re: How speed up timers Arduino-UNO or Due (for 1...10 usec. pulse generation) on: November 03, 2013, 03:08:57 pm
correction to my above note. it only applies to atmega2560. atmega328 does not go beyond mode 7. I have not used the due.
65  Using Arduino / Programming Questions / Re: How speed up timers Arduino-UNO or Due (for 1...10 usec. pulse generation) on: November 03, 2013, 03:00:50 pm
the arduino analogWrite pwm uses 490hz freq,or about 2ms period.
If you want to do 1us period on the UNO, you must access the timer registers directly.

first, use a smaller divider, like 8, which gives you 0.125us per timer count,
this gives you 8 counts to get your period of 1 us.

if you use mode 11, phase correct PWM mode, all you need to do is set OCR register to 4, then you will get your 1us pulse at 50% duty cycle. the divider and mode are set in timer registers TCCRnA and TCCRnB

If you want a duty cycle other than 50%, then you must use mode 10, use ICR register to set your top (value 4), then the OCR register to control your duty cycle.

everything you need to know is in the timer/counter chapter in the atmega datasheet.

66  Using Arduino / Programming Questions / Re: which is more efficient? using -> or . to access array of struct members on: November 03, 2013, 02:49:12 pm
since we are speaking of optimization, are you able to check and confirm the compiler did not turn your for loop into a noop?

when I did the object dump check on some of my test program, I noticed the compiler completely omits code that actually are noop, like assigning something to a variable that is never used.
67  Using Arduino / Programming Questions / Re: Generating single timer interrupt on: November 03, 2013, 03:54:53 am
Thanks all for the suggestions.  The boolean flag solution is not suitable.  The other methods are what I had thought I would do. 

I was just wondering if there was a register value that would achieve the same thing automatically.

Thanks for the links Nick.  They look useful

Exactly what I said above is exactly what you want.

You can read the data sheet first. Everything you need to know is there. Do you need an example?
68  Using Arduino / General Electronics / Re: Who can identify Chinese led color names please? on: November 03, 2013, 12:13:12 am
Fungus got it right.

The handwriting is like chicken scratch, or old people handwriting smiley
69  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
70  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.



71  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.

72  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?
73  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.
74  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.
75  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?

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