please dont rip this site

SX Microcontroller Time Methods

Code:

Also:

Timer tutorial (incl prescalers)

James Newton has translated the original text from Andrew Warren [fastfwd at ix.netcom.com] of Fast Forward Engineering San Diego, California for the SX:

RTCC has three components: The clock input (either from the RTCC pin or from the internal instruction clock), the prescaler, and the RTCC register.

CLOCK INPUT:

You'll probably use the internal instruction clock as your RTCC input; I'll assume that your SX is running at 50 MHz. If you are operating in Turbo mode, this means that instruction clocks occur at a 50 MHz rate.

PRESCALER:

The RTCC prescaler is set (via 4 bits in the OPTION register) to divide-by-1, -2, -4, -8, -16, -32, -64, -128, or -256. The RTCC input clock (external or internal as set by the RTS bit in the OPTION register) is passed to the prescaler, whose divided-down output is then fed to the RTCC register.

For example, if the RTCC prescaler is set to divide-by-4 and the SX is running at 4 MHz, the prescaler will send a 250 KHz clock to the RTCC register.

RTCC REGISTER:

The RTCC register can be preloaded with any 8-bit value that you like.

Each clock pulse from the prescaler increments the contents of the RTCC register. When the value in the RTCC register rolls over from 0xFF to 0x00, an interrupt occurs (the RTCC register continues to be incremented on every pulse from the prescaler, though).

INTERRUPT FLAGS:

If the RTI flag is set when the RTCC rolls over, an interrupt is generated and the SX jumps to the "interrupt vector" at location 0x04. Your interrupt-service routine at that location should check the RTCC count to determine the source of the interrupt.

At this point in the interrupt routine, you can re-load the RTCC with any appropriate value or increment it to control the exact period of the interupt cycle.

When you're finished handling the interrupt, your code should execute a RETIW instruction, which will automatically re-enable interrupts, add W to the RTCC to control the number of cycles before the next interrupt and return to your main program.

Nikolai Golovchenko says:


When waiting for RTCC overflow by testing RTCC.7 bit, the code

	sb RTCC.7
	 jmp $-1
	snb RTCC.7
	 jmp $-1

detects overflow every 4 cycles. If RTCC is used without the prescaler, the
delay after overflow may be anywhere from 0 to 3 RTCC counts. The routine below
corrects the delay, so that it is constant for all cases.

;----------------------------------------------------------------
; Wait for RTCC overflow with zero jitter
;----------------------------------------------------------------
waitZeroRTCC
	mov w, #2
	sb RTCC.7
	 jmp $-1
	snb RTCC.7
	 jmp $-1
	add w, RTCC
	and w, #3
	add PC, w
	nop
	nop
	nop
	ret

Nikolai Golovchenko says:


The one below is 1 instruction shorter :)

;----------------------------------------------------------------
; Wait for RTCC overflow with zero jitter
;----------------------------------------------------------------
waitZeroRTCC
	mov w, #-2
	sb RTCC.7
	 jmp $-1
	snb RTCC.7
	 jmp $-1
	add w, RTCC
	add PC, w
	nop
	nop
	nop
	ret


file: /Techref/scenix/lib/flow/timer_sx.htm, 6KB, , updated: 2004/6/10 14:40, local time: 2024/10/31 18:03,
TOP NEW HELP FIND: 
3.141.45.179:LOG IN
©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://ecomorder.com/Techref/scenix/lib/flow/timer_sx.htm"> SX Microcontroller Time Methods</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to ecomorder.com!

 

Welcome to ecomorder.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .