Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC 16F877 with Scope data

Status
Not open for further replies.

apple9

New Member
Could you help me about my project? I dose real time voltage monitor ADC by PIC16F877 and send the data value to PC (serial port). It’ seems a big problem about the sampling rate? I’m comparing my project between boards (ETT16F877) with Oscilloscope but result error very much. Need you help me for suggestions? Below picture my soft code PIC and VB6.(Sorry I'm not good english ):D
CCS for PIC.
#include <16F877.H>
#define TxD PIN_C6
#define RxD PIN_C7
#define CLOCK_SP 10000000
#fuses HS
#fuses NOLVP,NOWDT
#fuses NOPROTECT
#device ADC=10
#use delay (clock=CLOCK_SP)
#use rs232(baud=9600,xmit=TxD,rcv=RxD)
#use fast_io(A)
#define Vbe 0.0048875855327468230694037145650049 // Vref/1023 (5/1023)

void main(void) {
int16 value;
float volt;
setup_adc_ports(0x82); // A0 A1 A2 A3 A5 E0 E1 E2 Ref=Vdd
setup_adc(ADC_CLOCK_INTERNAL); // Clock RC
set_adc_channel(0); // Read Analog input RA0
do{
value = Read_ADC();
delay_us(10);
volt = Vbe*(float) value;
printf("\n\r%f",volt);
} while (TRUE);
}

Code VB6
Option Explicit
Dim data As String
Dim i As Variant
Dim n As Variant
Dim MyData As String
Dim stime As Variant
Dim sdate As String

Private Sub cmdExit_Click()
MSComm1.PortOpen = False
End
End Sub

Private Sub Command1_Click()
MSComm1.PortOpen = False
End Sub
Private Sub Form_Load()
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

Label4.Caption = " Data Save"
Shape2.BackColor = vbGreen
Shape2.BackStyle = 1


MSComm1.CommPort = 1
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 512
MSComm1.RThreshold = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True


Timer3.Interval = 1000
Label6.Caption = Date
Label5.Caption = Time

If MSComm1.PortOpen = False Then
Shape1.BackColor = vbRed
Label2.Caption = " Disconnect to HW "
End If

MSChart1.ColumnCount = 1
MSChart1.RowCount = 30

MSChart1.chartType = VtChChartType2dLine
MSChart1.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
MSChart1.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
MSChart1.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 10
MSChart1.Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision = 10
MSChart1.data = data

Timer1.Enabled = True
Timer2.Enabled = False

End Sub

Private Sub Label3_Change()
Open "C:\Voltage Detect " & Date$ & " .txt " For Append As #1
'Print #1, Date$ + Time$ + Label3.Caption
'Print #1, Trim$(Date$) + Trim$(Time$) + Trim$(Label3.Caption$)
Print #1, Date$ + " " + Time$ + " " + Label3.Caption$
Close #1
End Sub

Private Sub MSComm1_OnComm()
On Error Resume Next

If MSComm1.CommEvent = comEvReceive Then
data = MSComm1.Input
Label3.Caption = data
Shape1.BackColor = vbGreen
End If
MSChart1.data = data
For i = 1 To MSChart1.RowCount + 1
MSChart1.Row = i + 1
n = MSChart1.data
MSChart1.Row = i
MSChart1.data = n
Next i
MSChart1.Column = 1
MSChart1.Row = MSChart1.RowCount

End Sub

Private Sub Timer1_Timer()
Shape2.BackColor = vbRed
Shape2.BackStyle = 1
Timer2.Enabled = True
Timer1.Enabled = False

End Sub

Private Sub Timer2_Timer()
Shape2.BackColor = vbBlue
Shape2.BackStyle = 1
Timer2.Enabled = True
Timer1.Enabled = False
End Sub
 
Wave from by Oscilloscope. And result by txt file data.
06-07-2008 09:20:37 2.99
06-07-2008 09:20:37 2.98
06-07-2008 09:20:37 2.99
06-07-2008 09:20:37 2.98
06-07-2008 09:20:37 2.99
06-07-2008 09:20:37 2.98
06-07-2008 09:20:37 2.83
06-07-2008 09:20:37 3.23
06-07-2008 09:20:37 3.00
06-07-2008 09:20:37 3.01
06-07-2008 09:20:37 3.00
06-07-2008 09:20:37 3.01
06-07-2008 09:20:37 3.00
06-07-2008 09:20:37 3.01
06-07-2008 09:20:37 2.99
06-07-2008 09:20:37 3.01
06-07-2008 09:20:37 3.00
06-07-2008 09:20:37 3.01
06-07-2008 09:20:37 2.84
06-07-2008 09:20:37 2.91
06-07-2008 09:20:37 3.01
06-07-2008 09:20:37 2.99
06-07-2008 09:20:37 3.01
06-07-2008 09:20:37 3.00
06-07-2008 09:20:38 3.01
06-07-2008 09:20:38 3.00
06-07-2008 09:20:38 3.01
06-07-2008 09:20:38 3.00
06-07-2008 09:20:38 3.01
06-07-2008 09:20:38 3.00
06-07-2008 09:20:38 2.94
06-07-2008 09:20:38 2.99
06-07-2008 09:20:38 3.03
06-07-2008 09:20:38 3.02
06-07-2008 09:20:38 3.03
06-07-2008 09:20:38 3.02
06-07-2008 09:20:38 3.03
06-07-2008 09:20:38 3.02
06-07-2008 09:20:38 3.03
06-07-2008 09:20:38 3.03
 

Attachments

  • DSC03748.JPG
    DSC03748.JPG
    97.3 KB · Views: 257
Help me please:(:(

hi apple,
Could you explain in more detail.:)

Are you saying the PIC program is causing the sampling 'error' or the VB6 program in the PC.

Is it the 'accuracy' or the 'sampling rate' you are concerned about.?

I dont write programs in 'C', but many members are expert in 'C' programming.
 
If i will use PIC16F877 to do low cost scope. How are you think?
PIC16F877 , it can do the measurement is like a picture that at , press come to get ? ,
:D:D
 

Attachments

  • Measurement.JPG
    Measurement.JPG
    47.7 KB · Views: 263
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top