PDA

View Full Version : Instruction times



BobEdge
- 4th June 2009, 16:50
Hi all,

Can anyone tell me how to work out how long an instruction takes to execute when running at 20MHz?

I have some software for firing a 3 phase bridge rectifier using thyristors. It now needs modifying to work on 50 or 60Hz. working with 50Hz just required a simple pauseus. Now it needs an if then else.

if frequency = 50 then
pauseus 1533 'delay for 60 degrees on 50Hz
else
pauseus 977 'delay for 60Hz
endif

The way phase angle firing works means that you get 6 peaks of current every mains cycle but the peaks are uneven, by as much as 200A.
I think this is because of the extra time the if then takes to run.

This just got me thinking how can I work out the time it takes to run an instruction, for time sensitive applications.

Regards
Bob...

ScaleRobotics
- 4th June 2009, 17:33
Can anyone tell me how to work out how long an instruction takes to execute when running at 20MHz?

That would be about 5,000,000 single word instructions per second. But those are assembly instructions, not PicBasic instructions. Each PicBasic instruction differs in length. To get an idea how large parts of your code is in assembly, try the codesize.php utility here: http://www.picbasic.co.uk/forum/showthread.php?t=2418

Then you can try to figure out the approximate speed of parts of your program.

mister_e
- 5th June 2009, 09:16
Some asm instructions takes 1, some other takes 2 instruction to execute, if you add conditionnal instruction then you mess up everything as they can use 1 OR 2 instructions, hence Code size is not a safe way to evaluate execution speed.

What you want to use is a internal Timer, MPLAB stopwatch OR toggle a I/O then measure it with a scope.

Look at the following, for simple code implementations. Note that you'll need to adjust those to suite 20MHz.
http://www.picbasic.co.uk/forum/showpost.php?p=39033&postcount=9
http://www.picbasic.co.uk/forum/showpost.php?p=39049&postcount=13


For accuracy, you want to use internal timer instead of Pause/PauseUs. This also allow you to do something else in meantime.

HTH