Author |
Message |
elizabeth.mabrey
Expert
Joined: Sun Aug 19, 2007 2:43 pm Posts: 156 Location: New Jersey
|
 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?
_________________ ==Elizabeth Mabrey
|
Wed Apr 17, 2013 10:50 am |
|
 |
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 Re: Instructions per cycle....
I think you're misunderstanding the quote. Here's the original: 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 |
|
 |
mattallen37
Expert
Joined: Thu Sep 29, 2011 11:09 pm Posts: 184 Location: Michigan USA
|
 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: NXT:
_________________ Matt
|
Sat Apr 20, 2013 12:34 pm |
|
 |
roboRed
Expert
Joined: Fri Nov 02, 2012 12:07 am Posts: 163 Location: California, USA
|
 Re: Instructions per cycle....
_________________ string Robored = "Awesome" ~~Neil Balch~~
|
Mon Jun 03, 2013 8:41 pm |
|
 |
mattallen37
Expert
Joined: Thu Sep 29, 2011 11:09 pm Posts: 184 Location: Michigan USA
|
 Re: Instructions per cycle....
It means jump to label "Restart".
_________________ Matt
|
Mon Jun 03, 2013 9:28 pm |
|
 |
roboRed
Expert
Joined: Fri Nov 02, 2012 12:07 am Posts: 163 Location: California, USA
|
 Re: Instructions per cycle....
And restart is.. Sorry, I really don't know 
_________________ string Robored = "Awesome" ~~Neil Balch~~
|
Mon Jun 03, 2013 9:30 pm |
|
 |
mattallen37
Expert
Joined: Thu Sep 29, 2011 11:09 pm Posts: 184 Location: Michigan USA
|
 Re: Instructions per cycle....
It's just a user created label.
_________________ Matt
|
Mon Jun 03, 2013 9:35 pm |
|
 |
roboRed
Expert
Joined: Fri Nov 02, 2012 12:07 am Posts: 163 Location: California, USA
|
 Re: Instructions per cycle....
So... In other words, a user defined function?
_________________ string Robored = "Awesome" ~~Neil Balch~~
|
Mon Jun 03, 2013 9:39 pm |
|
 |
mattallen37
Expert
Joined: Thu Sep 29, 2011 11:09 pm Posts: 184 Location: Michigan USA
|
 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 |
|
 |
Ernest3.14
Professor
Joined: Sat May 18, 2013 1:24 pm Posts: 271 Location: Olympia, WA
|
 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 |
|
 |
mattallen37
Expert
Joined: Thu Sep 29, 2011 11:09 pm Posts: 184 Location: Michigan USA
|
 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 |
|
 |
Ernest3.14
Professor
Joined: Sat May 18, 2013 1:24 pm Posts: 271 Location: Olympia, WA
|
 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 |
|
 |
mattallen37
Expert
Joined: Thu Sep 29, 2011 11:09 pm Posts: 184 Location: Michigan USA
|
 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 |
|
|