Name:
tmr3setup
Syntax:

TMR3SETUP config

Config - is a constant/variable that configures timer3.

Config is defined as (20X2, 28X2-5V, 28X2-3V, 40X2-3V, 40X2-5V):

Bit7 Must be set (1)
Bit6 Must be clear (0)
Bit5-4 1:8 Prescale (11)
  1:4 Prescale (10)
  1:2 Prescale (01)
  1:1 Prescale (00)
Bit3 Must be clear (0)
Bit2 Must be clear (0)
Bit1 Must be clear (0)
Bit0 Timer 3 Enable (1= on, 0 = off)

Config is defined as (28X2, 40X2):

Bit7 Must be clear (0)
Bit6 Must be clear (0)
Bit5-4 1:8 Prescale (11)
  1:4 Prescale (10)
  1:2 Prescale (01)
  1:1 Prescale (00)
Bit3 Must be clear (0)
Bit2 Must be clear (0)
Bit1 Must be set (1)
Bit0 Timer 3 Enable (1= on, 0 = off)
Description:

Configure the internal timer3 on X2 parts.

The tmr3setup command configures the internal timer3 on X2 parts. This is a free running timer that can be used for user background timing purposes.

The internal timer counts, when enabled, at a rate of (1/resonator speed) * 4. This means, for instance, at 8MHz the internal timer increment occurs every 0.5us. This value can be optionally scaled by the prescale value (set via bits 5:4) , so with a 1: 8 prescale the increment will occur every 4us (8 x 0.5us).

The PICAXE word variable 'timer3' increments on every overflow of the internal timer, ie 65536 x the increment delay. So at 8MHz with 1:8 prescalar the timer3 value will increment every 262144us (262ms).

Applies To:
20X2, 28X2, 40X2
See Also:
Related Create:
    Share:
    Print:

    28X2 Example

    This program shows how to initialise timer 3 for the PICAXE-28X2.

    Code Example:
    	tmr3setup %00110011	; timer3 on, 1:8 prescalar
    
    main:	pause 500		; short delay
    	debug			; display timer3 value
    	goto main
    Copy Code Submit an Example

    28X2-5V and 28X2-3V Example

    This program shows how to initialise timer 3 for the 28X2-5V and 28X2-3V variants.

    Code Example:
    	tmr3setup %10110001	; timer3 on, 1:8 prescalar
    
    main:	pause 500		; short delay
    	debug			; display timer3 value
    	goto main
    Copy Code Submit an Example

    Example suitable to automatically select 28X2, 28X2-3V or 28X2-5V

    This program shows how to programmatically initialise timer 3 regardless of whether the program is to run on a PICAXE-28X2, 28X2-3V or 28X2-5V device.

    Code Example:
    	readsilicon b1		; get chip silicon type
    	b1 = b1 & %11100000	; mask out type bits
    	if b1 = %10000000 then	; chip is 28X2
    	  tmr3setup %00110011	; timer3 on, 1:8 prescalar
    	else			; other type of chip
    	  tmr3setup %10110001	; timer3 on, 1:8 prescalar
    	endif
    
    main:	pause 500		; short delay
    	debug			; display timer3 value
    	goto main
    Copy Code Submit an Example

    Submit Your Own Code!

    You must be logged in to submit code examples. Login now.