EmbeddedRelated.com
Forums

68hc12 TOVF interrupt problems ICC12

Started by hendersonmarv March 25, 2009
I'm trying to get the timer overflow interrupt working on the
hc12dp256b but so far I haven't had any luck.

The overflow interrupt is never generated in my program(used a breakpiont in isr) and I can't find the logic error in my code.

Here is my work environment:
CHIP: hc12dp256
COMPILER: ICC12
DEBUGGER: NOICE

Here's the code that doesn't work

----------------------------------
#include
#include

#pragma interrup_handler TOVF_ISR() (isrs installed in vector table file)

int count

void main(void)
{
//setup
TFLG2|=0x80; //Clear interrupt flag
TSCR2 =0x8D; //Set timer frequency(250kHz), Enable TOVF int
TSCR1|=0x90; //enable timer and fast clear TOC7

asm("cli");

count=0;
while(count<3){
if(i%2000==0) printf("count: %d\n",count);
i++;
}

printf("count reached three\n");
}

void TOVF_ISR()
{
asm("cli"); //reenable interrupts
count++;
TFLG2|=0X80;
}
----------------------------------

Thanks to anyone who can help me out

A couple of things to check:

I don't think that the TCRE bit in TSCR2 should be set since you are not
using the TC7 counter.
Since TC7 resets to zero I'm not sure what will happen. Probably the TCNT
counter will never overflow because
it's being reset by the TC7 compare.

For reference you don't need to use TFLG2 |= 0x80. TFLG2 = 0x80 will work
fine.
Also interrupt handlers usually reenable interrupts automatically using an
RTI instruction.
I'm not familiar with ICC12 so this may not be true.
I know for IAR compilers the function is prefaced by the keyword
__interrupt to indicate the function should use RTI instead of RTS.
However when your interrupt handler is used somewhere the RTI instruction
must be called when it is finished.
You should never need to do an asm("cli") instruction in an interrupt
handler.
Lastly I don't use the fast clear bit TFFCA in TSCR1. Since you reset it
with TFLG2 = 0x80 it's not needed. Plus you not accessing TC7 anyway.
If ICC12 has a mixed listing output, see what instructions are generated.

Good luck.

Arlin L. Pierce
Principal Software Engineer
Raytheon Company / Rancho Innovations

"hendersonmarv"
Sent by: 6...
03/25/2009 07:33 AM
Please respond to
6...
To
6...
cc

Subject
[68HC12] 68hc12 TOVF interrupt problems ICC12

I'm trying to get the timer overflow interrupt working on the
hc12dp256b but so far I haven't had any luck.

The overflow interrupt is never generated in my program(used a breakpiont
in isr) and I can't find the logic error in my code.

Here is my work environment:
CHIP: hc12dp256
COMPILER: ICC12
DEBUGGER: NOICE

Here's the code that doesn't work

----------------------
#include
#include

#pragma interrup_handler TOVF_ISR() (isrs installed in vector table file)

int count

void main(void)
{
//setup
TFLG2|=0x80; //Clear interrupt flag
TSCR2 =0x8D; //Set timer frequency(250kHz), Enable TOVF int
TSCR1|=0x90; //enable timer and fast clear TOC7

asm("cli");

count=0;
while(count<3){
if(i%2000==0) printf("count: %d\n",count);
i++;
}

printf("count reached three\n");
}

void TOVF_ISR()
{
asm("cli"); //reenable interrupts
count++;
TFLG2|=0X80;
}
----------------------

Thanks to anyone who can help me out



I am not familiar with ICC12, but for a basic try:

1) Don't enable TCRE in TSCR1

2) Remove the cli in the interrupt routine.

3) Clear the interrupt flag with TFLG2=0x80.
----- Original Message -----
From: "hendersonmarv"
To: <6...>
Sent: Wednesday, March 25, 2009 9:31 AM
Subject: [68HC12] 68hc12 TOVF interrupt problems ICC12
I'm trying to get the timer overflow interrupt working on the
hc12dp256b but so far I haven't had any luck.

The overflow interrupt is never generated in my program(used a breakpiont in
isr) and I can't find the logic error in my code.

Here is my work environment:
CHIP: hc12dp256
COMPILER: ICC12
DEBUGGER: NOICE

Here's the code that doesn't work

----------------------------------
#include
#include

#pragma interrup_handler TOVF_ISR() (isrs installed in vector table file)

int count

void main(void)
{
//setup
TFLG2|=0x80; //Clear interrupt flag
TSCR2 =0x8D; //Set timer frequency(250kHz), Enable TOVF int
TSCR1|=0x90; //enable timer and fast clear TOC7

asm("cli");

count=0;
while(count<3){
if(i%2000==0) printf("count: %d\n",count);
i++;
}

printf("count reached three\n");
}

void TOVF_ISR()
{
asm("cli"); //reenable interrupts
count++;
TFLG2|=0X80;
}
----------------------------------

Thanks to anyone who can help me out

Little addition

> void TOVF_ISR()
> {
> asm("cli"); //reenable interrupts
> count++;
> TFLG2|=0X80;
> }

What happens ^^ here is

1) overlflow happens, overflow flag gets set
2) CPU stacks registers, sets I status bit, fetches TOVF vector and jumps to
ISR
3) asm("cli") is executed
4) single CPU instruction after cli is executed
5) since interrupt flag and interrupt mask are set, I status bit is cleared,
go back to step 2

On every overflow event, your ISR would execute more than once... Smart
code.

Edward
----- Original Message -----
From: "hendersonmarv"
To: <6...>
Sent: Wednesday, March 25, 2009 4:31 PM
Subject: [68HC12] 68hc12 TOVF interrupt problems ICC12
> I'm trying to get the timer overflow interrupt working on the
> hc12dp256b but so far I haven't had any luck.
>
> The overflow interrupt is never generated in my program(used a breakpiont
> in isr) and I can't find the logic error in my code.
>
> Here is my work environment:
> CHIP: hc12dp256
> COMPILER: ICC12
> DEBUGGER: NOICE
>
> Here's the code that doesn't work
>
> ----------------------------------
> #include
> #include #pragma interrup_handler TOVF_ISR() (isrs installed in vector table file)
>
> int count
>
> void main(void)
> {
> //setup
> TFLG2|=0x80; //Clear interrupt flag
> TSCR2 =0x8D; //Set timer frequency(250kHz), Enable TOVF int
> TSCR1|=0x90; //enable timer and fast clear TOC7
>
> asm("cli");
>
> count=0;
> while(count<3){
> if(i%2000==0) printf("count: %d\n",count);
> i++;
> }
>
> printf("count reached three\n");
> }
>
> void TOVF_ISR()
> {
> asm("cli"); //reenable interrupts
> count++;
> TFLG2|=0X80;
> }
> ----------------------------------
>
> Thanks to anyone who can help me out
>
>
Thanks a ton, the fast clear and TCRE were for an output compare I'm adding to this to generate a 1Hz interrupt on an output compare
channel. So I guess I just have to wait until the overflows happen
then set up the output compare.

For anybody who has the same problem I'm going to post the changes to the thread.

1. asm("cli") is not needed in isrs for ICC12

2. New Code changes
--------------------------------
//setup changes
TFLG2 = 0X80; //Clear interrupt flag
TSCR2 = 0X85; //Set timer frequency:250KhZ ,
//and ENABLE TOVF int
TSCR1 = 0X80; //enable timer
asm("cli");

ISR CHANGES
void TOVF_ISR()
{
count++;
TFLG2 =0X80;
}

--- In 6..., Arlin L Pierce wrote:
>
> A couple of things to check:
>
> I don't think that the TCRE bit in TSCR2 should be set since you are not
> using the TC7 counter.
> Since TC7 resets to zero I'm not sure what will happen. Probably the TCNT
> counter will never overflow because
> it's being reset by the TC7 compare.
>
> For reference you don't need to use TFLG2 |= 0x80. TFLG2 = 0x80 will work
> fine.
> Also interrupt handlers usually reenable interrupts automatically using an
> RTI instruction.
> I'm not familiar with ICC12 so this may not be true.
> I know for IAR compilers the function is prefaced by the keyword
> __interrupt to indicate the function should use RTI instead of RTS.
> However when your interrupt handler is used somewhere the RTI instruction
> must be called when it is finished.
> You should never need to do an asm("cli") instruction in an interrupt
> handler.
> Lastly I don't use the fast clear bit TFFCA in TSCR1. Since you reset it
> with TFLG2 = 0x80 it's not needed. Plus you not accessing TC7 anyway.
> If ICC12 has a mixed listing output, see what instructions are generated.
>
> Good luck.
>
> Arlin L. Pierce
> Principal Software Engineer
> Raytheon Company / Rancho Innovations
> "hendersonmarv"
> Sent by: 6...
> 03/25/2009 07:33 AM
> Please respond to
> 6...
> To
> 6...
> cc
>
> Subject
> [68HC12] 68hc12 TOVF interrupt problems ICC12
>
> I'm trying to get the timer overflow interrupt working on the
> hc12dp256b but so far I haven't had any luck.
>
> The overflow interrupt is never generated in my program(used a breakpiont
> in isr) and I can't find the logic error in my code.
>
> Here is my work environment:
> CHIP: hc12dp256
> COMPILER: ICC12
> DEBUGGER: NOICE
>
> Here's the code that doesn't work
>
> ----------------------
> #include
> #include #pragma interrup_handler TOVF_ISR() (isrs installed in vector table file)
>
> int count
>
> void main(void)
> {
> //setup
> TFLG2|=0x80; //Clear interrupt flag
> TSCR2 =0x8D; //Set timer frequency(250kHz), Enable TOVF int
> TSCR1|=0x90; //enable timer and fast clear TOC7
>
> asm("cli");
>
> count=0;
> while(count<3){
> if(i%2000==0) printf("count: %d\n",count);
> i++;
> }
>
> printf("count reached three\n");
> }
>
> void TOVF_ISR()
> {
> asm("cli"); //reenable interrupts
> count++;
> TFLG2|=0X80;
> }
> ----------------------
>
> Thanks to anyone who can help me out
>
>