定时器TCNT写操作

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

定时器TCNT写操作

2,497 Views
xwj
Contributor II

请教大神一个问题:
问题描述:

         我目前用的MCU: MC9S12G64

          使用外部晶振: 8MHz

          用定时器溢出中断,定时器时钟8分频(1MHz);在溢出中断写 TCNT = 65536-1000,  定时1MS,  

          在溢出中断中置IO, 用仿真器调试1MS 波形OK; 但取掉仿真器后,波形出现问题;也就是TCNT寄存器好象没有写成  功; 

          是否可以在溢出中断中对TCNT进行写操作;

程序代码如下:

pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt  VectorNumber_Vtimovf void overflow(void) 
{
  unsigned int temp=0;  
  if(TFLG2_TOF==1)
  {  
    temp = TCNT;   // 清除TOF标志   
    PWM_MPWM = ~PWM_MPWM;    // 置反IO      
    TSCR1_TEN = 0;  
    TCNT = TIMER_START_VAL2; //  65535-1000 1MS   TIM CLOCK  1MHz
    TSCR1_TEN = 1;      
  }   
}
#pragma CODE_SEG DEFAULT
目前这种配置定时器最小只能做到4MS  65536*(8/256)=4096 US;
如果要实验定时1MS,有没有其它办法,可以实现;
0 Kudos
2 Replies

1,050 Views
xwj
Contributor II

问题描述:

         我目前用的MCU: MC9S12G64

          使用外部晶振: 8MHz

          用定时器溢出中断,定时器时钟8分频(1MHz);在溢出中断写 TCNT = 65536-1000,  定时1MS,  

          在溢出中断中置IO, 用仿真器调试1MS 波形OK;

          但取掉仿真器后,波形出现问题;也就是TCNT寄存器好象没有写成 功;

          TCNT是否可以进行写操作, 

          是否可以在溢出中断中对TCNT进行写操作

         附件为工程文件;

0 Kudos

1,050 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi,

To work on your problem, please send your processor expert project here.

we need reproduce and test first

Thanks.


Have a great day,
Jennie Zhang

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------