I am doing a project with a PIC micro controller by using its ADC to measure the peak-to-peak voltage and the frequency of an analog signal between 0v and 5v, and show it in the PC GUI screen. I got communication between my computer (GUI interface) and the PIC by RS232 serial port.
Now,I need help for this:
1) To write a part of the program so that the results update whenever I change or vary the input signal because I need to close and re-open my interface program to see the new values to be measured.
2) When I tested it, the ADC was sending some weird characters to the screen that I assume are ASCII characters, I need the ADC values in decimals because I need it in volts. Is there any way to convert those characters into numbers?
I need a code that calculate the voltage peak to peak and frequency.
Here is part of the whole code, but this is the most important because everything (calculations and conversions) goes into here:
void CTestDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
BYTE data;
port.ReadByte(data);
if (data!=0)
{
m_RECEIVE_VOLTAGE.Insert(m_RECEIVE_VOLTAGE.GetLength(),data); m_RECEIVE_FREQUENCY.Insert(m_RECEIVE_FREQUENCY.GetLength(),data);
UpdateData(FALSE);
}
// 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
port.OpenPort("com1");
port.ConfigurePort(9600,8,0,NOPARITY,ONESTOPBIT);
port.SetCommunicationTimeouts(0,100,0,0,0);
SetTimer(1,100,NULL);
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 CTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
// 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 CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
BYTE data;
port.ReadByte(data);
if (data!=0)
{
m_RECEIVE_VOLTAGE.Insert(m_RECEIVE_VOLTAGE.GetLength(),data);
m_RECEIVE_FREQUENCY.Insert(m_RECEIVE_FREQUENCY.GetLength(),data);
UpdateData(FALSE);
}