Content originally posted in LPCWare by Rob65 on Thu Jul 07 07:55:42 MST 2011
Yes!
and I thought I was going mad :p
The content of the match registers is latched into the shadow registers on a reset of the counter.
But ... There is a bit in the PWM Timer Control Register called "PWM Enable".
That name is absolutely misleading!!!
PWM is also enabled when this bit is 0 but, as stated in the UM (section 24.6.2):
Quote:
PWM mode is enabled (counter resets to 1). PWM mode causes the shadow
registers to operate in connection with the Match registers. A program write to a
Match register will [COLOR=Red][B]not have an effect[/B][/COLOR] on the Match result [B][COLOR=Red]until the corresponding bit
in PWMLER has been set[/COLOR][/B], followed by the occurrence of a PWM Match 0 event.
Note that the PWM Match register that determines the PWM rate (PWM Match
Register 0 - MR0) must be set up prior to the PWM being enabled. Otherwise a
Match event will not occur to cause shadow register contents to become effective.
Thinking of this strange behaviour I discovered why this is being done:
When you set new values for multiple MRx registers, you then write ones in the PWMLER and then all values are changed simultaneously changed at the next MR0 match event.
If, like me, you are just using the PWM to control things like LEDs you can just leave the PWM_EN bit set to 0. In that case there is no need to write ones into the PWMLER register, now the value of the MRx register is taken over at the next reset of the counter.
So the complete answer is (correct me if I am wrong):
[LIST=1]
[*]When PWM_EN = 0, the altered values become effective when the counter reaches 0
[*]When PWM_EN = 1, the altered values become effective only when the PWMLER bits aer set [I]and[/I] a PWM MR0 match event occurs
[/LIST]
This again shows how carefull you have to be when reading, and interpreting, the UM - even I make mistakes :D
Rob