📄 pulse.c
字号:
/*
'**********************************************************************
'* Program : Pulse.c *
'* Revision : 1.00 *
'* Date : 6/24/2002 Arbor Technology Corp. *
'*====================================================================*
'* *
'* This program demonstrates the Pulse out funciton of pDAQ-722. *
'* pDAQ-722 counter 0 supports this feature. *
'* *
'**********************************************************************
*/
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include "PCI.C"
#include "pDAQ722.h"
#define TIME_BASE 4*1000000 //4Mhz chrystral
#define FREQ_MIN ((TIME_BASE+65535) / 65536)
#define FREQ_MAX 4000
#define STR_FREQ_OUT "Pulse out frequency: "
void main(void)
{
word wVendorId, wDeviceId, wIndex;
int iScanKey, iErrCode, iFreqVal;
byte ucBusNumber, ucDevAndFunc;
dword dwData, dwBaseAddr;
word wCount;
wVendorId = VENDOR_ID;
wDeviceId = DEVICE_ID;
// Description, Pulse out funciton Jumper setting and pins position
clrscr();
printf("Arbor Technology Corp.\n\n");
printf("Pulse Out demo program.\n");
printf("The isolation pulse out use %dKHz clock base, and\n", (int)(TIME_BASE / 1000));
printf("generates %d - %d Hz pulse.\n\n", (int)FREQ_MIN, (int)FREQ_MAX);
printf("Before running this program you should:\n");
printf("1. Check pDAQ-722 JP9 pin2,3 shorted.\n");
printf("2. Pulse out signal presents on TOUT_L0 (pin 33) and TOUT_H0(pin15).\n\n");
/***************************
* Get pDAQ-72x's resource
***************************/
//
// Search pDAQ-72x
//
for( wIndex=0; wIndex < 32; wIndex++)
{
iErrCode = find_pci_device(
wDeviceId,
wVendorId,
wIndex,
&ucBusNumber,
&ucDevAndFunc );
if (iErrCode == NOT_SUCCESSFUL )
{
printf("\n pDAQ-720/722 search fail.\n");
exit(1);
}
iErrCode = read_configuration_dword(
ucBusNumber,
ucDevAndFunc,
PCI_CS_SUBSYSTEM_ID,
&dwData);
if(dwData == SUBSYSTEM_ID)
break;
}
//
//Get base address, from PCI base address range 2
//
iErrCode = read_configuration_dword(
ucBusNumber,
ucDevAndFunc,
PCI_CS_BASE_ADDRESS_2,
&dwData);
if (iErrCode == NOT_SUCCESSFUL)
{
printf("\npDAQ-72x gets base address failure.\n");
exit(1);
}
else
dwBaseAddr = dwData & 0xfffffffc;
/*******************
* Counter 0 setting
*******************/
/******************************
* Config counter to start event counting function.
*
* Base + 0xb, control register, standard mode
* bit# 7 6 5 4 3 2 1 0
* value SC1 SC2 RW1 RW0 M2 M1 M0 BCD
*
* SC1 SC0 Select Counter | RW1 RW2 Select R/W operation
* 0 0 0 | 0 0 Counter latch
* 0 1 1 | 0 1 Read/write LSB
* 1 0 2 | 1 0 Read/write MSB
* 1 1 Read-back comand | 1 1 R/W LSB first then MSB
*
* M2 M1 M0 Mode
* 0 0 0 0 Stop on terminal count
* 0 0 1 1 Programable one shot
* 0 1 0 2 Rate generate
* 0 1 1 3 Square wave generator
* 1 0 0 4 Software triggered strobe
* 1 0 1 5 Hardware triggered strobe
******************************/
outportb(dwBaseAddr+0xb, 0x36); // Counter 0, R/W LSB first then MSB,
// Rate generate, Binary.
iFreqVal = (FREQ_MAX+FREQ_MIN) / 2; // default pulse frequency
wCount = TIME_BASE / iFreqVal;
outportb(dwBaseAddr+0x8, wCount & 0xff); //LSB first
outportb(dwBaseAddr+0x8, (wCount >> 8) & 0xff); //MSB next
/***************
* Cyclic change current pulse frequency
***************/
printf("Press Up, down, Left, Reiht arrow keys to change pulse out frequency.\n");
printf("Press other keys to stop program.\n\n");
printf(STR_FREQ_OUT);
printf("%dHz", iFreqVal);
iScanKey = 1;
while(iScanKey)
{
if(kbhit())
{
if( getch() == 0)
{
iScanKey = getch();
switch(iScanKey)
{
case 0x48:
iFreqVal += 10;
break;
case 0x4d:
iFreqVal += 1;
break;
case 0x4b:
iFreqVal -= 1;
break;
case 0x50:
iFreqVal -= 10;
break;
}
if(iFreqVal > FREQ_MAX)
iFreqVal = FREQ_MAX;
else if(iFreqVal < FREQ_MIN)
iFreqVal = FREQ_MIN;
//Write new value to counter 0
wCount = TIME_BASE / iFreqVal;
outportb(dwBaseAddr+0x8, wCount & 0xff); //LSB first
outportb(dwBaseAddr+0x8, (wCount >> 8) & 0xff); //MSB next
// Display on screen
gotoxy( sizeof(STR_FREQ_OUT), wherey());
printf("%dHz ", iFreqVal);
}
else
iScanKey = 0;
}
}
}//Main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -