Drew Rainwater

(Simple) Timer Problem on MC9S12A32

Discussion created by Drew Rainwater on Jan 27, 2010
Latest reply on Jan 27, 2010 by kef

I'm trying to port old HC11 code (written by another employee) to the MC9S12A32, and this is my first attempt at working with the Motorola/Freescale family of MCUs.

 

The problem I'm seeing is that the C0F flag is immediately set when I initialize the timer (by enabling the Output Compare on Channel 0 and enabling the timer by setting TEN) :

 

---

 TIMERINIT   LDAA #$01
            STAA TIOS     ;SET CHANNEL 0 TO OUTPUT COMPARE
           
            LDAA #$80
            STAA TSCR1    ;ENABLE TIMER
          
            RTS

---

 

Later, when I'm trying to create a 15ms delay, the C0F flag is already set and my delay subroutine exits too quickly.  I have tried to clear the C0F flag by writing a 1 to the bit (TFLG1.1), but that either fails or the flag is immediately set again before I can read it with the next instruction

 

---

 DELAY
       LDAA        #$01
       STAA        TFLG1           ;CLEAR OC0F
       LDD         TCNT.H          ;GET PRESENT TIMER VALUE
       ADDD        DLY              ;ADD REQUIRED DELAY
       STD         TC0.H           ;STORE IN COMPARE 0
     
       
LP1           LDAB        TFLG1           ;WAIT FOR COMPARE
       STAB        TFLAG
       BRCLR       TFLAG,  $01,  LP1

       RTS

---

 

Can anyone offer a suggestion why the C0F flag is being set immediately and/or continuously?

 

Also, as a side question, in CodeWarrior, there doesn't seem to be an easy way to watch the Timer registers change as I step through instructions (which would make this problem easier to diagnose).  My Memory window doesn't update the contents of memory locations as I step through--should this be the case?

 

Thanks in advance.

Drew

Outcomes