RE: TPU TCR overflow interrupt

"Jean-Christophe MATHAE" <[email protected]> Thu, 6 Jul 2006 10:40:05 +0200
Newsgroups gmane.comp.hardware.motorola.microcontrollers
Message-ID <[email protected]>
Hello Sinil,


We use a TPU channel configured with the Output Capture function.

Here is the C++ code, which defines the TPUCOUNTEROVERFLOW class as derived from a TPU class not described here, but this should be enough to give you an idea of how it works...


////////////////////////////////////////////////////////////////////////

WORD TPUCOUNTEROVERFLOW::m_wMSW1Timer32 = 0,	// incremented at half period
	 TPUCOUNTEROVERFLOW::m_wMSW2Timer32 = 0;	// incremented at end of period

#ifdef	_DEBUG
bool TPUCOUNTEROVERFLOW::m_bIsActivePresent = false;// 'true' if instanciation with interrupt enabled
#endif	_DEBUG

TPUCOUNTEROVERFLOW::TPUCOUNTEROVERFLOW (const int iChannel,
	const MODULE Module /*= A*/)
	:TPU (iChannel, Module)
{
}

/*	cFunction= TF_OC;
	cPriority= TP_LOW;
	cHSQ= 1;	All code is executed			OFFSET == $8000
	cHSR= 1;	Host-init pulse mode			REF_ADDR1 == $F8 (REF_TIME)
	cInterrupt= TRUE;							REF_TIME == 0
	cTBS= TO_TCR1;	capture and match TCR1
	cPAC= TE_FALL;	Low on match (at $8000)
	cPSC= TF_NONE;	Do not force any state
*/
const MPC555::TPU::INIT TPUCOUNTEROVERFLOW::ctiOCInit = {
	OC, LOW, 1, 1, true, TCR1_OUT, FALL, NOFORCE,
	{0, 0x8000, 0x00F8, 0x0000, 0x0000, 0x0000}	// Parameter RAM
};

void
TPUCOUNTEROVERFLOW::Init (const bool bInterrupt /*= true*/)
{
	INIT tiOC = ctiOCInit;
	tiOC.cHSQ= bInterrupt ? 1 : 3;
	tiOC.bInterrupt= bInterrupt;
	tiOC.awRAM [2]= (tiOC.awRAM [2] & 0x000F) | (m_iChannel << 4);
	TPU::Init (&tiOC);

#ifdef	_DEBUG
	if (bInterrupt)
		m_bIsActivePresent= true;
#endif	_DEBUG
}

DWORD
TPUCOUNTEROVERFLOW::GetCurrentTime() const
{
	ASSERT (not m_bitInterruptEnable.Test());

	SetHostSequence (3);
	Restart (1);
	WaitReady();

	return (GetTime (MPC555::InputW (((DWORD) &m_awRAM & 0xFFFF00) | 0x0000EC)));
}

void
TPUCOUNTEROVERFLOW::Interrupt()
{
	ASSERT (m_bitInterruptEnable.Test());

	//AcknowledgeInt();	Done in Restart() !

	const WORD wTCR1 = ReadWord (5);
//static SPYARRAY<WORD, 0x100> spy;
//spy.Put (wTCR1);
	if (wTCR1 < 0x8000U)
	{
		m_wMSW1Timer32= m_wMSW2Timer32;
		WriteWord (0, ChannelControl (TCR1_OUT, FALL, NOFORCE));	// Reprogramme channel
	}
	else
	{
		m_wMSW2Timer32 ++;
		WriteWord (0, ChannelControl (TCR1_OUT, RISE, NOFORCE));	// Reprogramme channel
	}

	Restart (1);	// Restarts channel
}

////////////////////////////////////////////////////////////////////////

Hope this could help you.

Best regards.


Jean-Christophe MATHAE

CIRTEM
http://www.cirtem.com

bâtiment Pointe Bleue
20, voie l'Occitane
BP661
31319 LABEGE cedex
France


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Yahoo! Groups gets a make over. See the new email design.
http://us.click.yahoo.com/XISQkA/lOaOAA/yQLSAA/dN_tlB/TM
--------------------------------------------------------------------~-> 

-----------------------------------------------------------
To learn more about Freescale Microcontrollers, please visit
http://www.freescale.com/mcu


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/MPC500/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/