EmbeddedRelated.com
Forums
The 2025 Embedded Online Conference

68hc12 TOVF interrupt problems ICC12

Started by Marcipicus March 25, 2009
I'm trying to get the timer overflow interrupt working on the hc12 dp256b
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 <hcs12dp256.h>
#include <stdio.h>

#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


"Marcipicus" wrote:

>I'm trying to get the timer overflow interrupt working on the hc12 dp256b >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 <hcs12dp256.h> >#include <stdio.h> > >#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
why do you set TCRE?
> 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"); >}
not what you asked, but what happens when main() returns?
>void TOVF_ISR() >{ > asm("cli"); //reenable interrupts
why? RTI will do so, and your ISR doesn't run very long.
> count++; > TFLG2|=0X80; >}
Oliver -- Oliver Betz, Munich despammed.com might be broken, use Reply-To:
This is a multi-part message in MIME format.

------=_NextPart_000_0195_01C9ADFE.4134FD60
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


"Marcipicus" <msammon@connect.carleton.ca> wrote in message =
news:ffWdnayE0-NRq1fUnZ2dnUVZ_gOWnZ2d@giganews.com...
> I'm trying to get the timer overflow interrupt working on the hc12 =
dp256b
> but so far I haven't had any luck. >=20 > 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. >=20 > Here is my work environment: > CHIP: hc12dp256 > COMPILER: ICC12 > DEBUGGER: NOICE >=20 > Here's the code that doesn't work >=20 > =
-------------------------------------------------------------------------= -----
> #include <hcs12dp256.h> > #include <stdio.h> >=20 > #pragma interrup_handler TOVF_ISR() (isrs installed in vector table =
file)
>=20 > int count >=20 > void main(void) > { > //setup > TFLG2|=3D0x80; //Clear interrupt flag
You should only clear the flag by TFLG2 =3D 0x80 else you will clear any = other unserviced flags as well.=20
> TSCR2 =3D0x8D; //Set timer frequency(250kHz), Enable TOVF int > TSCR1|=3D0x90; //enable timer and fast clear TOC7 >=20 > asm("cli"); >=20 > count=3D0; > while(count<3){ > if(i%2000=3D=3D0) printf("count: %d\n",count); > i++; > } >=20 > printf("count reached three\n");
Your returning from Main!!!!!!!!!!
> } >=20 > void TOVF_ISR() > { > asm("cli"); //reenable interrupts
This is not needed, RTI will restore it
> count++; > TFLG2|=3D0X80;
Same as mentioned above, clear by TFLG2 =3D 0x80. However, you have = setup to auto clear (TSCR1 |=3D 0x90) which simply requires an access to = the TCNT registers to auto clear.
> } > =
-------------------------------------------------------------------------= ---
>=20 > Thanks to anyone who can help me out >=20 >
------=_NextPart_000_0195_01C9ADFE.4134FD60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 6.00.6000.16809" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY> <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV> <DIV><FONT face=3DArial size=3D2>"Marcipicus" &lt;</FONT><A=20 href=3D"mailto:msammon@connect.carleton.ca"><FONT face=3DArial=20 size=3D2>msammon@connect.carleton.ca</FONT></A><FONT face=3DArial = size=3D2>&gt; wrote=20 in message </FONT><A=20 href=3D"news:ffWdnayE0-NRq1fUnZ2dnUVZ_gOWnZ2d@giganews.com"><FONT = face=3DArial=20 size=3D2>news:ffWdnayE0-NRq1fUnZ2dnUVZ_gOWnZ2d@giganews.com</FONT></A><FO= NT=20 face=3DArial size=3D2>...</FONT></DIV> <DIV><FONT face=3DArial size=3D2>&gt; I'm trying to get the timer = overflow interrupt=20 working on the hc12 dp256b<BR>&gt; but so far I haven't had any = luck.<BR>&gt;=20 <BR>&gt; The overflow interrupt is never generated in my program(used a=20 breakpiont<BR>&gt; in isr) and I can't find the logic error in my = code.<BR>&gt;=20 <BR>&gt; Here is my work environment:<BR>&gt; = CHIP:&nbsp;&nbsp;&nbsp;&nbsp;=20 hc12dp256<BR>&gt; COMPILER: ICC12<BR>&gt; DEBUGGER: NOICE<BR>&gt; = <BR>&gt;=20 Here's the code that doesn't work<BR>&gt; <BR>&gt;=20 -------------------------------------------------------------------------= -----<BR>&gt;=20 #include &lt;hcs12dp256.h&gt;<BR>&gt; #include &lt;stdio.h&gt;<BR>&gt; = <BR>&gt;=20 #pragma interrup_handler TOVF_ISR() (isrs installed in vector table=20 file)<BR>&gt; <BR>&gt; int count<BR>&gt; <BR>&gt; void = main(void)<BR>&gt;=20 {<BR>&gt;&nbsp; //setup<BR>&gt;&nbsp;=20 TFLG2|=3D0x80;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Clear interrupt=20 flag</FONT></DIV> <DIV><FONT face=3DArial color=3D#ff0000 size=3D2></FONT>&nbsp;</DIV> <DIV><FONT face=3DArial color=3D#ff0000 size=3D2>You should only clear = the=20 flag&nbsp;by TFLG2 =3D 0x80 else you will clear any other unserviced = flags as=20 well.&nbsp;</FONT></DIV> <DIV><BR><FONT face=3DArial size=3D2>&gt;&nbsp; TSCR2=20 =3D0x8D;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Set timer = frequency(250kHz), Enable=20 TOVF int<BR>&gt;&nbsp; = TSCR1|=3D0x90;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //enable=20 timer and fast clear TOC7<BR>&gt; <BR>&gt;&nbsp;=20 asm("cli");<BR>&gt;&nbsp;<BR>&gt;&nbsp; count=3D0;<BR>&gt;&nbsp;=20 while(count&lt;3){<BR>&gt;&nbsp;&nbsp;&nbsp; if(i%2000=3D=3D0) = printf("count:=20 %d\n",count);<BR>&gt;&nbsp;&nbsp;&nbsp; i++;<BR>&gt;&nbsp; }<BR>&gt;=20 <BR>&gt;&nbsp; printf("count reached three\n");</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV> <DIV><FONT face=3DArial size=3D2><FONT color=3D#ff0000>Your returning = from=20 Main!!!!!!!!!!</FONT></DIV> <DIV><BR>&gt; }<BR>&gt; <BR>&gt; void TOVF_ISR()<BR>&gt; {<BR>&gt;&nbsp; = asm("cli");&nbsp;&nbsp;&nbsp; //reenable interrupts</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV> <DIV><FONT face=3DArial size=3D2><FONT color=3D#ff0000>This is not = needed, RTI will=20 restore it</FONT></DIV> <DIV><BR>&gt;&nbsp; count++;<BR>&gt;&nbsp; TFLG2|=3D0X80;</DIV> <DIV>&nbsp;</DIV> <DIV><FONT color=3D#ff0000>Same as mentioned above, clear by TFLG2 =3D = 0x80.=20 However, you have setup to auto clear (TSCR1 |=3D 0x90) which simply = requires an=20 access to the TCNT registers to auto clear.</FONT></DIV> <DIV><FONT color=3D#ff0000></FONT><BR>&gt; }<BR>&gt;=20 -------------------------------------------------------------------------= ---<BR>&gt;=20 <BR>&gt; Thanks to anyone who can help me out<BR>&gt;=20 <BR>&gt;</FONT></DIV></BODY></HTML> ------=_NextPart_000_0195_01C9ADFE.4134FD60--
PhilW wrote:
> > Part 1.1 Type: Plain Text (text/plain) > Encoding: quoted-printable
Please do not use html in Usenet. This is a pure text medium. -- [mail]: Chuck F (cbfalconer at maineline dot net) [page]: <http://cbfalconer.home.att.net> Try the download section.

The 2025 Embedded Online Conference