Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | 68HC12 | Sorry for newbe question. Can't get timer interrupt to work at all... :-(


Advertise Here

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

Sorry for newbe question. Can't get timer interrupt to work at all... :-( - anda...@hotmail.com - Sep 26 8:58:37 2008

Hello all,
I use the HCS12 T-board with the mc9s12dp512. I also use the trial version of ICC12 compiler and the TWINpeeks monitor.
My purpose of the program is to toggle the T-board LED bar, so I can see when the timer interrupt works.
#include

void SetTimer(unsigned int Ticks)
{
asm("sei");
TSCR1 = 0x80; //Set TEN = 1 (enable)
TSCR2 = 0x04; //Timer Prescaler select = 0x0100 => 2^4 = 16MHz
TIOS = 0x04; //Set as output
TIE = 0x04; //Timer interrupt enable
TCTL2 &= ~(0x20 | 0x10);
// Clear Timer Flag
TFLG1 = 0x81;
asm("cli");
TC2 = Ticks - 1;
}

// ISR for timer 0 this is the same for timer 7
#pragma interrupt_handler Timer0
void Timer2(void)
{
PORTB ^= 0x00; // Pulse LED
// Clear timer interrupt flag
TFLG1 = 0x01;
}

void main(void)
{
DDRB = 0xFF;
PORTB = 0xFF;

*((unsigned char *)0x3FE2) = 0x06; // JMP opcode
*((void (**)(void))0x3FE3) = Timer2;

SetTimer(200);

while(1)
{
//Toggle LED bar
}
}

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )


Re: Sorry for newbe question. Can't get timer interrupt to work at all... :-( - Edward Karpicz - Sep 26 9:39:10 2008

Many issues with your code. interrupt_handler pragma for Timer0 function,
while ISR is called Timer2. In SetTimer you enable interrupt for TC2, clear
flags of TC0 and TC7, while Timer2 ISR is clearing TC0 flag. Also make sure
$3FE2 is right interrupt jump table entry for TC2.

Edward

----- Original Message -----
From:
To: <6...@yahoogroups.com>
Sent: Friday, September 26, 2008 15:58
Subject: [68HC12] Sorry for newbe question. Can't get timer interrupt to
work at all... :-(
> Hello all,
> I use the HCS12 T-board with the mc9s12dp512. I also use the trial version
> of ICC12 compiler and the TWINpeeks monitor.
> My purpose of the program is to toggle the T-board LED bar, so I can see
> when the timer interrupt works.
> #include void SetTimer(unsigned int Ticks)
> {
> asm("sei");
> TSCR1 = 0x80; //Set TEN = 1 (enable)
> TSCR2 = 0x04; //Timer Prescaler select = 0x0100 => 2^4 = 16MHz
> TIOS = 0x04; //Set as output
> TIE = 0x04; //Timer interrupt enable
> TCTL2 &= ~(0x20 | 0x10);
> // Clear Timer Flag
> TFLG1 = 0x81;
> asm("cli");
> TC2 = Ticks - 1;
> }
>
> // ISR for timer 0 this is the same for timer 7
> #pragma interrupt_handler Timer0
> void Timer2(void)
> {
> PORTB ^= 0x00; // Pulse LED
> // Clear timer interrupt flag
> TFLG1 = 0x01;
> }
>
> void main(void)
> {
> DDRB = 0xFF;
> PORTB = 0xFF;
>
> *((unsigned char *)0x3FE2) = 0x06; // JMP opcode
> *((void (**)(void))0x3FE3) = Timer2;
>
> SetTimer(200);
>
> while(1)
> {
> //Toggle LED bar
> }
> }
>
> ------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Sorry for newbe question. Can't get timer interrupt to work at all... :-( - anda...@hotmail.com - Sep 29 10:18:02 2008

Thanks for the update info, but can't still get it to work.
I think that the fault are in the following code lines:

*((unsigned char *)0x3FE2) = 0x06; // JMP opcode
*((void (**)(void))0x3FE3) = Timer2;

The manual I got with the T-board , it says 0x3FE2 for the mc9s12dp512 timer. But it also seems like some examples in the manual also are for the mc9s12dp256. :-/

So after done the small changes in the code, it's like following:
#include

void SetTimer(unsigned int Ticks)
{
asm("sei");
TSCR1 = 0x80; //Set TEN = 1 (enable)
TSCR2 = 0x04; //Timer Prescaler select = 0x0100 => 2^4 = 16MHz
TIOS = 0x04; //Set as output
TIE = 0x04; //Timer interrupt enable
TCTL2 &= ~(0x20 | 0x10);
// Clear Timer Flag
TFLG1 = 0x04;
asm("cli");
TC2 = Ticks - 1;
}

// ISR for timer 0 this is the same for timer 7
#pragma interrupt_handler Timer2
void Timer2(void)
{
PORTB ^= 0x00; // Pulse LED
// Clear timer interrupt flag
TFLG1 = 0x04;
}

void main(void)
{
DDRB = 0xFF;
PORTB = 0xFF;

*((unsigned char *)0x3FE2) = 0x06; // JMP opcode
*((void (**)(void))0x3FE3) = Timer2;

SetTimer(200);

while(1)
{
//Toggle LED bar
}
}

Thanks
/Andreas

Hello all,
>I use the HCS12 T-board with the mc9s12dp512. I also use the trial version of ICC12 compiler and the TWINpeeks monitor.
>My purpose of the program is to toggle the T-board LED bar, so I can see when the timer interrupt works.
>#include
>
>void SetTimer(unsigned int Ticks)
>{
> asm("sei");
> TSCR1 = 0x80; //Set TEN = 1 (enable)
> TSCR2 = 0x04; //Timer Prescaler select = 0x0100 => 2^4 = 16MHz
> TIOS = 0x04; //Set as output
> TIE = 0x04; //Timer interrupt enable
> TCTL2 &= ~(0x20 | 0x10);
> // Clear Timer Flag
> TFLG1 = 0x81;
> asm("cli");
> TC2 = Ticks - 1;
>}
>
>// ISR for timer 0 this is the same for timer 7
>#pragma interrupt_handler Timer0
>void Timer2(void)
>{
> PORTB ^= 0x00; // Pulse LED
> // Clear timer interrupt flag
> TFLG1 = 0x01;
>}
>
>void main(void)
>{
> DDRB = 0xFF;
> PORTB = 0xFF;
>
> *((unsigned char *)0x3FE2) = 0x06; // JMP opcode
> *((void (**)(void))0x3FE3) = Timer2;
>
> SetTimer(200);
>
> while(1)
> {
> //Toggle LED bar
> }
>}
>
>------------------------------------

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )

Re: Re: Sorry for newbe question. Can't get timer interrupt to work at all... :-( - David Simpson - Sep 30 0:50:44 2008

a...@hotmail.com wrote:
>
> // ISR for timer 0 this is the same for timer 7
> #pragma interrupt_handler Timer2
> void Timer2(void)
> {
> PORTB ^= 0x00; // Pulse LED

Maybe should be PORTB ^= 0xff; rather than 0x00, as exclusive or with 0
will not toggle any bits.

David
------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )