cancel
Showing results for 
Search instead for 
Did you mean: 

16-Bit Timer on ST7F2521

tech11
Associate
Posted on March 07, 2006 at 07:22

16-Bit Timer on ST7F2521

1 REPLY 1
tech11
Associate
Posted on March 07, 2006 at 07:22

Hi,

I'm a newbe in ST7F2521 programming and I've a lot of problems using the 16-Bit timer. I've to measure the time between 2 pulses on 2 different pin (2 inputs of timerA: PF5 and PF6)

If i set the TACR1 register with 0xA0 value (enabling input capture and timer overflow interrupt) the m_woNamurTime at the and will contain always 0x0000, otherwise if i set the TACR1 = 0x80 (enabling only the Input capture interrupt) everything seems to work fine accept that I've no way to measure time bigger than the 16-bit timer.

Prescaler solution is not acceptable because i need a timer able to measure till about 20 secs.

Below there is my code; anybody has an idea?

/***************************************************/

void (* const _vectab[])() = {

NULL,

NULL,

NULL,

NULL,

NULL,

measureNamur,

NULL,

NULL,

displayModuleBusyIRQ,

displayKeyboardIRQ,

NULL,

NULL,

NULL,

NULL,

NULL,

_stext,

};

/***************************************************/

volatile WORD m_woNamurTime = 0x0000;

volatile BYTE m_byNamurIndex = 0x00;

volatile BYTE m_byTimerOverflow = 0x00;

/***************************************************/

void main(){

PFDDR = 0x00;

PFOR = 0x00;

PFDR = 0x00;

DisableInterrupts();

//External interrupt control register

ISPR0 = 0b11111100;

ISPR1 = 0b11111100;

ISPR2 = 0b11111100;

ISPR3 = 0b11111100;

EICR = 0x40;

TACR1 = 0xA0; //interrupt generated on PF5 e PF6

TACR2 = 0x00;

// Get Namur's time

m_byNamurIndex = 0x00;

m_woNamurTime = 0x0000;

m_byTimerOverflow = 0x00;

EnableInterrupts();

TACR = 0x0000;

TASR = 0x00;

while (m_byNamurIndex < 0x02){ };

TASR = 0x04;

}

/***************************************************/

@interrupt

void measureNamur()

{

BYTE byTemp = 0x00;

byTemp = TASR;

//First Sensor

if((byTemp & 0x80) && (m_byNamurIndex == 0x00))

{

m_byTimerOverflow = 0x00;

TAIC1HR = 0x00;

TAIC1LR = 0x00;

TAIC2HR = 0x00;

TAIC2LR = 0x00;

TACR = 0x0000;

TASR = 0x00;

m_byNamurIndex = 0x01;

}

//Second sensor

if((byTemp & 0x10) && (m_byNamurIndex == 0x01))

{

m_woNamurTime = (m_byTimerOverflow*256)+TAIC2HR;

TASR = 0x40;

TACR = 0x0000;

TAIC2HR = 0x00;

TAIC2LR = 0x00;

m_byNamurIndex = 0x02;

}

//Timer overflow

if((byTemp & 0x20) && (m_byNamurIndex == 0x01))

{

m_byTimerOverflow++;

}

TACR = 0x0000;

}

:-[ :-[ :-[