Count between two inpulsion

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Count between two inpulsion

Jump to solution
2,072 Views
loulou
Contributor I
Hello Friend,
 
 
I work on the MC9S12XDP512EVB and I work whith code warrior 4.1.
 
Now I want to count a time between two inpulsions but a i have 2 or 3 small problem or/and questions.
 
First Question
is It  possible not to use an interruption to manage the flags?  Or rather the microcontrollor can make it of him same ?
 
Me i don't use the interruption.
 
My Program:
 
#define TCTL_3 (*((char*)0x004A))
#define TCTL_4 (*((char*)0x004B))
#define LECTURE (*((short int*)0x0050))
#define TEMPS (*((short int*)0x3000))
 
//////////////////////////////////////////////////////////////////////////////////////////// 
void main(void) {
 
init_timer();  
   
 for(;:smileywink: {

 if ( TFLG1_C0F ) {
   TEMPS=LECTURE;
      }
}
//////////////////////////////////////////////////////////////////////////////////////////// 
 static void init_timer(void)  {
  
  TEMPS=0x0034;
  TIOS = 0xFE;
   TIE =0x00;
  TSCR2 =0x06;
   TCTL_3=0x00;
  TCTL_4=0x01;
  TSCR1=0xE8;
  
 } 
////////////////////////////////////////////////////////////////////////////////////////////// 
My program makes first of all an initialization of the module timer and after i wait an inpulsion on IOS0.
 
But the problem the microcontrollor don't put the flags at 0 and me i can't it too.
this fact my count don't restart and i don't take a good count between two inpulsion.
 
Now I turn to you for your assitance. I looking for of information and assistance on this programmme so that it realise the operation which I wish.
 
But if you have a other similar program of this you can take me please.
 
thank you for your assistance
 
 
PS: I'm sorry for my bad english
 
 
 
Labels (1)
Tags (1)
0 Kudos
1 Solution
341 Views
Alban
Senior Contributor II
Salut Loulou !
 
Reading a value is not enough to clear a flag.
The general rule of thumb on S12 to clear a flag is:
- Read the register which has the flag set,
- Write a ONE to the bit you want to reset or to its associated ACK bit.
 
So, and I haven't looked at your example in particular, but:
You can check the flag sometimes (what you do with your IF) it is reading the register. But then, within the "if" you whould do something like
TFLG1_TOF = 1; or use an ACKnowledgment bit if exists.
 
Do you see what I mean ?
Alban.

View solution in original post

0 Kudos
2 Replies
342 Views
Alban
Senior Contributor II
Salut Loulou !
 
Reading a value is not enough to clear a flag.
The general rule of thumb on S12 to clear a flag is:
- Read the register which has the flag set,
- Write a ONE to the bit you want to reset or to its associated ACK bit.
 
So, and I haven't looked at your example in particular, but:
You can check the flag sometimes (what you do with your IF) it is reading the register. But then, within the "if" you whould do something like
TFLG1_TOF = 1; or use an ACKnowledgment bit if exists.
 
Do you see what I mean ?
Alban.
0 Kudos
341 Views
loulou
Contributor I
Thank you for your answer Alban.
 
 
I understood well what you said  for restart the flags but if i  restart the flags is what my count will pass by again has 0 too ??
 
Now I go to test the restart flag.
 
Thank
0 Kudos