Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 7th June 2008, 08:56 AM   (permalink)
Default ADC 16F877 with Scope data

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 )
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.MajorDi vision = 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
apple9 is offline   Reply With Quote
Old 7th June 2008, 09:12 AM   (permalink)
Default

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
Attached Images
File Type: jpg DSC03748.JPG (97.3 KB, 19 views)
apple9 is offline   Reply With Quote
Old 9th June 2008, 07:31 AM   (permalink)
Default

Help me please
apple9 is offline   Reply With Quote
Old 9th June 2008, 07:52 AM   (permalink)
Default

Quote:
Originally Posted by apple9 View Post
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.
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline   Reply With Quote
Old 9th June 2008, 03:22 PM   (permalink)
Default

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 ? ,
Attached Images
File Type: jpg Measurement.JPG (47.7 KB, 10 views)
apple9 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Crazy scope spuffock General Electronics Chat 28 25th August 2007 05:28 PM
16f877 pic pin voltages when data is writing uditha33 Micro Controllers 2 6th June 2007 03:26 AM
What is on the top of this scope? Andy1845c General Electronics Chat 12 7th April 2007 03:10 PM
New scope zachtheterrible General Electronics Chat 10 27th August 2006 02:23 AM
Rearranging data - 16F877 in assembler atferrari Micro Controllers 3 1st December 2005 09:00 AM



All times are GMT. The time now is 02:35 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.