; TIMER3 - nastaveni (typ C)
; TCS = 0 , TGATE = 0 (pro vnitrni CLK Tcy), TGATE = T3CON<6>
; TON = 1 (spusteni citani) = T3CON<15>
; TCKPS = 2bity , <1,0> prescaler ,  "11" pro 1:256, bity v T2CON<5,4>
; PR3 prednastaveni pro komparator 16b, spocitat pro 100ms
; pri dosazeni PR3 nastavi T3IF

T3CON = 0x30

XT = 7,3728 MHz
Fosc = krystal XT * PLL
Tcy = Fosc / 4
PLL = 4

Tcy = FXT = 7,3728 MHz

16 bit cislo <=
max 65535

=> delicka 256 => TCKPS<1,0> = "11"
=> PR3 = 2880 => 2779
=> delicka 64 => TCKPS<1,0> = "10"
=> PR3 = 11520 => 11519


Capture registry:
preruseni __IC1Interrupt

vstup IC1:

ICTMR - vyber Timer2/3, 0=T3 (ICxCON<7>)
ICM<2:0> mod(vzest. sest. hrana) (ICxCON<2:0>)
iterrupt nastavi IC1IF flag - nutno smazat v prerus. rutine
nastaveni ICBNE, ICOV z FIFO R/W logic -> IC1CON
IC1CON -> ICI<1:0> nast. interruptu ICI<1:0> (ICxCON<6:5>)
preddelicka v IC1CON

FIFO = 4x16b
IC1CON = 0x0003


ICBNE - Input Capture Buffer Not Empty
ICOV - Input Capture Overflow

IC1CON bity:
15-14 Unimplemented: Read as 0
   13 ICSIDL: Input Capture Module Stop in Idle Control bit
	1 = Input capture module will halt in CPU Idle mode
	0 = Input capture module will continue to operate in CPU Idle mode
12- 8 Unimplemented: Read as 0
    7 ICTMR: Input Capture Timer Select bits
	1 = TMR2 contents are captured on capture event
	0 = TMR3 contents are captured on capture event
	    Note: Timer selections may vary. Refer to the device data sheet for details.
 6- 5 ICI<1:0>: Select Number of Captures per Interrupt bits
	11 = Interrupt on every fourth capture event
	10 = Interrupt on every third capture event
	01 = Interrupt on every second capture event
	00 = Interrupt on every capture event
    4 ICOV: Input Capture Overflow Status Flag (Read Only) bit
	1 = Input capture overflow occurred
	0 = No input capture overflow occurred
    3 ICBNE: Input Capture Buffer Empty Status (Read Only) bit
	1 = Input capture buffer is not empty, at least one more capture value can be read
	0 = Input capture buffer is empty
 2- 0 ICM<2:0>: Input Capture Mode Select bits
	111 = Input Capture functions as interrupt pin only, when device is in Sleep or Idle mode
	      (Rising edge detect only, all other control bits are not applicable.)
	110 = Unused (module disabled)
	101 = Capture mode, every 16th rising edge
	100 = Capture mode, every 4th rising edge
	011 = Capture mode, every rising edge
	010 = Capture mode, every falling edge
	001 = Capture mode, every edge (rising and falling)
	      (ICI<1:0> does not control interrupt generation for this mode.)
	000 = Input capture module turned off

example:
; The following code example will set the Input Capture 1 module
; for interrupts on every second capture event, capture on every
; fourth rising edge and select Timer 2 as the time-base. This
; code example clears ICxCON to avoid unexpected interrupts.

	BSET IPC0, #IC1IP0	; Setup Input Capture 1 interrupt for
	BCLR IPC0, #IC1IP1	; desired priority level
	BCLR IPC0, #IC1IP2	; (this example assigns level 1 priority)
	BCLR IFS0, #IC1IF	; Clear the IC1 interrupt status flag
	BSET IEC0, #IC1IE	; Enable IC1 interrupts
	CLR IC1CON		; Turn off Input Capture 1 Module.
	MOV #0x00A2, w0		; Load the working register with the new
	MOV w0, IC1CON		; prescaler mode and write to IC1CON

	MOV #IC1BUF, w0		; Create capture data fetch pointer
	MOV #TEMP_BUFF, w1	; Create data storage pointer

; Assumes TEMP_BUFF is already defined
; The following code shows how to read the capture buffer when
; an interrupt is generated. W0 contains the capture buffer address.
; Example code for Input Capture 1 ISR:

__IC1Interrupt:
	BCLR IFS0, #IC1IF	; Reset respective interrupt flag
	MOV [w0++], [w1++]	; Read and save off first capture entry
	MOV [w0], [w1]		; Read and save off second capture entry

; test ICBNE - Input Capture Buffer Not Empty
; Remaining user code here
		
	RETFIE ; Return from ISR