PWM doesn't work

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

PWM doesn't work

Jump to solution
1,666 Views
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.

Labels (1)
0 Kudos
Reply
1 Solution
1,028 Views
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

 

View solution in original post

0 Kudos
Reply
4 Replies
1,027 Views
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 Kudos
Reply
1,029 Views
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 Kudos
Reply
1,027 Views
Pivson
Contributor II

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

 

Thank you ! :smileyhappy:

 

P.

0 Kudos
Reply
1,027 Views
Pivson
Contributor II

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

 

P.

0 Kudos
Reply