HCS12 + ECT

Started by M.B. September 2, 2003
Where I can find any sample code for simple use ECT ?
I have to count short time, but I don't know how use this timer (in
interrupt).

regards
Mariusz




Here is an example of timer in compare mode and modulus down counter
mode. The difference is: In compare mode compare register should be
load by the hand in every interrupt, in MDC mode all registers reload
automaticaly.

// Bus Clock = 24 Mhz // This is ports defines for HCS12 DG128 Part (described in Device
User Guide of your chip)

#define TIOS ( *(unsigned char *) 0x40 ) #define TCNT ( *(unsigned int *) 0x44 ) #define TSCR1 ( *(unsigned char *) 0x46 ) #define TCTL3 ( *(unsigned char *) 0x4A ) #define TCTL4 ( *(unsigned char *) 0x4B ) #define TIE ( *(unsigned char *) 0x4C ) #define TSCR2 ( *(unsigned char *) 0x4D ) #define TFLG1 ( *(unsigned char *) 0x4E ) #define TFLG2 ( *(unsigned char *) 0x4F ) #define TC0 ( *(unsigned int *) 0x50 )

#define MCCTL ( *(unsigned char *) 0x66 ) #define MCFLG ( *(unsigned char *) 0x67 ) #define MCCNT ( *(unsigned int *) 0x76 )

#define TC0_INT 0x6E #define MDC_INT 0x4A

#define T1000_HZ 0x05DB

//------- Here is example of Timer in compare mode (ETC 0) ---------- void Timer_Init( void ) { TIOS = 0x1; // T0 is used TIE = 0x1; // Enable Interrupt from T0 TSCR2 = 0x4; // Prescaler = 16 TCTL3 = 0x0; TCTL4 = 0x0;

TC0 = T1000_HZ;

TSCR1 = 0x80; //Timer enable

} interrupt [ TC0_INT ] void TimerCh0_Int( void ) //1000 Hz {

TC0 += T1000_HZ; //increment timer register for next compare TFLG1 = 0x1; //Clear interrupt flag }
//------- And example of MDC (Timer in modulus down counter mode)
----------
#define T1000_HZ 0x5DC0

void MDC_Init( void ) {

//1ms imterrupt

MCCTL = 0x80 | 0x40 // Interrupt Enable, Modulus Mode, PRSC =
0 MCCTL |= 0x4; // MDC enable MCCNT = T1000_HZ; // 0xFFFF - 3000

}
interrupt [ MDC_INT ] void MDC_Int( void ) { MCFLG |= 0x80; //Clear interrupt flag

} Dont forget do CLI instruction for global interrupt enable!

WBR, lenux

--- In , "M.B." <manekb@p...> wrote: > Where I can find any sample code for simple use ECT ?


> I have to count short time, but I don't know how use this timer (in


> interrupt).


>


> regards


> Mariusz




Great thanks

--- In , "lenux22" <lenux22@y...> wrote:
> Here is an example of timer in compare mode and modulus down
counter
> mode.
...