For simlicuty, lets say I need to use two channels from the same TPM. Not at the same time.
CH0: capturing (from sensor)
CH1: pwm out (to buzzer)
I could initialise TPM1 as follow:
TPM1SC = 0x17;
TPM1C0SC = 0x44;
TPM1C1SC = 0x38;
I am able to use Interrupt for TPM1CH0 for capturing some data from sensor (data coming in microsecond intervals). This part working fine.
But then, for some uncertain reason, I cannot change TPM1MOD from zero to anything else to produce PWM signal. As well I can't write to TPM1CH1V. It just ignore anything I try to put there. However, buzzer could produce some sounds after long period of time. Then I am able turn it OFF (TPM1SC=0) and ON (TPM1SC=0x17). Its a mistery why its working in that manner.
Any ideas, what is wrong in theory ?