CLR PADR LD A,#$0F LD PADDR,A LD A,#$FF LD PAOR,A CLR PBDR LD A,#0 ;#$7 LD PBDDR,A LD A,#0 ;#$7 LD PBOR,A LD A,#$0C LD ATRH,A LD A,#$0E0 LD ATRL,A ;PWM frequ0K LD A,#2 LD PWM0CSR,A LD A,#$10 ;fcpu= 8MHZ LD ATCSR,A BSET PWMCR,#0 ;Enable loop: LD A,#$0F LD DUTY_H,A LD DUTY_L,A LD A,DUTY_H LD DCR0H,A LD A,DUTY_L LD DCR0L,A JRA loop The problem is the PWM output frequency in the oscilliscope is not stable, it change between 9.8K and 4.9K. I don't know why. could anyone help me to explain it. Best Regards, mcuinterest
you are right, now I update the duty cyle in the overflow interrupt subroutine of auto reload timer. but the problem(PWM output wave form is not very stable) still exists in some duty cyle point(8%-12% around). I don't know why I guess it is because the DCR and ATR are very close. Just like the suggestion in the datasheet, the DCRx register shouldbe updated just before an OVF event, in order not to miss a compare event and to have the right signal applied on the PWM output. But I don't know how to update the DCR value befor OVF envent. can anyone help me!. Best Regards, mcuinterest