⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console_pci2.cpp

📁 msp430F413用DS18B20测温
💻 CPP
字号:
// console_pci2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "atmd_pci.h"
#include "conio.h"
#include "console_pci2.h"
#include "math.h"
#include "winbase.h"

#include "stdio.h"

void writeRegQuiet ( WORD, int, DWORD);


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int mc(WORD);

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
  int nRetCode;
  int i,iBoardCount;
  char ch;
  WORD atmd_pci_base_address[10],base;
  BOOL AtmdOK = FALSE, quit = FALSE;
  DWORD dwTemp;


  //  Your variables
  WORD  N0,N1,hits, TEF;
  DWORD FIFO0[1000], FIFO1, FIFOM, Max, Min;
  float FIFOE,FIFOA;


	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
    // **************************************************************** 
	// ************* Start of application code ************************
	// detect ATMD PCI (call GetATMDPCIBoardCount() to detect number of ATMD-PCI boards)
		
		iBoardCount = GetATMDPCIBoardCount();
		printf("No. of ATMD PCI boards found = %d\n",iBoardCount);
		
		i=0;
		while((!AtmdOK) || (i>4))
		{
			AtmdOK = GetATMDPCIBaseAddr(i,dwTemp);
			atmd_pci_base_address[i] = (WORD) dwTemp;
			i++;
		}
		if (AtmdOK)
		{
			printf("ATMD PCI Board found on 0x%x\n",atmd_pci_base_address[i-1]);
			base = atmd_pci_base_address[i-1];  		// base = base address 
			if(!EnablePortAccess())
			{
				AfxMessageBox("Giveio.sys couldn't be opened");
			}
		}
		else
		{
			AfxMessageBox("ATMD-PCI interface not found");
		}
	
    }  
	//  ******************** board-reset ******************

	
	if(!EnablePortAccess())
	{
			AfxMessageBox("Giveio.sys couldn't be opened");
	}

	_outpw(base+0xC,0x0101);
	Sleep(1);
	_outpw(base+0xC,0x0000);

//  *********************** Your Code ********************************************************

	
	// ****************** Setup ***************************
	//                     _LSB                  ___Address
	//                    |                     | _____MSB 
	//                 ...|                     ||..
	_outpw(base+0x0, 0x008B);_outpw(base+0x2, 0x0000);//Reg 0, 000008B	Start ring oscillator, enable rising edges
	_outpw(base+0x0, 0x0620);_outpw(base+0x2, 0x1062);//Reg 1, 0620620	Channel adjust
	_outpw(base+0x0, 0x2004);_outpw(base+0x2, 0x2006);//Reg 2, 0062004	R-Mode	
	_outpw(base+0x0, 0x001f);_outpw(base+0x2, 0x3800);//Reg 3, 800001e	use LVTTL inputs,  MSet=31
	_outpw(base+0x0, 0x0300);_outpw(base+0x2, 0x4600);//Reg 4, 6000300	Quiet mode, M-Mode
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x5000);//Reg 5, 0000000	Start Offset 1
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x6800);//Reg 6, 8000000	TTL inputs
	_outpw(base+0x0, 0x1fb4);_outpw(base+0x2, 0x7f02);//Reg 7, 0141FCE	Resolution = 27.4384 ps, MTimer 100ns
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0xB400);//Reg 11,4000000	PLL not locked -> Err
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0xC200);//Reg 12,2000000	MTimer -> Int 

	//******************** Measurement ********************


	_outpw(base+0x0,0x0300);_outpw(base+0x2,0x4640);	//Reg 4, 6400300	TDC-GPX MasterReset 
	_outpw(base+0xC,0x0000);  // enable inputs
	printf("TDC resetted\n\n");
	
	i = 0; FIFOM = 0; 

	do 
	{
		_outpw(base+0xC,0x0010);						// externer Trigger
		_outpw(base+0xC,0x0000);
		
		while(!(_inpw(base+0x8) & 0x0020));				// Check Interrupt flag

		//Sleep(1);

		_outpw(base+0x0,0x0300);_outpw(base+0x2,0x4700);// Reg 4, 7000200	ALU trigger
		
		while((_inpw(base+0x8) & 0x0800)>0);			// Check Empty flag

		_outpw(base+0x4,0xb);
	
		

		_outpw(base+0x4,0x0008);										// read FIFO1
		FIFO1 = _inpd(base+0x0);
		//printf("%X\t",FIFO1);

		FIFO1 = FIFO1 & 0x7FFFFF;										// get time stamp
		//printf("%5.3fns\n",float(FIFO1)*27.4384/1000/32);

		FIFO0[i]=FIFO1;
		FIFOM = FIFOM + FIFO1;
		i++;

		if(i==1000)
		{
			FIFOA = float(FIFOM)/1000;									// average value
			printf("average %5.3fns\n",float(FIFOA)*27.4384/1000/32);

			FIFO1=0;
			for(i=0;i<1000;i++)											// calculate standard deviation			
			{
				FIFO1=FIFO1+(FIFO0[i]-FIFOA)*(FIFO0[i]-FIFOA);	

				if(i==0){												// minimum value
					Min=FIFO0[i];
				}
				else
				{	
					if(FIFO0[i]<Min){
						Min = FIFO0[i];
					}
				}

				if(i==0){												// maximum value
					Max=FIFO0[i];
				}
				else
				{	
					if(FIFO0[i]>Max){
						Max = FIFO0[i];
					}
				}

			}
			FIFOE= sqrt(FIFO1/(1000-1));								// standard deviation

			printf("min %d\tmax %d\n",Min,Max);
			printf("span d %5.3fns\n",float(Max-Min)*27.4384/1000/32);
			
			printf("stddev %5.3fns\n\n",float(FIFOE)*27.4384/1000/32);
			i=0;

			FIFOM=0;
			
		}

		// Keyboard: "i" = interrupt measurement, "q" = quit measurement
		if(kbhit())
		{
			ch=getch();
			if(ch=='q')
				quit=true;
				
			if(ch=='i')
			{
				while(!kbhit());
				quit=false;
			}
		}
		
		_outpw(base+0x0,0x0300);_outpw(base+0x2,0x4640);//Reg 4, 6400300	TDC-GPX MasterReset

		//Sleep(500);

	} while ( !quit );

// ********************************* End of Your code *****************************************

	return nRetCode;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -