the output of MC9S12G128 is not normal

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

the output of MC9S12G128 is not normal

1,094 Views
liufeng123
Contributor II

i use the mcu which is the MC9S12G128,but when the general timer is enable ,the output of PJ4 is not normal,the voltage ot the PJ4 is 2.6v,however when the Real time is enable ,the output of PJ4 is ok(5V).the same situation is when the PJ4  is configuration as input.

the source code is as follows:

void initialize_TIM(void){
  TSCR1_TFFCA = 1;  // 定时器标志位快速清除
  TSCR1_TEN = 1;    // 定时器使能位. 1=允许定时器正常工作; 0=使主定时器不起作用(包括计数器)
  TIOS  = 0xff;      //指定所有通道为输出比较方式
  TCTL1 = 0x00;        // 后四个通道设置为定时器与输出引脚断开
  TCTL2 = 0x00;     // 前四个通道设置为定时器与输出引脚断开
  TIE   = 0x01;     // 允许通道0定时中断
  TSCR2 = 0x07;        // 预分频系数pr2-pr0:110,时钟周期为4us,
  TFLG1 = 0xff;        // 清除各IC/OC中断标志位
  TFLG2 = 0xff;     // 清除自由定时器中断标志位
}  


//传感器1中断配置
      PTIJ_PTIJ4=0;
      PPSJ |= 0x00;              //极性选择寄存器,选择下降沿;
      PIFJ |= 0x10;                    //对PIFJ的每一位写1来清除标志位;
      PIEJ |= 0x10;              //中断使能寄存器;
      PERJ_PERJ4=1;

the realtimer source is as follows:

 //16ms real timer
    CPMUINT  &=~(0x80);
    CPMUFLG  &=~(0x80);
    CPMURTI  |= 0x10;     //   0x10
    CPMURTI  |= (16-1);
    //CPMUINT  |=0x80;
    CPMUINT_RTIE = 1;

0 Kudos
5 Replies

937 Views
kef2
Senior Contributor IV

Hi,

perhaps you drive your pin to one level and your external too heavy load drives it to the opposite level?

If the pin has no excess load, then perhaps part is damaged. Isn't chip hot?

BTW I see problems in your code. You should fix your way to clear flags, or they will bite you later when you add more features to your code.

This is correct:

TFLG1 = 0xff;        // 清除各IC/OC中断标志位
  TFLG2 = 0xff;     // 清除自由定时器中断标志位

to clear single bit 2 flag your would do

TFLG1 = (1<<2);

or

TFLG1 = 4;

This is wrong:

PIFJ |= 0x10;                    //对PIFJ的每一位写1来清除标志位;

flags register is not regular register or memory cell. Flag is cleared writing one to particular bit. If more flags bits are set, then you will rewrite with 1 and thus clear all flags which are set! Above code line is clearing all PIFJ flags!

You need to either

PIFJ = 0x10;

or

PIFJ &= 0x10; // please notice the difference, not ~0x10 but 0x10

This is wrong as well:

CPMUFLG  &=~(0x80);

it clears all flags except what you expect to clear. You think bit 7 should be cleared, but instead bit6..0 flags are cleared. 

should be

CPMUFLG &= 0x80;

or

CPMUFLG = 0x80;

or even better self commented

CPMUFLG &= CPMUFLG_RTIF_MASK;

or

CPMUFLG = CPMUFLG_RTIF_MASK;

Regards,

Edward

0 Kudos

937 Views
liufeng123
Contributor II

dear edward,thank you for your help.according to your suggestion,we modify the source code,but the problem is all the same.

/************************************************************/
/* 初始化TIM模块 */
/************************************************************/
void initialize_TIM(void){
TFLG1 = 0xff; // 清除各IC/OC中断标志位
TFLG2 = 0xff; // 清除自由定时器中断标志位
TSCR1_TFFCA = 1; // 定时器标志位快速清除
TSCR1_TEN = 1; // 定时器使能位. 1=允许定时器正常工作; 0=使主定时器不起作用(包括计数器)
TIOS = 0xff; // 指定所有通道为输出比较方式
TCTL1 = 0x00; // 后四个通道设置为定时器与输出引脚断开
TCTL2 = 0x00; // 前四个通道设置为定时器与输出引脚断开
TIE = 0x00; // 禁止所有通道定时中断
TSCR2 = 0x86; // 预分频系数pr2-pr0:110,时钟周期为4us,使能定时器溢出中断
}

TFLG1_C0F = 1;
TC0 = TCNT + 5000;

DDRJ_DDRJ4=0;
PIFJ = 0x10;
PERJ_PERJ4=1;

PJ4  is configured as input mode with the Pull device enable,but when the TIOS =oxff,the output of PJ4 is 0.however when the TIOS=oxff is removed,the  output  of PJ4 is 5v(OK)

0 Kudos

937 Views
kef2
Senior Contributor IV

Hi,

Looks like you didn't listen to me trying to save your from nasty software bugs.

TFLG1_C0F = 1; // wrong!

^^ this is equivalent to :

TFLG1 |= TFLG1_C0F_MASK; // wrong, will clear all TFLG1 flags instead of just C0F !

And regarding your bigger problem, 2.6V instead of 0/5V on PJ4, it's clearly not software but hardware problem. Either circuit is wrong or perhaps MCU is damaged.

Edward

0 Kudos

937 Views
liufeng123
Contributor II

however,PJ4  is configured as input mode with the Pull device enable,but when the TIOS =oxff,the output of PJ4 is 0.however when the TIOS=oxff is removed,the  output  of PJ4 is 5v(OK).2.6v is not appear.

0 Kudos

937 Views
kef2
Senior Contributor IV

Hi Liu Feng,

It's quite difficult to understand your problem description.

First of all PJ4 pin has no connection with timer on S12G. To see some change on PJ4 while toggling TIOS bits it must be some external connection which ties some of timer pin with PJ4. Are you sure your project is set up for S12G128 and not for some other derivative? For example S12GC128 is quite different MCU.

By default enabling timer compare writing TIOS bit =1 turns on corresponding pin output buffer. To keep output pin not driven while timer compare is enabled you need to set corresponding bit in OCPD (pin disconnect) register.

Edward

0 Kudos