GP32 Timer4 Interrupt


light0

Still Fresh
Joined
Aug 14, 2006
Messages
4
Could someone let me know how often the:

void __irq timer4Int(void) { }


Will be executed each second? Ie how many times will the above function be called each second?

Presumably this might depend on my clock speed?

This is how my timer4 interrupt is setup:



Code:
void installTimer4( void )
{
double pclk;

	// Calculate timer frequencies etc..
	pclk = (double)GpPClkGet();
	pclk /= 2;						// clock divider 1/16
	pclk /= 0+1;					// prescaler 256
	pclk /= INT_RATE;

	_pclk = (int)pclk;

	// Install timer4 interrupt..

	disable_IRQ();

	swi_install_irq(14,timer4Int);

	*tcntb4 = _pclk;								// timer4 counter
	*tcon = (*tcon & 0x0fffff) | 0x200000;			// manually update timer4 counter
	*tcfg0 |= 0x0000;
	*tcfg1 = (*tcfg1 & 0x0ffff) | 0x00000;			// configure timer4, clock divider 1/2
	*tcon = (*tcon & 0x0fffff) | 0x100000;			// start timer4

	enable_IRQ();
}

RELEVANT INFO:
(inside gpmain)
SetCpuSpeed(166);
#define INT_RATE 100000.0f
 
Squidge posted on Aug 16 2006 at 01:42 PM said:
It depends on the prescaler & clock speed. Check the magic eyes PDF for the algorithm.

magic eyes PDF ?
 
Last edited by a moderator:
Err... Squidge, this is a GP32 thread :D

Assuming that PCLK is MCLK/2, ie. 83MHz, then your pclk variable will be 83000000/2/100000 = 415.

You haven't said what the prior value of TCFG0 is, so we don't know what the prescaler will be... I'll assume it's 0, so Prescaler1 won't have any effect on Timer 4. You've set MUX 4 to 0000, so the timer input to Timer 4 will be PCLK/2, = 41.5MHz.

So, all up, the output frequency will be 41.5MHz / 415 = 100,000 Interrupts per second. Man, that's huge! I hope you're not going to be doing very much in the interrupt routine :D

Of course, if Prescaler1 is not 0 (check out TCFG0), then the interrupt frequency will be less.

By the way, I'm pretty sure you need to set the Timer 4 Auto Reload bit if you want periodic interrupts (rather than just a one-shot). To do this, set bit 22 of TCON both in the manual update instruction and the timer start instruction:
Code:
	*tcntb4 = _pclk;								// timer4 counter
	*tcon = (*tcon & 0x0fffff) | 0x600000;			// manually update timer4 counter and set auto reload bit
	*tcfg0 |= 0x0000;
	*tcfg1 = (*tcfg1 & 0x0ffff) | 0x00000;			// configure timer4, clock divider 1/2
	*tcon = (*tcon & 0x0fffff) | 0x500000;			// start timer4, leaving auto reload bit set
All this information came from chapter 10 of the S3C2400 user manual, which can be got from lots of places around the web. Mr_spiv's site has it, for example (check the GP32 Downloads section, near the bottom, for "um_s3c2400x_rev1.1.pdf").
 
Code:
// timers

volatile long* tcfg0  = (long*)0x15100000;		// config the two 8 bit prescalers
volatile long* tcfg1  = (long*)0x15100004;		// config
volatile long* tcon   = (long*)0x15100008;		// control

volatile long* tcntb0 = (long*)0x1510000c;		// count
volatile long* tcmpb0 = (long*)0x15100010;		// compare
volatile long* tcnto0 = (long*)0x15100014;		// timer count observation

volatile long* tcntb1 = (long*)0x15100018;
volatile long* tcmpb1 = (long*)0x1510001c;
volatile long* tcnto1 = (long*)0x15100020;

volatile long* tcntb2 = (long*)0x15100024;
volatile long* tcmpb2 = (long*)0x15100028;
volatile long* tcnto2 = (long*)0x1510002c;

volatile long* tcntb3 = (long*)0x15100030;
volatile long* tcmpb3 = (long*)0x15100034;
volatile long* tcnto3 = (long*)0x15100038;

volatile long* tcntb4 = (long*)0x1510003c;
volatile long* tcnto4 = (long*)0x15100040;
Thanks very much for your posts guys very helpful. Hopefully I can work my problem out using your post and this code.

Actually using the GP32 as a signal generator for research purposes. I've kind of fallen for it a bit, I think I might buy one and start contributing to the community if I can!
 
Back
Top