// waveformDlg.cpp : implementation file // #include "stdafx.h" #include "waveform.h" #include "waveformDlg.h" #include "acces32.h" #include unsigned int BASE=0x300; #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CWaveformDlg dialog CWaveformDlg::CWaveformDlg(CWnd* pParent /*=NULL*/) : CDialog(CWaveformDlg::IDD, pParent) { //{{AFX_DATA_INIT(CWaveformDlg) m_addrEDIT = _T(""); m_instrLBL = _T(""); //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); outputting = false; } void CWaveformDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CWaveformDlg) DDX_Control(pDX, IDC_BEGIN_BTN, m_beginBTN); DDX_Text(pDX, IDC_EDIT_ADDR, m_addrEDIT); DDX_Text(pDX, IDC_INSTRUCTIONS_LBL, m_instrLBL); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CWaveformDlg, CDialog) //{{AFX_MSG_MAP(CWaveformDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BEGIN_BTN, OnBeginBtn) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CWaveformDlg message handlers BOOL CWaveformDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here m_addrEDIT = "300"; m_instrLBL += "This program will output three wave forms from the 104-DA12-8.\n\r"; m_instrLBL += "The wave forms will be output on DACS 0 - 2.\n\r"; m_instrLBL += "The wave forms will stop when the user clicks stop or exits the program\n\r"; UpdateData(false); return TRUE; // return TRUE unless you set the focus to a control } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CWaveformDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CWaveformDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CtrMode(unsigned short addr, char cntr, char mode) { int ctrl; ctrl = (cntr << 6) | 0x30 | (mode << 1); OutPortB(addr+3,ctrl); } void CtrLoad(unsigned short addr ,int c,int val) { OutPortB(addr+c,val & 0x00FF); OutPortB(addr+c,(val>>8) & 0x00FF); } void CWaveformDlg::OnBeginBtn() { // TODO: Add your control notification handler code here unsigned short BUFFER[30000]; char *buf; int count; if (!outputting) { outputting = true; m_beginBTN.SetWindowText("STOP"); UpdateData(true); buf = m_addrEDIT.GetBuffer(5); sscanf(buf, "%x", &BASE); m_addrEDIT.ReleaseBuffer(-1); /***************************************************** ** This for loop will fill the buffer with the following ** three wave forms and rescales them to have the same period: ** 1) sin(x^2) from x = -3.3 to 3.3 ** 2) cos(x^2) from x = -3.0 to 3.0 ** 3) sin(x^2) * cos (x^2) from x = -1.9 to 1.9 *****************************************************/ for (count = 0; count < 10000; count++) { BUFFER[(count * 3)] = int(sin(pow(-3.3 + (.00066 * count), 2)) * 2047.0 + 2048.0); BUFFER[(count * 3)] &= 0x0fff; //need to be certain that the control bits are what we want BUFFER[((count * 3) + 1)] = int(cos(pow(-3.0 + (.0006 * count), 2)) * 2047.0 + 2048.0); BUFFER[((count * 3) + 1)] &= 0x0fff; BUFFER[((count * 3) + 2)] = int(sin(pow(-1.9 + (.00038 * count), 2)) * cos(pow(-1.9 + (.00038 * count), 2)) * 2047.0 + 2048.0); BUFFER[((count * 3) + 2)] &= 0x0fff; //let the card know that this is the end of this scan BUFFER[((count * 3) + 2)] |= 0x2000; } BUFFER[29999] |= 0x1000; //this is the end of the stream and the card needs to loop OutPortB(BASE + 0x1a, 0); //we will only be writing to the first 30k addresses //so we get to leave bit 16 of the SRAM addr at 0 for (count = 0; count < 30000; count++) { OutPort(BASE + 0x18, (count * 2)); //set the address we are going to write to OutPort(BASE + 0x1c, BUFFER[count]); //write the value for that address } CtrMode(BASE + 0x14, 1, 2); //set counter 1 to mode 2 CtrMode(BASE + 0x14, 2, 2); //set counter 2 to mode 2 CtrLoad(BASE + 0x14, 1, 5); //load counter 1 to 5 ticks CtrLoad(BASE + 0x14, 2, 10); //load counter 2 to 10 ticks OutPortB(BASE + 0x10, 0x41); //tell the card to start and enable the //ARB } else { outputting = false; OutPortB(BASE + 0x10, 0); //tell the card to stop m_beginBTN.SetWindowText("&Begin"); } } void CWaveformDlg::OnClose() { // TODO: Add your message handler code here and/or call default OutPortB(BASE + 0x10, 0); //tell the card to stop CDialog::OnClose(); }