Problem using TC7 to also control TC3

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Problem using TC7 to also control TC3

279 次查看
JohnnyP
Contributor III

Hi,

I'm using a 9s12C32 to control spark timing, using TC7 to also control TC3.

OC7D = 88 AND OC7M = 08.

After loading TC7, I ADDD $0032 into TC3, so TC3 should go low 100usec after TC7 ends, but TC3 instantly goes low when TC7 is loaded with the compare value.  

 

BSET TIOS, $F8

LDAA #$88

STAA OC7M

LDAA #$08

STAA OC7D

LDD Delay

ADDD #$0002

ADDD TCNT

STD TC7

ADDD #$0032

STD TC3

0 项奖励
回复
3 回复数

209 次查看
JohnnyP
Contributor III

Oops, please edit my last post, as that doesn't really work.  It only works on every other spark event. 

0 项奖励
回复

210 次查看
JohnnyP
Contributor III

Thanks for your reply but google Ai and I finally figured it out.  Here is the correct code:

 

; Assume PT3 has been properly set high via GPIO
; and the timer is already enabled via TSCR1:TEN

    ; Step 1: Disable OC3 to prepare for configuration
    BCLR TIOS, $08

    ; Step 2: Set TC3 to the immediate past
    LDD TCNT
    SUBD #$0001    STD TC3

    ; Step 3: Configure OC3 to "no action" (OM3:OL3 = 00)
    ; This ensures the pin is not affected when OC takes over.
    BCLR TCTL2, $C0

    ; Step 4: Re-enable OC3
    BSET TIOS, $08

    ; Step 5: Wait for the "past" compare event to occur and set its flag
zot:
    BRCLR TFLG1, $08, zot

    ; Step 6: Clear the timer flag for channel 3    LDAA #$08    STAA TFLG1

    ; Step 7: Set the TC3 for the future compare event
    LDD TCNT
    ADDD Delay
    ADDD #$0032    STD TC3

    ; Step 8: Configure OC3 for the **next** compare to "clear" the output (OM3:OL3 = 01)
    ; The timing is critical here. This must be done AFTER the flag is cleared.
    BSET TCTL2, $40      ; Set OL3 (bit 6)
    BCLR TCTL2, $80      ; Clear OM3 (bit 7)
0 项奖励
回复

215 次查看
lama
NXP TechSupport
NXP TechSupport

Hi,

there is a lot of missing info. It is not possible to investigate issue without full setup and loop.

However, look at following code. It generates on pulse after delay.... inspired by your code.

I did it in C+ asm but believe you will understand....

//-----------------------------------------
unsigned int Delay;
//-----------------------------------------
void main(void)
{
  //-----------------------------------------
  asm
  {
    MOVW #$0022, Delay

    MOVB #$04, TSCR2 // ; prescaler =16, do not reset tim by OC of channel 7
                                     // ; ovf int disable
    MOVB #$AA, TCTL1  // ; channels 7,6,5,4 clear on compare
    MOVB #$AA, TCTL2 // ; channels 3,2,1,0 clear on compare

    BSET TIOS, $F8          // ; 7,6,5,4,3 :OC 2,1,0 :IC
    LDAA #$88
    STAA OC7M             // ; Xnnn ynnn

    LDAA #$08
    STAA OC7D              // ; 0000 1000 … FORCE TC3 TO 1 ON TC7 OC

    LDD Delay
    ADDD #$0002
    ADDD TCNT              // ; D = TCNT+DELAY+2
    STD TC7                    // ; TC7 = D

    ADDD #$0032
    STD TC3                    // ; TC3 = D+32
  }
  //-----------------------------------------
  TSCR1 = 0xE0;            // enable timer,stop in wait,stop in freeze, NO fast flag clear
  //-----------------------------------------
  for(;;)
    {
        asm nop;
    }
   //-----------------------------------------
}

//***********************************************************************************

 

Best regards,
Ladislav



0 项奖励
回复