PWM doesn't work

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
2,260件の閲覧回数
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,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 件の賞賛
返信
4 返答(返信)
1,621件の閲覧回数
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,623件の閲覧回数
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,621件の閲覧回数
Pivson
Contributor II

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

 

Thank you ! :smileyhappy:

 

P.

0 件の賞賛
返信
1,621件の閲覧回数
Pivson
Contributor II

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

 

P.

0 件の賞賛
返信