在线时间0 小时
UID132782
注册时间2009-6-4
NXP金币0
该用户从未签到
新手上路

- 积分
- 20
- 最后登录
- 1970-1-1
|
As a customer of freescale Co. for long time ,I have tried to develop a item which was related to the model
of TPM2 at the DEMO9S08DZ60. I want to realize a PWM with edentulous rectangle wave.namely ,58 rectangle
wave and two teeth missing .make up one period.I have paid so much time for debugging .There got nothing
but to get puzzled,the ondoscope showed a PWM with 3 teeth missing . Obviously ,I wrote a C program to realize
a PWM with two teeth missing,but got 3 teeth missing.Then,I wrote another program in order to get a PWM with
one tooth missing,but got 2 teeth missing. I was puzzled for a long time.
I used the single chip of MC9S08DZ60 .There is the program below:
//****************************************************
#include
#include "derivative.h"
volatile unsigned char CrankNum;
//volatile unsigned char CamNum;
volatile unsigned int ModValCalc;
volatile unsigned int ChanlValCalc;
//****************************************************
void Init_tpm2_ch0_edge_pwm(void);
//****************************************************
void main(void)
{
CrankNum = 0;
// CamNum = 0;
ModValCalc = 0x08c9;
ChanlValCalc = 0x0465;
void Init_tpm2_ch0_edge_pwm();
TPM2CNTH = 0;
EnableInterrupts;
for(;;)
{
_RESET_WATCHDOG();
}
}
//****************************************************
void Init_tpm2_ch0_edge_pwm(void)
{
TPM2MODH = (unsigned char)(ModValCalc>>8);
TPM2MODL = ModValCalc & 0xFF;
TPM2C0VH = (unsigned char)(ChanlValCalc>>8);
TPM2C0VL = ChanlValCalc & 0xFF;
TPM2C0SC = 0x28;
TPM2SC = 0x4F; // div by 128 , bus clk ISR enable.
}
//****************************************************
interrupt VectorNumber_Vtpm2ovf void TPM2_OVF_ISR(void)
{
// volatile char cam_pos;
if((TPM2SC & 0x80) == 0x80)
{
TPM2SC_TOF = 0;
++CrankNum;
switch(CrankNum)
{
case 58 : TPM2C0VH = 0x00; //the 59th tooth position is a missing tootn
TPM2C0VL = 0x00;
break;
case 118 : TPM2C0VH = 0x00; //the 118th tooth position is a missing tootn TPM2C0VL = 0x00;
break;
case 120 : CrankNum = 0x00; TPM2CNTH = 0x00;
break;
case 59 : TPM2C0VH = (unsigned char)(ChanlValCalc>>8);
TPM2C0VL = ChanlValCalc & 0xFF;
break;
case 119 : TPM2C0VH = (unsigned char)(ChanlValCalc>>8); TPM2C0VL = ChanlValCalc & 0xFF;
break;
default: break;
}
}
}
//****************************************************
During the ISR function of "TPM2_OVF_ISR(void)" , I made a arithmetic for the program to get the PWM with one teeth missing ,but got two teeth missing.
I need help ,thanks
|
|