全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2089
推到 Plurk!
推到 Facebook!

請問研華的USB4711的PWM輸出怎麼使用????

尚未結案
hop75217
一般會員


發表:3
回覆:1
積分:0
註冊:2009-08-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-08-20 16:56:53 IP:140.121.xxx.xxx 訂閱
我RUN範例程式後用三用電表卻量不到輸出   不知道是不能這樣做 還是我少了什麼步驟 請高手們幫幫我吧!!!

以下是她付的範例程式



PulsePWM
//---------------------------------------------------------------------------
#include
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("PWMForm.cpp", frmMain);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TfrmMain), &frmMain);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------



------------------------------------------------------------------------------------------------------------------------


PWMForm
//---------------------------------------------------------------------------
/*
Program: PWM
Description: BCB Demo program for PWM output
Version: 1.0
Date: 08/29/02 Advantech. Co., Ltd.
*/
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include (PWMForm.h)
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
//This function is for getting the device number
if(1 == DRV_SelectDevice(Handle, True, (ULONG*)&lDeviceNum, szDescription)){
Application->MessageBoxA("Can not Open Select Device Dialog", "Error");
btnExitClick(Sender);
}
labDeviceName->Caption = AnsiString(szDescription);
//open device
ErrCde = DRV_DeviceOpen(lDeviceNum, (LONG far *) &lDriverHandle);
if (ErrCde != SUCCESS){
strcpy(szErrMsg,"Device open error !");
Application->MessageBoxA((char* )szErrMsg,"Device Open");
return;
}
//get device features
ptDevGetFeatures.buffer = (LPDEVFEATURES )&DevFeatures;
ptDevGetFeatures.size = sizeof(DEVFEATURES);
ErrCde = DRV_DeviceGetFeatures(lDriverHandle, (PT_DeviceGetFeatures*)&ptDevGetFeatures);
if (ErrCde != SUCCESS){
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
Application->MessageBoxA((LPCSTR)szErrMsg,"Driver Message");
DRV_DeviceClose((LONG far *)&lDriverHandle);
return;
}
//record some device specific parameters
dwBoardID = DevFeatures.dwBoardID;
usMaxCntNum = DevFeatures.usMaxTimerChl;
//updata UI
cmbChannel->Clear();
for(int i=0; i cmbChannel->Items->Add(AnsiString(i));
}
cmbChannel->ItemIndex = 0;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnSelectDeviceClick(TObject *Sender)
{
FormCreate(Sender);
}
//---------------------------------------------------------------------------




void __fastcall TfrmMain::btnExitClick(TObject *Sender)
{

Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::txtPeriod0Exit(TObject *Sender)
{
//Check the validation of input data
if(txtPeriod0->Text.ToDouble()-0.0005<-10e-10 || txtPeriod0->Text.ToDouble()>60){
Application->MessageBoxA("The value is out of bound","Warning");
}
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::txtHiPeriod0Exit(TObject *Sender)
{
if((txtHiPeriod0->Text.ToDouble()-0.0005 < -10e-10)|| txtHiPeriod0->Text.ToDouble()>=txtPeriod0->Text.ToDouble()){
Application->MessageBoxA("The value must no less than 0.0005 and no greater than the period time","Warning");
}
}
//---------------------------------------------------------------------------



void __fastcall TfrmMain::btnRunClick(TObject *Sender)
{
LRESULT ErrCde;
char szErrMsg[80];
ErrCde = DRV_DeviceOpen(lDeviceNum, (LONG far *) &lDriverHandle);
if (ErrCde != SUCCESS){
strcpy(szErrMsg,"Device open error !");
Application->MessageBoxA((char* )szErrMsg,"Device Open");
return;
}
ptDevGetFeatures.buffer = (LPDEVFEATURES )&DevFeatures;
ptDevGetFeatures.size = sizeof(DEVFEATURES);
ErrCde = DRV_DeviceGetFeatures(lDriverHandle, (PT_DeviceGetFeatures*)&ptDevGetFeatures);
if (ErrCde != SUCCESS){
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
Application->MessageBoxA((LPCSTR)szErrMsg,"Driver Message");
DRV_DeviceClose((LONG far *)&lDriverHandle);
return;
}
if (0 == DevFeatures.usMaxTimerChl){
Application->MessageBoxA((LPCSTR)"No Counter Channel","Driver Message");
DRV_DeviceClose((LONG far *)&lDriverHandle);
return;
}
//start counter
ptCounterPWMSetting.Port = cmbChannel->Text.ToInt();
ptCounterPWMSetting.Period = txtPeriod0->Text.ToDouble();
ptCounterPWMSetting.HiPeriod = txtHiPeriod0->Text.ToDouble();
ptCounterPWMSetting.GateMode = 0;
ptCounterPWMSetting.OutCount = txtOutCount->Text.ToInt(); //no use here
ErrCde = DRV_CounterPWMSetting(lDriverHandle, (LPT_CounterPWMSetting)&ptCounterPWMSetting);
if (ErrCde != SUCCESS){
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
Application->MessageBoxA((char*)szErrMsg, "Driver Message");
return;
}
ErrCde = DRV_CounterPWMEnable(lDriverHandle,cmbChannel->Text.ToInt());
if(ErrCde != SUCCESS){
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
Application->MessageBoxA((char* )szErrMsg, "Driver Message");
return;
}

btnRun->Enabled = False;
btnStop->Enabled = True;
btnExit->Enabled = False;
grpDevSelect->Enabled = False;
btnSet->Enabled = True;
txtOutCount->Enabled = False;
}
//---------------------------------------------------------------------------

void __fastcall TfrmMain::btnStopClick(TObject *Sender)
{
LRESULT ErrCde;
char * szErrMsg[80];
ErrCde = DRV_CounterReset(lDriverHandle, cmbChannel->Text.ToInt());
if(ErrCde != SUCCESS){
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
Application->MessageBoxA((char*)szErrMsg, "Driver Message");
}
DRV_DeviceClose((LONG far*)&lDriverHandle);
btnExit->Enabled = True;
btnRun->Enabled = True;
btnStop->Enabled = False;
grpDevSelect->Enabled = True;
btnSet->Enabled = False;
txtOutCount->Enabled = True;
}
//---------------------------------------------------------------------------


void __fastcall TfrmMain::btnSetClick(TObject *Sender)
{
if(ptCounterPWMSetting.OutCount != 0)
{
Application->MessageBoxA("Can't change setting in noncyclic mode", "Driver Message");
return;
}
ptCounterPWMSetting.Port = cmbChannel->Text.ToInt();
ptCounterPWMSetting.Period = txtPeriod0->Text.ToDouble();
ptCounterPWMSetting.HiPeriod = txtHiPeriod0->Text.ToDouble();
ptCounterPWMSetting.GateMode = 0;
ptCounterPWMSetting.OutCount = txtOutCount->Text.ToInt(); //no use here
ErrCde = DRV_CounterPWMSetting(lDriverHandle, (LPT_CounterPWMSetting)&ptCounterPWMSetting);
if (ErrCde != SUCCESS){
DRV_GetErrorMessage(ErrCde,(LPSTR)szErrMsg);
Application->MessageBoxA((char*)szErrMsg, "Driver Message");
return;
}
}
//---------------------------------------------------------------------------
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-08-20 17:01:08 IP:122.116.xxx.xxx 訂閱
PWM的輸出用三用電表量? 應該用示波器吧^^|
系統時間:2024-12-04 1:21:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!