Nuvoton 8051 Pwm issue.

Post Reply
yoonts
Posts: 2
Joined: 23 Feb 2018, 15:44

25 Feb 2018, 18:24

My mcu is N76E003.

I need two pwm mode(periode).
One is 50% duty in 1khz for fan.
The other is 50% in 2.7khz for buzzer.

Is it possible?

jmg
Posts: 13
Joined: 15 Apr 2017, 10:19

26 Feb 2018, 13:53

My mcu is N76E003.

I need two pwm mode(periode).
One is 50% duty in 1khz for fan.
The other is 50% in 2.7khz for buzzer.

Is it possible?
Yes, if you search the data, as well as the 16b PWM module, it says

"The Timers 0 and 1 can be configured to automatically toggle a port output whenever a timer overflow occurs. The same device pins that are used for the T0 and T1 count inputs are also used for the timer toggle outputs. This function is enabled by control bits T0OE and T1OE in the P2S register, and apply to Timer 0 and Timer 1 respectively."

Timer0/1 has choice of 8b reload, or 16b mode, (with SW preload possible).
Lowest speed at 16MHz is 16M/12/256 = 5208.333 Hz toggle rate, or a lowest Freq of = 2604.166 Hz ( for 2.7k, you select 16M/12/247/2 = 2699.055Hz)
If you need below 2604Hz, or a change from 50% duty, you could run 16b mode toggle, and add an offset preload TH0,TL0 on every interrupt, for a modest CPU loading.
At 16MHz and no prescaler, Interrupt would add 0xF46D to give ~ 2699.966Hz; With no interrupt adder, you will output ~122Hz

(ie you might want to adjust kHz and PWM to vary the buzzer message alerts to user.
Because the FAN is less noticeable to a user, you might choose to use Timer0.1 for Fan, and the more flexible PWM for Buzzer.
Interrupt adder formula for 1Khz is : 16M/(2^16-0xE0C0)/2 = 1000 Hz

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests