Yahoo Groups archive

68300

Index last updated: 2026-04-29 00:01 UTC

Message

TPU Problem

2003-03-31 by Robert Yablonski

Hello Group,

We have a TPU problem.  When using the PTA function, in Mode 3 we sometimes 
get a reading that is 1/2 the actual period Plus 1035+-1.  The hardware 
signals look good.  Increasing the period count reduces the number of times 
we see the error but does not stop the error.

The code looks as follows:

volatile UL pta;
volatile B cpta;
UL ptaRead(UW pin_index0)
	{
	UL ptaLocal;
	if(pin_index0 != 8)
		return 0;
	
	if(cpta != 0)
		return 0xffffffff;

	ptaLocal = pta;

	/* enable the interrupt to measure again */
	cpta = 2;
	CIER |= (W)(~CISR_MASK(pin_index0));

	return ptaLocal;
	}

/* written in assembly because it runs often- optimizing it is good */
asm void tpuPin8(void);
asm void tpuPin8(void)
	{
	/* no registers used, so no need to save & restore them */
	/* count reads */
	sub.b		#1,cpta ;
	bgt.s		tp8_no_disable
	/* clear the flag */
	clr.b		cpta
	/* clear the interrupt enable bit in CIER */
	andi.w	#(~(1 << 8)),(Y + 0xffe0a );
tp8_no_disable:
	/* clear the interrupt status bit in CISR */
	andi.w	#(~(1 << 8)),(Y + 0xffe20 );
	/* read period with a coherent long read, and put it in the array */
	move.l	(Y+0xfff00+(8<<4)+8),pta ;
	/* clear the pin's high word */
	clr.w	(Y+0xfff00+(8<<4)+8) ;
	/* no registers used, so no need to save & restore them */
	rte
	}

/* initialize a TPU pin to count using TCR1, the faster, internal TCR. */
void ptaInit(UW pin_index0)
	{
	W tmp;

	/* turn off pin  by setting the priority to zero */
	tmp = CPR(pin_index0);
	tmp &= ((W)(~(3 << ((pin_index0 & 7)<<1))));	/* clear the priority */
	CPR(pin_index0) = tmp;

	/* disable the interrupt */
	CIER &= CISR_MASK(pin_index0);
	/* clear the interrupt status bit */
	CISR &= CISR_MASK(pin_index0);

	/* first, set up the first pin's function code; only write it once */
	tmp = CFSR(pin_index0);
	tmp &= ((W)~(0x0F << (4*(pin_index0 & 3))));	/* clear the code */
	tmp |= ((W)(PTA_FN_CODE << (4*(pin_index0 & 3)))); /* time accumulate */
	CFSR(pin_index0) = tmp;

	PARM16(pin_index0, 0x00) = 0x07;	/* measure period with TCR1 */

	/* measure a whole period from a rising edge */
	tmp = HSQR(pin_index0);
	tmp &= ((W)~(3 << (2*(pin_index0 & 7))));
	tmp |= ((W)(2 << (2*(pin_index0 & 7))));
	HSQR(pin_index0) = tmp;

	/* initialize MAX_COUNT & PERIOD COUNT */
	PARM16(pin_index0, 0x02) = 0x100;
	/* initialize LAST_TIME */
	PARM16(pin_index0, 0x04) = 0;
	/* initialize ACCUM */
	PARM16(pin_index0, 0x06) = 0;
	/* initialize HW */
	PARM16(pin_index0, 0x08) = 0;
	/* initialize LW */
	PARM16(pin_index0, 0x10) = 0;

	/* install or check the interrupt */
	irqVector((UB)(0x50+pin_index0), tpuPin8);	/* assure a vector */

	/* enable the interrupt */
	CIER |= (W)(~CISR_MASK(pin_index0));

	/* send the initialize fn */
	tmp = HSRR(pin_index0);
	tmp &= (W)(~(3 << ((pin_index0 & 7)<<1)));	/* clear the function code */
	tmp |= (W)(3 << ((pin_index0 & 7)<<1));	/* initialize channel */
	HSRR(pin_index0) = tmp;

	/* update pins to high priority */
	tmp = CPR(pin_index0);
	tmp &= ((W)(~(3 << ((pin_index0 & 7)<<1))));	/* clear the priority */
	tmp |= ((W)(3 << ((pin_index0 & 7)<<1)));	/* set high priority- 3 */
	CPR(pin_index0) = tmp;
	
	ptaRead((UW)8);
	}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.