SN8P275X Series
8-bit micro-controller build-in 12-bit ADC
SONiX TECHNOLOGY CO., LTD
Page 108
Version 0.7
If TC0R is changing in the program processing, the PWM waveform will became as following diagram.
1
1st PWM
2
Update PWM Duty
3
2nd PWM
4
Update PWM Duty
TC0C Value
PWM0 Output
Period
5
3th PWM
TC0C overflow
and TC0IRQ set
Old TC0R
Old TC0R
New TC0R
New TC0R
Update New TC0R!
Old TC0R < TC0C < New TC0R
Update New TC0R!
New TC0R < TC0C < Old TC0R
TC0C > = TC0R
PWM High > Low
TC0C < TC0R
PWM Low > High
0xFF
0x00
In period 2 and period 4, new Duty (TC0R) is set, but the PWM output waveform of period 2 and period 4 are wrong. In
period 2, the new TC0R value is greater than old TC0R value. If setting new TC0R is after PWM output “low”, system is
getting TC0C < TC0R result and making PWM output “high”. There are two high level periods in the cycle, and the
waveform is unexpected. Until next cycle, PWM outputs correct duty. In period 4, the new TC0R value is smaller than
the old TC0R value. If setting new TC0R is before PWM output “low”, system is getting TC0C
≧
TC0R result and
making PWM output “low”. In the cycle, the high duty is shorter than last cycle and longer than correct cycle. It is an
unexpected PWM output.
Though the wrong waveforms only exist in one cycle, it is still a problem for precise PWM application and might make
outside loading operations error. The solution is to load new TC0R after TC0 timer overflow. Using TC0IRQ status to
determine TC0 timer is overflow or not. When TC0IRQ becomes “1”, to set the new TC0R value into TC0R buffer, and
the unexpected PWM output is resolved.
¾
Example: Using TC0 interrupt function to set new TC0R value for changing PWM duty.
MAIN:
…
B0MOV
TC0RBUF, A
; Load new PWM duty setting value into TC0RBUF.
…
…
INT_SER:
…
; Push routine to save ACC and PFLAG to buffers.
…
B0BTS1
FTC0IRQ
JMP
INT_SER90
B0MOV
A, TC0RBUF
; When TC0 Interrupt occurs, update TC0R.
B0MOV
TC0R,
A
…
…
INT_SER90:
…
; Pop routine to load ACC and PFLAG from buffers.
RETI