18M2 touch(16) command and timer1 use

kranenborg

Senior Member
Hello,

The manual (part 2, appendix 4) is not completely clear about the timer use of the touch and touch16 command on the 18M2. From the PIC16F1827 I understand that the touch sensing module can use either timer0 (8-bit) or timer1 (16-bit). Does anybody know which timer has been used for implementing the touch commands?

In general, it would be useful to have a list of all timers and how they are used by commands (maybe as an extension of appendix 4 in manual 2)

Best regards,
Jurjen
www.kranenborg.org/electronics
 

Technical

Technical Support
Staff member
The list is fairly short:

timer 0 is 'reserved' in the PICAXE system as it is used in a large number of commands, including touch
timer 1 is user available (settimer) (but also used by servo (and M2 time))
timer 2 is reserved for pwmout and servo
timer 3 is user available (tmr3setup)
timer 4 is reserved for pwmout
timer 6 is reserved for pwmout

Note that not all timers are all available in all PICAXE types, only newer parts have 3-6 (and before someone asks, timer 5 does not exist!)
 

BeanieBots

Moderator
I'd like to see a little more explanation of the impact and consequences of mixing up timer related commands.

For example, if you use the basic "timer", its value will be compromised if you also use serial commands.

To get around that, you can use timer3 but that too is compromised if you use a command that exceeds the rollover value because the interrupt will be missed. This can happen for example with a very long serial line. The workaround being to break the line up into chunks. These are things I have found out by trial and error. Some 'inside' details and/or workarounds would be very welcome.
 

kranenborg

Senior Member
Thanks technical, that explains a lot. Glad to see that Timer1 is generally available, because this makes very accurate timing of events available using a 32KHz watch quartz crystal on the 18M2, 20X2 and other picaxes that come without resonators

Regards,
Jurjen
 
Last edited:

Technical

Technical Support
Staff member
Thanks technical, that explains a lot. Glad to see that Timer1 is generally available, because this makes very accurate timing of events available using a 32KHz watch quartz crystal on the 18M2, 20X2 and
Hippy has already done this:
http://www.picaxeforum.co.uk/showthread.php?t=13983&highlight=32khz+clock

BB - you have really already answered your own question

pwm uses an internal silicon module separate to the main processing, so the timer/pwmout use is independent of other commands

For all other background timer controlled functions (e.g. timer1 or servo) the timer 'time interval expired' overflow event causes an internal 'interrupt' that pauses the main BASIC program, processes the time event (e.g. a servo pulse) and then restarts the main BASIC program.

But interrupting time critical commands, such as serial or 1-wire, would corrupt the data. Hence the PICAXE 'bans' interrupts from occuring until the timing critcial function is finished. So a timer interrupt during the serin type of command will not process until the critical command timing is complete. This has the advantage that the BASIC command will process correctly without corrupt data, but the disadvantge that the timer based feature will have a stretched time interval (e.g. servo pulses may have longer gaps than normal).

So in summary the PICAXE gives priority to timing critical commands rather than background timer based features.
 

inglewoodpete

Senior Member
While on the subject of timers, I'd like to throw the PulsIn and Count commands into the discussion.

Both use a timer of some sort: PulsIn is a timer and the Count command has a time-out parameter. However, there is no mention of a timer constraint in either of the command descriptions or Appendix 4, "Possible Conflicting Commands". Could either of the PulsIn and Count commands conflict with, say, i2c slave communication?
 

Technical

Technical Support
Staff member
These commands do not use an internal timer, they simply use a 'timed loop' (ie counting number of instructions processed in a loop, not a timer based interrupt). That is why their resolution varies depending on clock speed (4MHz, 8MHz etc).
 
Top