ECT_TCNT Random in Debugger

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

ECT_TCNT Random in Debugger

Jump to solution
1,816 Views
Destroy
Contributor II
Hello,
 
When I single step my program and watch the TCNT Word in the debugger, it changers by great amounts, like 30,000 steps at a time, even when I assembler step it.
 
It should change by two steps for each assembler step at the absolute maximum.
 
I am running 16x32 division through TSCR2 and PTPSR so I would expect the pulses to take many single steps.
 
What is happening? 
 
My PLL is working fine as I can generate known frequencies on the ECLK pin.
 
Also this is causing continuous interrupts and the flags are always set.
 
However when I run it on the processor, it runs nearly as expected, except it is out by a factor of 8 to what my expected period is.
 
This is my Init routine...
 
**********************************************************
 
void ECT_Init(void){
    ECT_TSCR1 = 0x98;      / // turn Counter on and enable precision timer.
    ECT_TSCR2 = 0x04;      // Divide by 16
    ECT_PTPSR = 0x1F;      // Divide by 32 
                                            // Bus Freq (80Mhz) Divided by (16*32) = 156,250hz
    ECT_TIOS |= 0x01;        // Set IOS0 as Output Compare
    ECT_TCTL2 |= 0x01;     // Set Output Compare 0 to toggle  
    ECT_TIE = 0x01;            // Set OC0 and OC1 to allow interrupts 
    
    ECT_TC0 = ECT_TCNT + 0x0870;   // Load first compare value 216 degrees
}
 
interrupt void ISR_MakeCrankSignal (void){  // ECT0
    int CmpVal = 0;
    
    ECT_TFLG1 = 0x01;      // Clear Flag
    
    if (CAS_Pos == 1){
        CmpVal = CAS_PW;
    } 
    if (CAS_Pos == 2){
        CmpVal = CAS_PW*4;
    }
    if (CAS_Pos == 3){
        CmpVal = CAS_PW*2;
    }
    if (CAS_Pos == 4){
        CmpVal = CAS_PW*3;
    }
    ECT_TC0 += CmpVal;
    CAS_Pos = CAS_Pos + 1;
    if (CAS_Pos == 5){
        CAS_Pos = 1;
    }
    return;
}
 
 
**********************************************************
 
 
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
675 Views
kef
Specialist I
When you single step or stop on breakpoint, TCNT keeps running. Try setting TSFRZ bit and see what happens.

View solution in original post

0 Kudos
Reply
3 Replies
675 Views
Destroy
Contributor II
Okay I realise that I made a mistake with thinking that TSCR2[PR2:smileytongue:R0] Multiplied with PTPSR.  It is wither one or the other.  I have now rectified that error.
 
However, the TCNT word in the debugger jumps by counts of 30,000 or more each single step of the assembler.
 
I would think that most assembler instructions only take one or two clock pluses and therefore the TCNT registers should only step by 1 or 2 also, assuming no prescalar.  I would think that a prescalr would make you have to do 2,4,8 etc: assembler steps to see a step in the TCNT register.
 
What Am I doing wrong?
0 Kudos
Reply
676 Views
kef
Specialist I
When you single step or stop on breakpoint, TCNT keeps running. Try setting TSFRZ bit and see what happens.
0 Kudos
Reply
675 Views
Destroy
Contributor II
Thank You very much, that was exactly it, that was doing my head in yesturday.  It works as expected now. :smileyhappy:
0 Kudos
Reply