PICAXE - How fast ?

Buzby

Senior Member
Hi,

I'm looking at using the PICAXE 18X running at 4MHz to monitor two digital inputs which are repeatedly changing state every 8 seconds, at approximately the same time as each other within a 2 sec window. ( i.e. one might change at 7.65 sec and the other at 9.20 sec, then again at 17.30 and 15.85, a bit like times on a stopwatch for two runners.)

The PICAXE will record the timestamp at which each input changes, then send these values out over a serial port. I know this task is fairly simple to code, but how fast will a PICAXE be able to this ?.

The time difference between the inputs could be from zero to 2 seconds , and I need results to a resolution of 5ms or better.

Am I on a hiding to nothing if I try to use a PICAXE for this task ?.

( The reason I looked at PICAXE is becase the project board is exactly what I need, no having to build any extra gubbins. I need 12 of these, so the less hardware mods the better !.)
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

With 5ms resolution and an 8 second time frame a PICAXE should be able to handle this, even the 08M. It can poll for either input ( including both together ), and then poll for the second. There's then a few seconds to process and output the data. There's usually no reason to stick to 4MHz when 8MHz is available.

To get a reliable timebase on anything less than a 28X1 you will have to jump through some hoops and peek / poke timer registers. On the plus-side, the 08M is cheap, as is the AXE021 08 Proto Board and you could probably just as easily build on veroboard or stripboard.

I would recommend prototyping a single system before building multiple units.
 

lbenson

Senior Member
Check this recent thread on timing of 5 inputs: http://www.picaxeforum.co.uk/showthread.php?t=11469

If what you want is the time between one input coming on and then the next one, then a very tight loop like the following might do it for you.

Code:
#picaxe 08M

main:
  do
    do : loop while pin1 = 0  ' wait for signal 1
    w6 = 0
    do
      inc w6
      pause 1  ' wait a millisecond; use pulsout for smaller pause down to 10us
    loop while pin2 = 0       ' wait for signal 2
' now do what you want to do when you have detected the two pulses
    if pin1 = 1 then : do : loop until pin1 = 0 : endif ' wait until 1 clears
  loop
For refinement of timings, check this thread: http://www.picaxeforum.co.uk/showthread.php?t=11497
 

Buzby

Senior Member
Hi,

Thanks for your prompt replies - I knew I'd get some good results here !.

Hippy: Regarding the peek/poke stuff to access timer registers. I was expecting something like this, it's the only way I could think of to get a stable timebase without extra hardware. If PICAXE code can configure and execute an interrupt on a timer rollover, say every 1 or 2ms, then I'm on a winner !. I can peruse the PIC and PICAXE datasheets to get the details, I just wanted the forum to give me a quick yes/no !.

lbenson: Your code snippet give me accurate delta-T between the events, not a timestamp referenced to Time-Zero. I looked at the timing link you gave. Lots of useful information there. Thanks.


It's been a while since I last programmed PICs, all in assembler in MP-LAB. I could do it that way again, but PICAXE looks more fun !.

The serial port will actually be a wireless link, so I was looking at the AXE210 board with an XBee module. Again, no hardware to build.

I've got an ancient Rev-Ed board called PIC Interface A V2, which has been languishing in by box of odd bits for ages, I'll try and power that up to start with. ( Just did it !. It's a 'PICAXE-18 Firmware Version 3'. How old is that ? )

This should be enough to get my code started, until I order the AXE210 boards.

I'll keep you updated.

Cheers.
 
Last edited:

lbenson

Senior Member
Reaching way back this long thread has a peek and poke routine which can signal half-second events, as well as provide access to finer resolution: http://www.picaxeforum.co.uk/showthread.php?t=5849

Moderately accurate long-count timers can be built with this, tho I'm not sure how long it would take to be out by 5ms. An update to this routine would be a useful addition to the code snippets library.
 

hippy

Technical Support
Staff member
Setting timer 2 running then polling for overflows to increment msb of a timestamp and grabbing msb of timer as lsb of timestamp ( or something like that ), while polling the inputs should all be achievable within 5ms I think. One advantage of the 08M is it can be configured to run timer 2 from a watch crystal which keeps the timebase quite accurate over longer time periods.
 
Top