Colin McGuire

HCS12 (MC9S12C32) WAI and Trigger C Occurred

Discussion created by Colin McGuire on Feb 13, 2008
Latest reply on Feb 21, 2008 by Colin McGuire
Hey there,

I am quite new to using the HCS12 and am having some problems. I am using the simple code below to try and create a simple output with a period of 64microS. I am doing it this way to expand on it later.

The problem I am having is that every so often periods are missed out, ie the output goes to 1 or 0 for say 10 cycles. I have no idea why it is doing this and it appears to be random. When I remove the WAI instruction it works perfectly and there are no missed periods. Does anyone know what is wrong?

MyCode:     SECTIONmain:Entry:                                    LDS #__SEG_END_SSTACK   ; Initialise Stack Pointer                                 BSET DDRT, #$01         ; Enable port T output            BSET TIOS, #%00000010   ; Set TIOS (Set TC1 to output compare)            BSET PTT, #$01          ; Set Port T to 1                        MOVB #$80, TSCR1        ; Timer enable                        LDD TCNT                ; Set TC1 to triger in 1ms             ADDD #256            STD TC1                        BSET TFLG1, #%00000010  ; Reset interrupt flag                        BSET TIE, #$02          ; Enable Interrupt for TC1                        CLI                        SPIN:       WAI                     ; Wait for interrupt then loop forever            BRA SPIN                        ISR_TC1:                                    LDAA PTT             EORA #$01                           STAA PTT                ; Set output to 1            LDD TC1                 ; Set TC1 to trigger in another 1ms            ADDD #256                          STD TC1                                       LDAA #$02               ; Reset the flag            STAA TFLG1                        RTI                                                                            

 I have used interrupts and timers before and they have worked OK. I am just not sure what the WAI is doing.

My second question is when a put a PLL code in here I get the error when I debug using P&E multilink "Trigger C Occured" when using the WAI statement. Why am I getting this error?

Thanks in advance,


Message Edited by Deadstar on 2008-02-13 06:20 PM