Problem with MC9S12NE64V1's timer!!

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

Problem with MC9S12NE64V1's timer!!

4,875 Views
jeypi
Contributor I
    Hello,

I´m using the MC9S12NE64V1 and I'm having some problems when debugging in CodeWarrior IDE version 5.7.0. I'm trying to program the Timer to generate interrupts. But the problem occurs when I debug the program. I can´t clear the interrupt flag of Timer and the program is always going to the interruption part, even when I disable the Timer. The code to configure the Timer is present below:

    TIOS_IOS4 = 1;   // timer 4 output compare
    TSCR2_PR = 0;    // prescaler 0 : 25Mhz
    TIE_C4I = 0;     // interrupt 4 enable
    TSCR1_TSFRZ = 1; // disable timer in freeze mode

    TC4 = _TCNT.Word + 200;
    TSCR1_TEN = 1;   // enable timer

Another doubt, the TFLG1_C4F flag is set when I enable the Timer, why this happen? I clear the flag with the command in the end of interruption:
   
    TFLG1_C4F = 1;

But the flag doesn't clear. For debugging the code, I'm using the Serial Monitor.

Thanks,

João Paulo.




Labels (1)
0 Kudos
9 Replies

889 Views
Technoman64
Contributor III
Look at the generated code to see if the TFLG1_C4F = 1 is generating a bset instruction. This will NOT clear the timer flag.
 
Instead try using TFGL1 = 0x10 which should work as needed.
 
I have ran into this before in an early release of Codewarrior for HCS12 and the code generated by Processor Expert used this method. I contacted support it was changed for future releases.
0 Kudos

889 Views
kef
Specialist I
Technoman64,
 
Just a small correction. You are right, TFLG1_C4F = 1, where TFLG1_C4F is a member of C bitfield, is or should generate
 
BSET TFLG1, #0x10    ;  bit4 bitmask is 1<<4 = 0x10
 
Coumpiler also could not generate BSET, but something like this:
 
LDAB  TFLG1
ORAB  #0x10
STAB  TFLG1
 
No matter, is it BSET or above 3 instructions, TFLG1_C4F=1 DOES CLEAR C4F and all other TFLG1 flags that are set at the moment CPU reads TFLG1 register. Bitfiels can't be used to clear timer (and many other peripherals) flags without sideeffects! Problem with bitfield is that when you want to change a bit, C carefully preserves all other bits. That's cool, but unfortunately not with timer flags, which are clearable by writing '1' to them.
 
 
I don't know what could be wrong with NE64 timer or with jeypi's code.
 
Regards
0 Kudos

889 Views
Technoman64
Contributor III
I have found that the HCS12(X) compiler will optimize under the default settings and use BSET as it requires fewer instructions.
 
The Codewarrior is very efficent and it is one of the best I have ever worked with. I have even went as far to port code over that creates object oriented code in C and the compiler accepted all of the directives that work with Microsoft C. I am sure there are some things that would not be the same but is a very feature rich development environment, in my opinion anyways.
0 Kudos

889 Views
jeypi
Contributor I
Hello,

I use the register to (TFLG1 = 0x01) clear the flag but didn't work. Is is possible that the Code Warrior Debug doesn't accept Timers when debugging?

Thanks for helping.

João Paulo.
0 Kudos

889 Views
kef
Specialist I
jeypi,
 
I think I have idea what's wrong in your case. TFRZ bit makes sense only for debug via BDM. Serial monitor doesn't stop MCU, timers and anything else. Serial monitor is just an another program that must run all the time. So when timer channel is operating in compare mode, and you step over flag clear code, timer will quickly tick another 2^16 ticks and set flag again... Even at 4MHz and 1:128 prescaler, it will take just 2 seconds to count another 2^16 ticks and set flag again.
 
You are right, TFLG1 = 0x01; - is fine to clear timer channel 0 flag. Alternatively you may
use TFLG1 &= 0x01;. But you shouldn't use TFLG1 |= 0x01; or bitfields TFLG1_C0F = 1; or
TFLG1_C0F = 0;
 
0 Kudos

889 Views
Technoman64
Contributor III
You are using hex 01 which will clear the flag for output compare 0. In your previous post you were trying to clear the flag for output compare 4 which would require the hex value 10.
 
Look at the values as binary
 
0x01 = %00000001
0x10 = %00010000
 
Try using TFGL1 = 0x10 instead of TFLG1 = 0x01 to clear the flag for output compare 4.
0 Kudos

889 Views
jeypi
Contributor I
Hello,

You are right Techonoman, I was writing the wrong command. but I corrected and didin´t work. Even when I diseable the Timer the code continues to execute the interrupt on degub mode. Another thing I didn't get: when I enable the Timer, this flag (TFLG1_C4F) become 1, is it right? When the Timer finishes the counts and generate an interrupt, the flag assume which valor: 1 or 0? Because in PIC´s microcontrollers when you clear a flag you clear the bit, writing 0 in the flag.

Thanks for help,

Jey Pi.
0 Kudos

889 Views
Technoman64
Contributor III
I beleive that you are now experianceing waht Kef stated earlier about using the serial debug monitor. Unless it has method to disable stepping into interrups it is going to occur faster than you can debug. With a 25Mhz clock and a timeout of 200 counts this is occuring faster than the debug interface can react.
 
If you use a BDM interface, for example the PE USB BDM interface you will have more options to debug from within the Codewarrior debugger. This interface and Hiwave debugger will allow you to single step interrupts and it will stop the interrupts while debugging so you can accuratly view what is happening.
 
And yes with the HCS12 you write a 1 to clear the flag not a 0. There is much information on this in the Referance manual. Also do a search and there are other posts covering the Timer Flag clearing and disabling interrupts while debugging.
 


Message Edited by Technoman64 on 2007-12-14 03:21 PM
0 Kudos

889 Views
jeypi
Contributor I
Ok,

I'll check!

Thanks,

Jey Pi.
0 Kudos