Search This Blog

Showing posts with label Timer. Show all posts
Showing posts with label Timer. Show all posts

Thursday, June 10, 2010

Soft-Timer Module for 8051 Microcontroller

Embedded system အားလုံးလိုလို မှာ timer တွေကို သုံးကြပါတယ်။ 8051 microcontroller မှာ hardware timer နှစ်ခု၊ သုံးခု ပဲ ပါတဲ့ အတွက် ပုံမှန် system တစ်ခု အတွက် လိုအပ်တဲ့ timer အားလုံးကို hardware timer တွေပဲ သုံးပြီး ရေးမယ် ဆိုရင် လုံလောက်မှာ မဟုတ်ပါဘူး။ ဒါကြောင့် သိပ်ပြီး တိကျဖို့ မလိုတဲ့ timer တွေကို ရေးတဲ့အခါ software ကိုပဲ သုံးပါတယ်။ ဒီမှာ ကျွန်တော် ရေးထားတဲ့ soft-timer module လေး တစ်ခု အကြောင်း ကို ပြောချင်ပါတယ်။ သူ့ကို 8051 microcontroller အတွက် ရေးထားတာ ဖြစ်ပေမယ့် တစ်ခြား microcontroller တွေ အတွက်ဆိုရင် လဲ အလွယ်တစ်ကူ ပြောင်းသုံးလို့ ရပါတယ်။
နမူနာ source code ကို

UART-Timer-8051 on GitHub

မှာရယူ နိုင်ပါတယ်။

Using soft-timer module

သူ့ကို သုံးချင်တဲ့ module မှာ ထုံးစံ အတိုင်း header file ကြေငြာဖို့ လိုပါတယ်။ ကျွန်တော့် နမူနာ မှာတော့ header အားလုံးကို 'headers.h' ဖိုင်ထဲမှာ စုထားတဲ့ အတွက် အဲဒီဖိုင်ကို ထည့်လိုက်ရုံ ပါပဲ။
Timer က သတ်မှတ်ချိန် ကုန် လို့ time out ဖြစ်ရင် လုပ်ချင်တဲ့ function ရယ်၊ timer ရဲ့ အချိန် သတ်မှတ်ဖို့၊ timer စတင်ဖို့ အတွက် function များကိုရေးပါ။ ကျွန်တော့် နမူနာ မှာတော့ SysSBYLEDTmrTO() နဲ့ SysSBYLEDInit() တို့ကို System.c module ထဲမှာ ရေးထားပါတယ်။
TmrConfig.h ဖိုင်ကို ဖွင့်ပြီး အဲဒီမှာ ရှိတဲ့ အဆင့် သုံးဆင့် ကို လုပ်ဖို့ လိုပါတယ်။ သင့် compiler က function pointers တွေကို သုံးလို့ မရရင် switch structure နဲ့ ပြောင်းသုံး နိုင်ပါတယ်။
main function ထဲမှာ initialize လုပ်ဖို့ TmrInit() နဲ့ ပုံမှန် poll လုပ်နေဖို့ TmrTask() တွေကို ခေါ်ဖို့ လို့ပါတယ်။ သူတို့ကို Tmr.c ထဲမှာ ရေးထားပါတယ်။

Tuesday, February 2, 2010

VB2005 Timers

The .NET Framework ထဲမှာ သုံးစရာ timer အမျိုးမျိုး ရှိပါတယ်။ Windows Forms applications တွေမှာ ဆိုရင် System.Windows.Forms.Timer control ကို သုံးနိုင်ပြီး user interface မရှိတဲ့ application မှာ ဆိုရင်တော့ System.Threading.Timer class ဒါမှမဟုတ် the System.Timers.Timer class ကို သုံးနိုင်ပါတယ်။ အောက်မှာ ပြထားတဲ့ နမူနာ မှာ System.Threading.Timer class ကို သုံး ပြီး procedure တစ်ခုကို ခေါ်သုံးထား ပါတယ်။ Timer ကို စပြီးတာ နဲ့ သူ့ရဲ့ တန်ဖိုးတွေကို ပြောင်းချင်ရင် Change method ကိုသုံးပြီးမှ ပြောင်းလို့ ရပါတယ်။ Stop method မရှိပါဘူး။ ရပ်ချင်ရင် Dispose method ကိုသုံးမှ ရပါမယ်။
Imports System.Threading
Dim dueTime as New TimeSpan(0,0,1)
Dim period as New TimeSpan(0,0,0,0,500)
Dim t As New Timer(AddressOf TimerProc, Nothing, dueTime, period)
Dim tEn As Boolean = True
Private Sub TimerProc(ByVal state As Object)
 If tEn = True Then
'Do timer things
 End If
End Sub