Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
Problem initialise timer for 1µs cycle - folg...@yahoo.com - May 1 7:56:51 2009
Hello,
I have a problem with using the Timer on a MC9S12DP512. I want to create 1µ second
cycles. Every µs I want to increment a variable, but I do not know how to initialise the
timer, so that I get a timer interrupt every µs.
I hope that someone can help me.
Best regards
Here is my function to initialise the timer:
--------------------------------------------
void Init_Timers(void)
{
TCTL2= 0;
// TCTL2_OL3= 0;
/*TCTL2_OM2= 0;
TCTL2_OL2= 0;
TCTL2_OM1= 0;
TCTL2_OL1= 0;
TCTL2_OM0= 0;
TCTL2_OL0= 0;*/
TIE&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // C3I= 0, C2I= 0, C1I= 0, C0I= 0
/*TIE_C2I= 0;
TIE_C1I= 0;
TIE_C0I= 0;*/
TTOV&= ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // TOV3= 0, TOV2= 0, TOV1= 0, TOV0= 0
/*TTOV_TOV2= 0;
TTOV_TOV1= 0;
TTOV_TOV0= 0;*/
//TTOV|= Bit6;
TSCR2&= ~(Bit3); // TCRE= 0
TIOS|= Bit5|Bit4|Bit3|Bit2|Bit1|Bit0; // IOS3= 1, IOS2= 1, IOS1= 1, IOS0= 1
/*TIOS_IOS2= 1;
TIOS_IOS1= 1;
TIOS_IOS0= 1;*/
//TIOS|= Bit6;
TSCR1|= Bit7; // TEN= 1
TSCR1&= ~(Bit6|Bit5); // TSWAI= 0, TSFRZ= 0
// TSCR1_TEN= 1;
// TSCR1_TSWAI= 0;
// TSCR1_TSFRZ= 0;
PWMCTL&= ~(Bit3|Bit2); // PSWAI= 0, PFRZ= 0
// PWMCTL_PSWAI= 0;
// PWMCTL_PFRZ= 0;
//TCTL2|= Bit4;
//TC6|= 0x8000;
PWMSDN= 0;
ICSYS= 0;
//MCCTL|= Bit6; // MODMC= 1
TSCR2|= 7; // PR2= 1, PR1= 1, PR0= 1
// TSCR2|= Bit2|Bit1;
// TSCR2_PR= 6;
InitTimer1();
}
and here is my Timer ISR:
-------------------------
@interrupt void _ISR_Timer1(void)
{
ISR_Timer1();
gTimer1Count++;
TFLG1= 0b00000010;// C0F - Interrupt Flag: Clear Input Capture 1 Flag
if( IsTimer1Abgelaufen() )
{
StartTimer1(1000);
}
}
and here are some other functions I use (used in ISR):
------------------------------------------------------
void InitTimer1(void)
{
//TC1= TCNT + 65249;
TIE&= ~Bit1; // C1I= 0
}
void ISR_Timer1(void)
{
TIE&= ~Bit1; // C1I= 0
bTimer1Abgelaufen= YES;
TFLG1|= Bit1; // C1F= 1
}
void StartTimer1(unsigned int ticks)
{
TC1= TCNT + ticks; // 65249;
TFLG1|= Bit1; // C1F= 1
bTimer1Abgelaufen= NO;
bTimer1Laeuft= YES;
TIE|= Bit1; // C1I= 1
}
------------------------------------

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
=?Windows-1252?Q?RE:_[68HC1?= =?Windows-1252?Q?2]_Problem?= =?Windows-1252?Q?_initialis?= =?Windows-1252?Q?e_timer_fo?= =?Windows-1252?Q?r_1=C2=B5s_cyc?= =?Windows-1252?Q?le?= - justin lucas - May 1 12:01:17 2009
Did you initialize the counter?=20
=20
I have just implemented a 1 millisecond timer for this processor, but its i=
n assembly since I use assembly more...
I don't see a initialize routine for a timer starting point...
=20
If you want, I'll pass along my code for the 1 millisecond timer...then you=
would have to convert it to the micro second you want..
=20
> To: 6...@yahoogroups.com
> From: f...@yahoo.com
> Date: Fri, 1 May 2009 07:56:39 -0400
> Subject: [68HC12] Problem initialise timer for 1=C2=B5s cycle
>=20
> Hello,
>=20
> I have a problem with using the Timer on a MC9S12DP512. I want to create =
1=C2=B5 second cycles. Every =C2=B5s I want to increment a variable, but I =
do not know how to initialise the timer, so that I get a timer interrupt ev=
ery =C2=B5s.
> I hope that someone can help me.
> Best regards
>=20
> Here is my function to initialise the timer:
> --------------------------------------------
>=20
> void Init_Timers(void)
> {
> TCTL2=3D 0;
> // TCTL2_OL3=3D 0;
> /*TCTL2_OM2=3D 0;
> TCTL2_OL2=3D 0;
> TCTL2_OM1=3D 0;
> TCTL2_OL1=3D 0;
> TCTL2_OM0=3D 0;
> TCTL2_OL0=3D 0;*/
>=20
> TIE&=3D ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // C3I=3D 0, C2I=3D 0, C1I=3D 0=
, C0I=3D 0
> /*TIE_C2I=3D 0;
> TIE_C1I=3D 0;
> TIE_C0I=3D 0;*/
>=20
> TTOV&=3D ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // TOV3=3D 0, TOV2=3D 0, TOV1=
=3D 0, TOV0=3D 0
> /*TTOV_TOV2=3D 0;
> TTOV_TOV1=3D 0;
> TTOV_TOV0=3D 0;*/
> //TTOV|=3D Bit6;
>=20
> TSCR2&=3D ~(Bit3); // TCRE=3D 0
>=20
> TIOS|=3D Bit5|Bit4|Bit3|Bit2|Bit1|Bit0; // IOS3=3D 1, IOS2=3D 1, IOS1=3D =
1, IOS0=3D 1
> /*TIOS_IOS2=3D 1;
> TIOS_IOS1=3D 1;
> TIOS_IOS0=3D 1;*/
> //TIOS|=3D Bit6;
>=20
> TSCR1|=3D Bit7; // TEN=3D 1
> TSCR1&=3D ~(Bit6|Bit5); // TSWAI=3D 0, TSFRZ=3D 0
> // TSCR1_TEN=3D 1;
> // TSCR1_TSWAI=3D 0;
> // TSCR1_TSFRZ=3D 0;
>=20
> PWMCTL&=3D ~(Bit3|Bit2); // PSWAI=3D 0, PFRZ=3D 0
> // PWMCTL_PSWAI=3D 0;
> // PWMCTL_PFRZ=3D 0;
> //TCTL2|=3D Bit4;
> //TC6|=3D 0x8000;
> PWMSDN=3D 0;
>=20
> ICSYS=3D 0;
>=20
> //MCCTL|=3D Bit6; // MODMC=3D 1
> TSCR2|=3D 7; // PR2=3D 1, PR1=3D 1, PR0=3D 1
> // TSCR2|=3D Bit2|Bit1;
> // TSCR2_PR=3D 6;
> InitTimer1();
> }
>=20
> and here is my Timer ISR:
> -------------------------
>=20
> @interrupt void _ISR_Timer1(void)
> {
> ISR_Timer1();
> gTimer1Count++;=20
> TFLG1=3D 0b00000010;// C0F - Interrupt Flag: Clear Input Capture 1 Flag=20
> if( IsTimer1Abgelaufen() )=20
> {=20
> StartTimer1(1000);=20
> }=20
> }
>=20
> and here are some other functions I use (used in ISR):
> ------------------------------------------------------
>=20
> void InitTimer1(void)
> {
> //TC1=3D TCNT + 65249;
> TIE&=3D ~Bit1; // C1I=3D 0
> }
>=20
> void ISR_Timer1(void)
> {
> TIE&=3D ~Bit1; // C1I=3D 0
> bTimer1Abgelaufen=3D YES;
> TFLG1|=3D Bit1; // C1F=3D 1
> }
>=20
> void StartTimer1(unsigned int ticks)
> {
> TC1=3D TCNT + ticks; // 65249;
> TFLG1|=3D Bit1; // C1F=3D 1
> bTimer1Abgelaufen=3D NO;
> bTimer1Laeuft=3D YES;
> TIE|=3D Bit1; // C1I=3D 1
> }
>=20
>=20
>=20
>=20
> ------------------------------------
>=20
>

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
=?iso-8859-1?Q?RE:_=5B68HC12=5D_Problem_initialise_timer_for_1=C2=B5s_cyc?= =?iso-8859-1?Q?le?= - jpdi - May 4 4:21:37 2009
Hi,
I find just this morning your problem about Timer.
Because of character problems on the mail I received, I can't see if you
want interrupt each micro-second...=20
If so, it seems very very fast for that processor.
With 12 Mhz quartz, no PLL, I use an empty function (in C) to delay 2.5
micro-seconds=A0:
void Delay_2_5_micro (void)
{ // nothing to do
}
That means just call and return from this empty function take 2.5
micro-seconds, measured with oscilloscope.
Hope this helps.
Joel
-----Message d'origine-----
De=A0: 6...@yahoogroups.com [mailto:6...@yahoogroups.com] De la part de
justin lucas
Envoy=E9=A0: vendredi 1 mai 2009 18:01
=C0=A0: 6...@yahoogroups.com
Objet=A0: RE: [68HC12] Problem initialise timer for 1=C2=B5s cycle
Did you initialize the counter?=20
=20
I have just implemented a 1 millisecond timer for this processor, but its i=
n
assembly since I use assembly more...
I don't see a initialize routine for a timer starting point...
=20
If you want, I'll pass along my code for the 1 millisecond timer...then you
would have to convert it to the micro second you want..
=20
> To: 6...@yahoogroups.com
> From: f...@yahoo.com
> Date: Fri, 1 May 2009 07:56:39 -0400
> Subject: [68HC12] Problem initialise timer for 1=C2=B5s cycle
>=20
> Hello,
>=20
> I have a problem with using the Timer on a MC9S12DP512. I want to create
1=C2=B5 second cycles. Every =C2=B5s I want to increment a variable, but I =
do not
know how to initialise the timer, so that I get a timer interrupt every =C2=
=B5s.
> I hope that someone can help me.
> Best regards
>=20
> Here is my function to initialise the timer:
> --------------------------------------------
>=20
> void Init_Timers(void)
> {
> TCTL2=3D 0;
> // TCTL2_OL3=3D 0;
> /*TCTL2_OM2=3D 0;
> TCTL2_OL2=3D 0;
> TCTL2_OM1=3D 0;
> TCTL2_OL1=3D 0;
> TCTL2_OM0=3D 0;
> TCTL2_OL0=3D 0;*/
>=20
> TIE&=3D ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // C3I=3D 0, C2I=3D 0, C1I=3D 0=
, C0I=3D 0
> /*TIE_C2I=3D 0;
> TIE_C1I=3D 0;
> TIE_C0I=3D 0;*/
>=20
> TTOV&=3D ~(Bit5|Bit4|Bit3|Bit2|Bit1|Bit0); // TOV3=3D 0, TOV2=3D 0, TOV1=
=3D 0,
TOV0=3D 0
> /*TTOV_TOV2=3D 0;
> TTOV_TOV1=3D 0;
> TTOV_TOV0=3D 0;*/
> //TTOV|=3D Bit6;
>=20
> TSCR2&=3D ~(Bit3); // TCRE=3D 0
>=20
> TIOS|=3D Bit5|Bit4|Bit3|Bit2|Bit1|Bit0; // IOS3=3D 1, IOS2=3D 1, IOS1=3D =
1, IOS0=3D
1
> /*TIOS_IOS2=3D 1;
> TIOS_IOS1=3D 1;
> TIOS_IOS0=3D 1;*/
> //TIOS|=3D Bit6;
>=20
> TSCR1|=3D Bit7; // TEN=3D 1
> TSCR1&=3D ~(Bit6|Bit5); // TSWAI=3D 0, TSFRZ=3D 0
> // TSCR1_TEN=3D 1;
> // TSCR1_TSWAI=3D 0;
> // TSCR1_TSFRZ=3D 0;
>=20
> PWMCTL&=3D ~(Bit3|Bit2); // PSWAI=3D 0, PFRZ=3D 0
> // PWMCTL_PSWAI=3D 0;
> // PWMCTL_PFRZ=3D 0;
> //TCTL2|=3D Bit4;
> //TC6|=3D 0x8000;
> PWMSDN=3D 0;
>=20
> ICSYS=3D 0;
>=20
> //MCCTL|=3D Bit6; // MODMC=3D 1
> TSCR2|=3D 7; // PR2=3D 1, PR1=3D 1, PR0=3D 1
> // TSCR2|=3D Bit2|Bit1;
> // TSCR2_PR=3D 6;
> InitTimer1();
> }
>=20
> and here is my Timer ISR:
> -------------------------
>=20
> @interrupt void _ISR_Timer1(void)
> {
> ISR_Timer1();
> gTimer1Count++;=20
> TFLG1=3D 0b00000010;// C0F - Interrupt Flag: Clear Input Capture 1 Flag=20
> if( IsTimer1Abgelaufen() )=20
> {=20
> StartTimer1(1000);=20
> }=20
> }
>=20
> and here are some other functions I use (used in ISR):
> ------------------------------------------------------
>=20
> void InitTimer1(void)
> {
> //TC1=3D TCNT + 65249;
> TIE&=3D ~Bit1; // C1I=3D 0
> }
>=20
> void ISR_Timer1(void)
> {
> TIE&=3D ~Bit1; // C1I=3D 0
> bTimer1Abgelaufen=3D YES;
> TFLG1|=3D Bit1; // C1F=3D 1
> }
>=20
> void StartTimer1(unsigned int ticks)
> {
> TC1=3D TCNT + ticks; // 65249;
> TFLG1|=3D Bit1; // C1F=3D 1
> bTimer1Abgelaufen=3D NO;
> bTimer1Laeuft=3D YES;
> TIE|=3D Bit1; // C1I=3D 1
> }
>=20
>=20
>=20
>=20
> ------------------------------------
>=20
>

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