打印
[8/16-bit MCU]

MC9S12G64 TIM 分频问题???(已解决)

[复制链接]
2409|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 FSL_TICS_A 于 2014-8-7 14:51 编辑

代码如下:
#include <hidef.h>        /* common defines and macros */
#include "derivative.h"   /* derivative-specific definitions */


/******************************************************************************
Function Name  : TIM0ISR
Engineer       : r59709        
Date           : 06/26/2009
Notes          : Interrupt service routine for Timer channel 0.
******************************************************************************/
#pragma CODE_SEG NON_BANKED
#pragma TRAP_PROC
void interrupt VectorNumber_Vtimch0 TIM0ISR(void)
{

  PTP_PTP0 ^= 1;          /* Toggle Port T4 to show output compare occured.*/
  T标志寄存器1 = T标志寄存器1_C0F_MASK; /* Clear channel 0 flag.                         */

}
#pragma CODE_SEG DEFAULT

/******************************************************************************
Function Name  : TIM1ISR
Engineer       : r59709
Date           : 06/26/2009
Notes          : Interrupt service routine for Timer channel 1.
******************************************************************************/
#pragma CODE_SEG NON_BANKED
#pragma TRAP_PROC
void interrupt VectorNumber_Vtimch1 TIM1ISR(void)
{

  PTP_PTP1 ^= 1;          /* Toggle Port T5 to show output compare occured.*/
  T标志寄存器1 = T标志寄存器1_C1F_MASK; /* Clear channel 1 flag.                         */

}
#pragma CODE_SEG DEFAULT


/******************************************************************************
Function Name  : TIM3ISR
Engineer       : r59709
Date           : 06/26/2009
Notes          : Interrupt service routine for Timer channel 3.
******************************************************************************/
#pragma CODE_SEG NON_BANKED
#pragma TRAP_PROC
void interrupt VectorNumber_Vtimch3 TIM3ISR(void)
{

  PTP_PTP3 ^= 1;          /* Toggle Port P3 to show input capture occured.*/
  T标志寄存器1 = T标志寄存器1_C3F_MASK; /* Clear channel 3 flag.                        */

}
#pragma CODE_SEG DEFAULT

/******************************************************************************
Function Name  : Perform_Output_Compare
Engineer       : r59709
Date           : 06/26/2009
Notes          : Function to setup Timer module for output compare.
******************************************************************************/
void Perform_Output_Compare(void)
{
  PTP_PTP0 = 1;
  PTP_PTP1 = 1;

  DDRP_DDRP0 = 1;
  DDRP_DDRP1 = 1;

  TSCR1_TEN = 0;  /* Disable Timer module before adjusting registers.    */
  TIOS_IOS0 = 1;  /* Set Channel 0 as output compare.                    */
  TCTL2_OM0 = 0;  /* Set channel 0 to toggle when a Timer match occurs.  */
  TCTL2_OL0 = 1;  /* Set channel 0 to toggle when a Timer match occurs.  */
  TC0       = 0x8000;   /* Set a value for channel 0 timer compare.            */
  TIE_C0I   = 1;    /* Enable channel 0 interrupt, handled by function TIM0ISR. */

  TIOS_IOS1 = 1;  /* Set Channel 1 as output compare.                   */
  TCTL2_OM1 = 0;  /* Set channel 1 to toggle when a Timer match occurs. */
  TCTL2_OL1 = 1;  /* Set channel 1 to toggle when a Timer match occurs. */
  TC1       = 0xFFFF; /* Set channel 1 timer compare.                             */
  TIE_C1I   = 1;      /* Enable channel 1 interrupt, handled by function TIM1ISR. */

  TSCR1_TSWAI = 1;/* Disables the timer module while in wait mode.    */
  TSCR1_TSFRZ = 1;/* Disables the timer counter while in freeze mode. */
  ////TSCR1_PRNT  = 1;  //在这里使能精度定时分频不起作用
  PTPSR = 24;
  ////TSCR2_PR    = 0x6; /* Set prescaler to divide by 64                    */
  TSCR1_TEN   = 1;  /* Timer Enable.                                    */
}

/******************************************************************************
Function Name  : Perform_Input_Capture
Engineer       : r59709
Date           : 06/26/2009
Notes          : Timer channel 3 is set as an any-edge input capture.
******************************************************************************/
void Allow_Input_Capture(void)
{
  PTP_PTP3    = 1;   /* To be used to indicate Input capture status on LED4          */
  DDRP_DDRP3  = 1;   /* Set P3 as output, the state of P3 will be toggled in TIM3ISR */

  PPST_PPST3  = 1;   /* Set Port T3 pull device polarity as low */
  PERT_PERT3  = 1;   /* Enable Port T3 pull device.             */

  TSCR1_TEN   = 0;   /* Disable timer module before adjusting registers. */
  TIOS_IOS3   = 0;   /* Set Channel 3 as input capture.                  */
  TCTL4_EDG3A = 1;   /* Set channel 3 to capture any edge transition.    */
  TCTL4_EDG3B = 1;   /* Set channel 3 to capture any edge transition.    */
  TIE_C3I     = 1;       /* Enable channel 3 interrupt, handled by function TIM3ISR.*/
  TSCR1_TSWAI = 1;   /* Disables the timer module while in wait mode.           */
  TSCR1_TSFRZ = 1;   /* Disables the timer counter while in freeze mode.        */

  TSCR2_PR    = 0x6; /* Set prescaler to divide by 64.                          */
  TSCR1_TEN   = 1;   /* Timer Enable.                                           */
}



/******************************************************************************
Function Name  : main
Engineer       : b30269
Date           : 09/19/2011
Notes          : Main procedure that calls initialization routines to:
                 1.- Configure OC0 and OC1 to toggle at a .7Hz, (output is
                     shown at P0 and P1 for LED1 and LED2)
                 2.- Configure IC3 to generate an interrupt when any transition
                     is detected at T3 (IOC3), output is shown at P3 for LED4.
.
******************************************************************************/
void main(void)
{

  TSCR1_PRNT  = 1;  //在这里使能精度定时分频可以
  Perform_Output_Compare();

        EnableInterrupts;


  for(;;)
  {
    _FEED_COP(); /* feeds the dog */
  } /* loop forever */
  /* please make sure that you never leave main */
}


问题:见注解红色字体,为什么会出现这种情况,这个位只能在复位写一次。

相关帖子

沙发
FSL_TICS_ZJJ| | 2014-7-30 09:03 | 只看该作者
楼主你好,
关于你这个问题,其实我们的reference manual 已经写了,如下:
723页

使用特权

评论回复
板凳
FSL_TICS_ZJJ| | 2014-7-30 09:04 | 只看该作者
所以说,在reset之后,是只写一次的。
RM的链接:
http://cache.freescale.com/files ... p;WT_TYPE=Reference Manuals&WT_VENDOR=FREESCALE&WT_FILE_FORMAT=pdf&WT_ASSET=Documentation&fileExt=.pdf

使用特权

评论回复
地板
caijun_2012|  楼主 | 2014-7-30 12:33 | 只看该作者
楼主,你好!红色部分是二选一,不是两个都写,只有在前面写这次才起做用,如果在后面写无效

使用特权

评论回复
5
FSL_TICS_ZJJ| | 2014-7-30 12:39 | 只看该作者
你不行是什么意思?
是值没有改变吗?
那你放在Perform_Output_Compare函数里面开始的地方试试。
我估计是其他的配置影响了。

使用特权

评论回复
6
caijun_2012|  楼主 | 2014-7-30 13:42 | 只看该作者
时钟分频不正确,我在试试看看

使用特权

评论回复
7
FSL_TICS_ZJJ| | 2014-7-30 13:57 | 只看该作者
caijun_2012 发表于 2014-7-30 13:42
时钟分频不正确,我在试试看看

好的,你试过之后再告诉我结果。
不可能只是因为放到后面就不能修改的,
肯定是你后面的程序影响到了这个地方的修改。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

42

主题

226

帖子

2

粉丝