Monday, 30 June 2008

Pulse Width Modulation (PWM) with Rabbit 3000 MCU

PWM (Pulse Width Modulation) ကို ေနာက္ပိုင္း MCU ေတြမွာ ေတာ္ေတာ္ေတြ႕လာရပါတယ္။ ကၽြန္ေတာ္အခုျပမွာက Rabbit 3000 နဲ႔ပါ။ အရင္ကၽြန္ေတာ္သံုးခဲ့တဲ့ MCU ေတြ Cygnal, NEC, ARM မွာ ဒီ function မပါတဲ့အတြက္ Timer ေတြ၊ Interrupt ေတြနဲ႔ ႐ႈပ္ေနေအာင္တြက္ရ ေရးခဲ့ရပါတယ္။ ၿပီးေတာ့ Time interval တိက်မႈလည္း မရွိပါဘူး။ ဒီ PWM function ကေတာ့ interval တိက်မႈရွိတဲ့အျပင္ Duty Cycle ကိုလည္း လိုအပ္သလို (%) နဲ႔ထုတ္ေပးလို႔ရပါတယ္။ တကယ္ေတာ့ MCU ေတြရဲ႕အားသာခ်က္ပါသလို compiler (core module) ေတြရဲ႕စြမ္းရည္ကလည္း အရမ္းျမင့္လာလို႔ပါ။ ဒီမွာ pwm_set ၄ ခါေရးရတာကေတာ့ Rabbit 3000 မွာ PWM Channel ၄ ခုပါတဲ့အတြက္ျဖစ္ပါတယ္။ Duty cycle တစ္မ်ိဳးစီနဲ႔ ေရးျပထားတာပါ။

void main()
{
unsigned long freq;
int pwm_options;

// request 10kHz PWM cycle (will select closest possible value)
freq = pwm_init(10000);
printf("Actual PWM frequency = %d Hz\n", freq);
pwm_options = 0;
pwm_set(0, 0.10 * 1024, pwm_options);

pwm_set(1, 0.25 * 1024, pwm_options);
pwm_set(2, 0.50 * 1024, pwm_options);
pwm_set(3, 0.99 * 1024, pwm_options);
while(1); //keep running the program

}


No comments:

Post a Comment