中级会员
- 积分
- 284
- 威望
- 142
- 贡献
- 78
- 兑换币
- 88
- 注册时间
- 2014-2-23
- 在线时间
- 32 小时
|
void PWM_Init( void )
{
SIM_SCGC5=SIM_SCGC5_PORTA_MASK;
PORTA_PCR4&=~(PORT_PCR_MUX_MASK);
PORTA_PCR4|= PORT_PCR_MUX(3);
GPIOA_PDDR|=(1<<4);
SIM_SCGC6|= SIM_SCGC6_FTM0_MASK;
FTM0_MODE=7;
FTM0_CNTIN=0x0;
FTM0_CNT=0x0;
FTM0_MOD=0Xbb7;//2999
FTM0_C1SC=0X28;
FTM0_C1V=500;//
FTM0_SYNC=0x84;
FTM0_OUTINIT=0X02;
FTM0_COMBINE|=(1<<5);
FTM0_SC=0X08;
}
void PWM_sync_set(unsigned int mod,unsigned int value)
{
int reg,M;
FTM0_MODE=7;
FTM0_SYNC|=0<<7;
FTM0_SYNC|=1<<7;
FTM0_CNTIN=0;
FTM0_CNT=0;
FTM0_MOD=0;
FTM0_C1V=0;
FTM0_MOD=mod;
FTM0_C1V=value;
reg=FTM0_SYNC;
while((reg&0x80)==0x80){
FTM0_SYNC&=(~(1<<7));
reg=FTM0_SYNC;
}
PORTA_PCR15|=0X0;
PORTA_PCR15|=(1<<8);
GPIOA_PDDR|=(1<<15);
GPIOA_PDOR=(1<<15);
}
int i;
void main(){
SIM_SCGC5 |=SIM_SCGC5_PORTA_MASK;
PORTA_PCR15|=0X0;
PORTA_PCR15|=(1<<8);
GPIOA_PDDR|=(1<<15);
GPIOA_PDOR|=(0<<15);
PWM_Init();
for(i=0;i<10000000;i++){};
PWM_sync_set(2999,1500);
for(i=0;i<10000000;i++){}
}我设置了几个断点查看变量值,发现FTM0_MOD,FTM0_C1V的值是我初始化时的值,不随 PWM_sync_set(2999,1500)设置的值而改变·
|
|