View unanswered posts | View active topics It is currently Fri Jul 25, 2014 7:23 am






Reply to topic  [ 13 posts ] 
Instructions per cycle.... 
Author Message
Expert

Joined: Sun Aug 19, 2007 2:43 pm
Posts: 134
Location: New Jersey
Post Instructions per cycle....
I'm back to ponder about the processing power between Arduino-Mega-Sketch vs NXT-RobotC ...

I read from one the previous post - "about 10 instructions out of the 48K cycles in a millisecond...", ie.
- ~20 µs per cycle (based on ~50 cycles per msec)
- ~1 instruction per 100 µs.

Since RobotC executable is bytecode so to speak, not like the Arduino's Sketch .hex binary code, even the processing power of Arduino's mega is lower than NXT's, I wonder how does the comparison between the two fare?


Wed Apr 17, 2013 10:50 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Instructions per cycle....
I think you're misunderstanding the quote. Here's the original:
Dick Swan wrote:
RobotC keeps a single list of waiting tasks that is sorted by when wiat-time expires. On a new timer tick it only needs to check to see if the top queue element timer is less than the current timer. This is about as close as you can get to "not consume any CPU cycles" -- i.e. about 10 instructions out of the 48K cycles in a millisecond.

I think Dick is saying that the background processing for the timers only takes about 10 instructions per millisecond. Not that 10 instructions execute in 48,000 cycles.

The NXT's main processor is the AT91SAM7S256 chip, which runs at around 48 MHz, while the ATmega1280 chip used for the Arduino Mega runs at 16 Mhz. I don't know how much overhead ROBOTC adds to the CPI (I asked this myself before) vs the .hex for the Arduino, but I'm fairly certain that the processor speed difference more than accounts for that.

_________________
sudo rm -rf /


Sat Apr 20, 2013 4:46 am
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Instructions per cycle....
The NXT uses a task scheduler, so there is overhead involved in that as well.

With the standard Arduino setup (not ROBOTC for Arduino), unless you do some fancy programming (or make use of the right library), you can't multitask on an Arduino (this applies to the Uno, Mega, Leonardo, etc.). If you do multitask on an Arduino, the task scheduler will use up a huge amount of the resources, and add a lot of overhead to the execution.

Any time you have a CPU dedicated to a single task, it will be far more efficient than running the same task on a CPU that is multitasking (especially if it uses a byte-code interpreter as well). For example, if you toggle an Arduino pin as fast as possible in code (using the standard Opti-boot and compiler, it's 4 MHz sustained), it's far faster than toggling one of the NXT IO pins in code (using ROBOTC, it seems to be about 60kHz to 72.3kHz, with a ~0.19 ms break every 1ms (likely for maintenance of the LCD etc.)).

Here are the two programs I used for testing the speed.

Uno:
Code:
void setup()
{
  pinMode(1, OUTPUT);
}

void loop()
{
Restart:
  PORTD = 0x02;
  PORTD = 0x00;
  goto Restart;
}

NXT:
Code:
#pragma config(Sensor, S1,     IO,             sensorI2CCustom)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   DigitalPinDirection[IO] = 0x03;
   Restart:
   DigitalPinValue[IO] = 0x01;
   DigitalPinValue[IO] = 0x00;
   goto Restart;
}

_________________
Matt


Sat Apr 20, 2013 12:34 pm
Profile WWW
Expert
User avatar

Joined: Fri Nov 02, 2012 12:07 am
Posts: 164
Location: California, USA
Post Re: Instructions per cycle....
What's
Code:
goto Restart;

_________________
string Robored = "Awesome"
~~Neil Balch~~


Mon Jun 03, 2013 8:41 pm
Profile WWW
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Instructions per cycle....
It means jump to label "Restart".

_________________
Matt


Mon Jun 03, 2013 9:28 pm
Profile WWW
Expert
User avatar

Joined: Fri Nov 02, 2012 12:07 am
Posts: 164
Location: California, USA
Post Re: Instructions per cycle....
And restart is..

Sorry, I really don't know :oops:

_________________
string Robored = "Awesome"
~~Neil Balch~~


Mon Jun 03, 2013 9:30 pm
Profile WWW
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Instructions per cycle....
It's just a user created label.

_________________
Matt


Mon Jun 03, 2013 9:35 pm
Profile WWW
Expert
User avatar

Joined: Fri Nov 02, 2012 12:07 am
Posts: 164
Location: California, USA
Post Re: Instructions per cycle....
So... In other words, a user defined function?

_________________
string Robored = "Awesome"
~~Neil Balch~~


Mon Jun 03, 2013 9:39 pm
Profile WWW
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Instructions per cycle....
No. Just a user defined label.

A label is a place the program can jump to.

_________________
Matt


Mon Jun 03, 2013 9:42 pm
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Instructions per cycle....
Gotos are evil... Why no use while loop?! (I don't think there's a speed difference.)

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Jun 03, 2013 9:47 pm
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Instructions per cycle....
There is a speed difference, and that's why.

A while statement checks the value, and if true runs the code, and at the end, it jumps back to check the value again. If the value is false, it jumps to the end of the while block.

goto jumps directly to the label without needing to check the value of "true".

_________________
Matt


Mon Jun 03, 2013 9:52 pm
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Instructions per cycle....
Ah. Does the RobotC optimizer take this into account, if you have a "while(true)" infinite loop? Or are compilers not smart enough yet :)

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Mon Jun 03, 2013 10:05 pm
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: Instructions per cycle....
I'm not sure about the ROBOTC compiler, but I know that some compilers do not.

_________________
Matt


Mon Jun 03, 2013 10:16 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.