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.
Solved! Go to Solution.
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
Sorry, there was typo, it should be:
TPM2SC =0b00001000;
TPM2MOD=256;
TPM2C0SC=0b00101000; // (MSnB:MSnA ELSnB:ELSnA=10 10)
TPM2C0VL=10;
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
It was the problem. I didn't saw, it's 16bit register...
Thank you !
P.
There is a typo, I am addressing just L byte of 16bit compare value. That's all
P.