Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Timer 2 prescaler bits... can't set to 32 :( on: October 17, 2010, 01:01:53 pm
Quote
It sounds like you're saying you think you can run the timer at 16us or at 128us.  I'm no expert on interrupts, and I'm not sure where you get those numbers, but if you divide 1 second by 16mhz, you get 0.0000000625.  I'm not sure whether that's 6.25us or 625us, but I don't see a 16 in there.

Anyway, I'm getting off track.  You seem to think you can run the interrupt at /1 or /8 or /32... and that is the speed at which your interrupt is called.

But that's not the case.  That is the rate at which your timer updates.  And while you can call the interrupt every time the timer updates, you can also call it every 2nd or 3rd or whatever time it updates.

So you could set the timer to a prescalar of /8 OR you could set it to /1 and then set it to trigger when it compares itself to a certain register and the values are equal, and then set that register to 8.  The interrupt would then be triggered just as often as it would have been if you set the presclar to /8 and made it trigger every time.

This means that if /8 is too slow, but /1 is too fast, you could set that register I mentioned to 6, and then effectively get clk/6.

At least that is my understanding of how it all works.  I am in the middle of writing some interrupt code myself.

Hey there, I set it up so that Timer2 calls my ISR every time it overflows, the lowest rate I can get it to do that is 16us. The next prescaler value causes it to overflow every 128us... which is what I've had to use, which is just about usable for my project.
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Timer 2 prescaler bits... can't set to 32 :( on: October 16, 2010, 07:44:34 am
Thanks Senso, good tip, I will adjust my code to the correct way. By luck the top bits must already be clear smiley
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Timer 2 prescaler bits... can't set to 32 :( on: October 16, 2010, 07:42:31 am
Thanks for the link, If I've read it properly... my original settings were un prescaled... so 16us is the timer rate, and the next setting is a devisor by 8, which is giving me my 128us. So that is the fastest I can get on this timer, above 16us

That will have to do, it's not perfect, but it is just about fast enough!

Many thanks.
4  Forum 2005-2010 (read only) / Syntax & Programs / Timer 2 prescaler bits... can't set to 32 :( on: October 16, 2010, 06:57:28 am
Hi all,

I set Timer2 to:

  TCCR2B = 0<<CS22 | (0<<CS21) | (1<<CS20);

which gives me a prescaler of 16us per interrupt, but that interrupt is too short to do anything more than increment a few counters... I would like to set the prescaler to 32... but adjusting these bits scales down too much smiley-sad

Can any help me set the prescaler to 32?

thanks x

EDIT:

I currently use:   TCCR2B = 0<<CS22 | (1<<CS21) | (0<<CS20);

which scales to 128... this gives me plenty of time to check some logic in my ISR... but is a little to corse for the timing requirements of my project
5  Forum 2005-2010 (read only) / Interfacing / Re: Processing serial.write command slow; any ideas? on: October 01, 2010, 08:40:44 am
Hi Mike, appologies I don't think I wa clear in my original post. I did not check the transmission time from the Arduino to the computer. I timed how long the actual Serial.write() function took to execute on the board itself, at 115200 I was getting ~600microseconds at double the baud rate I was getting ~300 microseconds.

AFAIK, the AVR should transmit to the Serial-USB bridge at a constant rate and that should be handled by a hardware UART
6  Forum 2005-2010 (read only) / Interfacing / Re: Processing serial.write command slow; any ideas? on: October 01, 2010, 08:06:47 am
Hi, as I only sent 4bytes to test the Serial.write function, I was not limited by the transmit buffer and the USB polling... Is there any explanation for my slowness? Is the source code to the Serial object available?
7  Forum 2005-2010 (read only) / Interfacing / Re: Processing serial.write command slow; any ideas? on: October 01, 2010, 07:27:36 am
I have a similar problem! I need to be able to send data very quickly. I profiled the Serial.write() function and found it takes 600microseconds to return (and thus continue program execution) after sending 4bytes of data. The speed of this function is dependent upon the baud rate, I assumed that the pins1/2 serial connection was handled by a UART and thus should be asynchronous to the program execution.

Does anyone have any ideas to speed this up?
8  Forum 2005-2010 (read only) / Development / Re: Arduino Nano vs. mbed LPC1768 on: October 04, 2010, 05:46:06 am
As I now have both, I can probably give a good answer.

The Arduino is the better device for hobby, fun and beginner projects. The dev environment is more mature, offline and quicker to get up an running.

I have an mbed simply because I needed some serious number crunching in a project. If Arduino made an ARM board I would have got that and been happy to keep using the Arduino dev environment, using my existing source code.

Pages: [1]