TICKS, anyone?

RogerTango

Senior Member
Nope, not the little creatures you need to remove with tweazers. :D

Does the AXE have ticks that can be read to determine elapsed time? If so, how many ticks/second does the chip run? Im running a 14M right now... Im guessing that the tick rate will be different depending on MHZ of the chip (assuming ticks is even supported!)

Andrew
 

Rickharris

Senior Member
Nope, not the little creatures you need to remove with tweazers. :D

Does the AXE have ticks that can be read to determine elapsed time? If so, how many ticks/second does the chip run? Im running a 14M right now... Im guessing that the tick rate will be different depending on MHZ of the chip (assuming ticks is even supported!)

Andrew
pause gives a time base measured in milli seconds so pause 500 is half a second.

there is also a wait command which is measured in seconds so wait 2 is the equivalent of pause 2000
 

Technical

Technical Support
Staff member
Not on the 14m.
However the X1 parts support this feature via the timer variable (see setttimer in part 2 of the manual)
 

RogerTango

Senior Member
I understand, but that is not what I need. I want to fetch the ticks, conduct a task then look at the ticks again, the difference of the two will tell my how long has elapsed between the two reads.

This would be helpful if anyone has any ideas.

Andrew
 

Jeremy Leach

Senior Member
As Technical says 'not on the 14M' ;) There might be other methods, depending on the time period - for instance if it's multiple seconds then could use a RTC chip, which you can interrogate for accurate time values. Best thing is to tell us what you're trying to time and why, and then we might be able to help more.
 

RogerTango

Senior Member
Thank you sirs, I think Technical was posting at the moment I was typing my above response.

There is yet so much to learn, I am eager... maybe too eager, I do hope the questions I generate are not unwelcome. I feel like a kid in the candy store, the PICAXE has become a focus of my electronics & ham radio hobby at this time.

Many thanks-
Andrew
 

Jeremy Leach

Senior Member
I'm sure no one feels the questions are unwelcome - we've all started from learning the basics. It's great to see your enthusiasm - there's certainly a lot of fun to be had with picaxes and a lot of helpful people here to help you along.
 

lbenson

Senior Member
As manuka points out above, Hippy's Tick code can be used to get tick from the system timer using PEEKs. Brian Lavery had a useful expansion of this code in this long thread: http://www.picaxeforum.co.uk/showthread.php?t=5849 Unfortunately, the code is much garbled because of the transition from the old format to the new. Someone had a nice version which could easily be used to time sections of code, but I can't find it now. Maybe it was Jeremy Leach's thread here: http://www.picaxeforum.co.uk/showthread.php?t=5824&highlight=PIC_T1CON
 

moxhamj

New Member
I like to write my code in a way that tends to produce ticks automatically - eg a main loop that runs continuously, and tests for inputs and goes off and does subroutines if things happen. If the subroutines are kept short, and don't happen very often, and the main loop has a pause or has a fairly constant time for execution, and you keep a counter running, then you can use that main loop counter as a sort of clock. I've had leds flashing once a second based on that clock that keep pretty good time with the ticks from a watch.
 

Jeremy Leach

Senior Member
I was thinking about this too Dr, as a rough solution. Another little idea I had too is:

1. time sections of code independantly. If you want to do this simply/roughly, then can just enclose the code in question in a test loop, loop for a big number of times and make an LED flash at the end - then work out the rough execution time. This method has been mentioned a lot before.

2. But then, have a variable 'ElapsedTime' or similar, and as each part of your code has executed, add a value to elapsed time. So every branch / option of code adds it's own value.

It's still all rough, and not sure how well it would work in practice because of accumulating errors etc !
 

westaust55

Moderator
I understand, but that is not what I need. I want to fetch the ticks, conduct a task then look at the ticks again, the difference of the two will tell my how long has elapsed between the two reads.

This would be helpful if anyone has any ideas.

Andrew
you could investigate the use of one of the PIC timers.
Not sure which ones are in use by the BASIC interpreter but there are TMR0, TMR1 and TMR2.

Using timer 0 and the SFR registers you may be able to achieve something.

SFR addr 01 = TMR0
SFR addr 11 = INTCON where bit 2 is a flag on timer roll over from $FF to $00
SFR addr 129 = OPTION_REG bit5 = 0, bit3 = 0 and bits 0,1 & 2 are the prescaler.

You will need the read the PIC datasheet to try use these timers.
you may also find your use will clash with the BASIC interpreter.
 

hippy

Ex-Staff (retired)
What the ticks / accumulated times are being used for will influence what the best solution is, also what else the chip is doing can dictate which solutions will or not work. Also whether our ticks are short or long.

One solution is to have an 08/08M sending out a tick count via serial, then when you need to know how many ticks have elapsed since last time, simply SERIN the latest tick count, subtract the last.
 

RogerTango

Senior Member
One solution is to have an 08/08M sending out a tick count via serial, then when you need to know how many ticks have elapsed since last time, simply SERIN the latest tick count, subtract the last.
Good idea- Ill have to give this more thought.

Extra components, but... might be a more practical and easy solution.

Maybe have the 08 send a tick count every 10ms, 6 of these is one second. Could be some large numbers to deal with if it runs for a few days. More thought here is needed...

I like having to come up with creative solutions... but it takes more time on a project.

Thanks,
Andrew
 

Jeremy Leach

Senior Member
Ok, here's another little idea (probably mentioned in old threads):

Code:
              ----------o---
                        |
                       .-.
                       | | R1
                       | |
               R2      '-'
   Picaxe      ___      |
  I/O Pin ----|___|-----o
                       --- C1
                       ---
                        |
             -----------o---
Fig1
Set up an interrupt on the picaxe I/O pin when the pin goes high, using SetInt command.

Tick cycle ...
- Start with picaxe pin as input.
- C1 charges via R1.
- Interrupt fires when pin goes high.
- Interrupt routine increments tick counter then sets the pin as an output briefly and set the level low. C1 discharges through R2. Set pin back to an input. ReEnable interrupt using Setint command. Then interrupt routine ends.

Cycle repeats over and over at constant rate determined by values of R1 and C1.

If rate is high then the frequent interrupts might be quite disruptive to running of your main code (although interrupt routine would be very fast if R2 a low value so discharge is very quick). But it's a simple idea that might work (even on 08M), and wouldn't need any external chip. Wouldn't be good enough for accurate clock because of temperature effects etc.

Example code ...
Code:
'DECLARATIONS
Symbol TickCounterW	= w0
Symbol TickPin = 'choose an I/O pin
Symbol DischargePause = 'set a small time in ms

'INITIALISE
SetInt ...
Input TickPin

'MAIN PROGRAM
bla bla

Interrupt:
	'Increment the tick counter
	Inc TickCounter
	
	'Make TickPin an output and sets it low
	Low TickPin
	
	'Discharge C1
	Pause  DischargePause
	
	'Set the TickPin back to being an input
	Input TickPin

         'Re-enable interrupt
         SetInt ...
Return
 
Last edited:

RobertN

Member
A variation of Jeremy's RC timer is to replace R! with a constant current diode and use an input set for A/D to read a value relative to time.
 

moxhamj

New Member
Is another chip permissable? Just thinking of a 555 astable triggering an interrupt, and the interrupt routine increments a counter.
 
Top