Configure Timer as output - s12zvl

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

Configure Timer as output - s12zvl

Jump to solution
1,282 Views
alexishernandez
Contributor III

Hi, i'm trying to use the timer0-channel3 as output in one of the supported pins PT3 (i just want to be sure that the timing configuration is correct). 
The port configuration seems ok but the maximum frequency that i can get from the output is 100 Hz even though the frequency of the bus is 6.25MHz (measured using the ECLK signal).
It looks like the issue comes from the configuration of the 16 bit counter register, my main question is how to configure the 16 bit comparator in order to achieve an output of 6.25 MHz?

Here is the code snippet:

void TIM_Init(void){
   TIM0TIOS = 0x3F; /*0B0011 1111 - Select all channels as Output Compare*/ 
   TIM0TCTL1 = 0x05; /*0b0000 0101 - Toggle OC5/4 Output Line*/ 
   TIM0TCTL2 = 0x55; /*0b0101 0101 - Toggle OC3/2/1/0 Output Line */ 
   TIM0TIE = 0x08; /*0b0000 0100 - Interrupt Enabled Ch3*/ 
   TIM0TSCR2 = 0x00; /*0b0000 0000 - TimerOverflow@b7:off Prescaler=Clk/1*/
   TIM0OCPD = 0x37; /*0b0011 1011 - Enable OutputCompare Ch3*/ 
   TIM0TC3H = 0xFF;    
   TIM0TC3L = 0xF0;   
   TIM0TSCR1 = 0x80; /*0b1000 1000 - TimerEnabled with Legacy prescaler */
   TIM0CFORC = 0x08; /*0b0000 1000*/
}

MODRR2_T0C3RR=0;

Labels (1)
1 Solution
749 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hi Alexis,

The timer counter is 16-bit. TCNT counter is free running from 0x0000 to 0xFFFF. When TCNT counter reach TCx values, the OC channels generate events. For periodic event generation, you can set the interval.

The example generate output frequency. The shorter the interval, the higher the frequency.

See interrupt function, the value of the interval (ECT_PERIOD) is added to the counter value.

//==============================================================================

// Input Capture Interrupt

//==============================================================================

interrupt VectorNumber_Vtim0ch0 void IC0_ISR()

{   

       PTS_PTS0 = ~PTS_PTS0;      //toggle PS0

       TIM0TC0 = TIM0TC0+ECT_PERIOD;     //the next event update

       TIM0TFLG1 = 0x01;   //clear the flag

}

In the init function is needed to enable interrupts and set the TCx value:  TIM0TC0 = ECT_PERIOD;

Whole example under the name ZVML128-TIM-500usPeriod-CW105.zip and discussion on this theme you can find on this site: https://community.nxp.com/message/860977 

I hope it helps you.

 

Best regards,

Diana

View solution in original post

1 Reply
750 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hi Alexis,

The timer counter is 16-bit. TCNT counter is free running from 0x0000 to 0xFFFF. When TCNT counter reach TCx values, the OC channels generate events. For periodic event generation, you can set the interval.

The example generate output frequency. The shorter the interval, the higher the frequency.

See interrupt function, the value of the interval (ECT_PERIOD) is added to the counter value.

//==============================================================================

// Input Capture Interrupt

//==============================================================================

interrupt VectorNumber_Vtim0ch0 void IC0_ISR()

{   

       PTS_PTS0 = ~PTS_PTS0;      //toggle PS0

       TIM0TC0 = TIM0TC0+ECT_PERIOD;     //the next event update

       TIM0TFLG1 = 0x01;   //clear the flag

}

In the init function is needed to enable interrupts and set the TCx value:  TIM0TC0 = ECT_PERIOD;

Whole example under the name ZVML128-TIM-500usPeriod-CW105.zip and discussion on this theme you can find on this site: https://community.nxp.com/message/860977 

I hope it helps you.

 

Best regards,

Diana