PWM doesn't work

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

PWM doesn't work

跳至解决方案
2,259 次查看
Pivson
Contributor II

Hello, I am having trouble with PWM  @ AW16 CPU. Device is selfcloked, 20MHz BUS. I am having following code:

 

    TPM2SC =0b00001000;
    TPM2MOD=256;

    TPM2C0SC=0b00010100;
    TPM2C0VL=10;

 

So, edge aligned high pulse PWM.

 

This doens't produce and output at TPM2CH0 pin. Pin is log0 for all the time. TPM2 is running properly (TPM2CNT cycles 0-255).

 

If I change channel mode to TPM2C0SC=0b00010110; which is low pulses, pin is logic zero and after first cycles goes to high and keeps high.

 

When I change mode to TPM2C0SC=0b00010100; which is toggle output on compare, pin in CPU starts doing PWM as expected.

 

What I am doing wrong ? Why PWN doesn't work and toggle on compare works ?

 

Thank you

 

P.

标签 (1)
0 项奖励
回复
1 解答
1,621 次查看
bigmac
Specialist III

Hello,

 

I am not sure whether you already found your problem.  The TPM module has a coherency mechanism that requires that both high and low bytes be written to TPM2C0V before the register becomes updated with the new value.

 

TPM2C0V = 10;  // This should update both high and low bytes

 

The TPM2MOD value in the example will give a period of 257 TPM clock cycles for overflow.  If you actually require a PWM period of 256 clock cycles, you should use the setting:

 

TPM2MOD = 255;  // This gives TPM overflow period of 256 cycles

 

Regards,

Mac

 

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,620 次查看
Pivson
Contributor II

Sorry, there was typo, it should be:

 

    TPM2SC =0b00001000;
    TPM2MOD=256;

    TPM2C0SC=0b00101000;  //  (MSnB:MSnA ELSnB:ELSnA=10 10)
    TPM2C0VL=10;

0 项奖励
回复
1,622 次查看
bigmac
Specialist III

Hello,

 

I am not sure whether you already found your problem.  The TPM module has a coherency mechanism that requires that both high and low bytes be written to TPM2C0V before the register becomes updated with the new value.

 

TPM2C0V = 10;  // This should update both high and low bytes

 

The TPM2MOD value in the example will give a period of 257 TPM clock cycles for overflow.  If you actually require a PWM period of 256 clock cycles, you should use the setting:

 

TPM2MOD = 255;  // This gives TPM overflow period of 256 cycles

 

Regards,

Mac

 

0 项奖励
回复
1,620 次查看
Pivson
Contributor II

It was the problem. I didn't saw, it's 16bit register...

 

Thank you ! :smileyhappy:

 

P.

0 项奖励
回复
1,620 次查看
Pivson
Contributor II

There is a typo, I am addressing just L byte of 16bit compare value. That's all :smileyhappy:

 

P.

0 项奖励
回复