By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

How would I determine the number of machine instructions needed to run a main loop?

P: n/a
I am determining the necessary processor throughput based on the amount of time a particular processor would take to handle the main loop in my code. If it is relevant, I am deliberating between using an Arduino MCU (16 MHz, 8-bit, 16 MIPS) and a Maple MCU (72 MHz, 32-bit). I know that, worst case scenario, the processor will have 12 milliseconds to run through the loop.
The below code is the "higher level" variant and calls some external codes.
Expand|Select|Wrap|Line Numbers
  1. void loop() {
  2.   potValue = analogRead(potPin);
  3.   int servoPulse = map(potValue, 0, 1023, 600, 1500); //Maps pulse in microseconds
  4.   servo.writeMicroseconds(servoPulse);
  5.   //int valveDegrees = servo.read(); //Reads the degrees the air manifold valve is open
  6.   pressureValue = analogRead(pressurePin);
  7.   int MAP = map(pressureValue, 40.92, 1002.54, 20, 250); //Maps pressure in kPa
  8.   tempValue = analogRead(tempPin);
  9.   int MAT = map(tempValue, 0, 1023, 0, 500); //Maps temp in K- values require confirmation 
  10.   //
  11.   pulseDelay = 1000*(((.79*2*14.01+.21*2*16)*7920*.148*.6)/(.0821*14.9*101.325*20))*(MAP/MAT);
  12.   sparkDelay = 215.94214021463*(timeNew-timeOld)-pulseDelay+corr; //Delay before spark fires (should the pulse calculations be at the beginning or end?)
  13. }
  14.  
This code is a little more "lower level" and incorporates fewer external calls.
Expand|Select|Wrap|Line Numbers
  1. void loop() {
  2.   pressureValue = analogRead(A2);
  3.   int MAP = (pressureValue-40.92)*(230/961.62)+20;
  4.   tempValue = analogRead(A4);
  5.   int MAT = tempValue*(500/1023); //Maps temp in K- values require confirmation 
  6.   potValue = analogRead(A0);
  7.   int servoPulse = potValue*(900/1023)+600; //Maps pulse in microseconds
  8.   //
  9.   pulseDelay = ((28.85*7920*148*.6)/(.0821*15*101.325*20))*(MAP/MAT); //Stoichiometric calculation for fuel injection timing- requires C, D, and F- simplify the number once found (allow for lean mix)
  10.   sparkDelay = 215.94214021463*(timeNew-timeOld)-pulseDelay+corr; //Delay before spark fires (should the pulse calculations be at the beginning or end?)
  11.   if (servoTimer<=(millis()-20)) {
  12.     PORTB=B00000001;
  13.     delayMicroseconds(servoPulse);
  14.     PORTB=B00000000;
  15.     servoTimer=millis();
  16.   }
  17. }
  18.  
I really appreciate the help, thanks!

-Hari Ganti
Oct 20 '10 #1
Share this Question
Share on Google+
2 Replies


ashitpro
Expert 100+
P: 542
In case of gcc, compile program with -g option.
Then invoke the gdb.
e.g.
gdb a.out
This will drop you to gdp command prompt.
after that just hit 'disas loop' command at gdb prompt
This will show you the assembly representation for method 'loop'

I don't know if this is what you are looking for.
Good luck !!!
Oct 20 '10 #2

100+
P: 687
Try it is the simulator for the first one (assuming it's slower) - avr studio(simulator), avr gcc(compiler). If it fits - you're ok, if not - you need maple.
Oct 20 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.