Code execution speed calculation

steliosm

Senior Member
Hello all.

I have been playing with the idea of creating a simple arcade game (Mame) controller using a PicAxe chip. I have created a 'breadboard version' prototype with 4 buttons which worked OK while testing a couple of games. The code is mainly a loop which scans the input pins for changes. In the complete version, I'm thinking of using 8 pins for input and since some games require fast moves I'm trying to figure out a way to benchmark my code while trying to achieve a faster scan speed.

Is there a way to measure the speed of execution of the code? I do understand that running the PicAxe at 32MHz and modifying the inputattach code to support 4800bps serial connection I might get some good results but I would like to be sure for the speed results during the code tuning procedure.

For anyone interested, using the information from this link and the Linux inputattach utility I was able to emulate a PS/2 keyboard over a 1200bps serial connection.
 

hippy

Senior Member
The best way to measure code execution time is with a "TOGGLE pin" at the start of the section and another at the end, the pulse length will be pretty close to the execution time of that code. You can measure that pulse with a scope, logic analyser or another PICAXE ( eg, using PULSIN ).

Alternative, the code to be timed can be called from within a loop a number of times. The TOGGLE is put outside that loop and the pin taken to a LED+R, its lit time measured with a stop watch. You can then calculate the approximate execution time from the stopwatch time divided by how many times the code was executed.

Rather than TOGGLE and watching a LED a SOUND command putting a beep on a piezo can work well.
 

pvdven777

New Member
Very exciting !
I'm doing several little projects with PS/2 myself. So far I've used the built in PS/2 (KBIN) routines but I was investigating feasability of writing my own code to bypass the KBIN limitations.
Sounds like that is exactly what you've done.

Funny enough I initially bumped into the Picaxe website while desperately searching for input methods on my own arcade machine to be but I ended up doing a completely different project first (http://www.picaxeforum.co.uk/showthread.php?21716-PS-2-keyboard-to-Amiga-1200-mainboard-adapter)

Anyway, would you be so kind as to share your picaxe code with us ?

Greet's

Patrick
 

inglewoodpete

Senior Member
Stelios, You don't mention which model PICAXE you are planning to use. The X2s can run at 64MHz and also have background serial I/O.
 

steliosm

Senior Member
@Patrick: Sure! I will be sharing code and schematics for the controller project.
@inglewoodpete: I'm planning to use the 14M2 chip. I will only support a single user on the controller. More users can join in using their own controller and the networked version of the arcade emulator ;-)
 
Top