Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16F877 internal ADC

Status
Not open for further replies.

S_51

Newbie level 5
Joined
Jan 6, 2009
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,350
pic16f877 adc

I have decided to use the PIC16F877 µC to convert a 4-20mA analog signal. I went through the manual and came accross the ADCON 1 register. I found out that it has two parts; a single bit ADFM and a 4-bit PCFG3:pCFG0. There was a table which I had was to use in order to determine what to set PCFG3:pCFG0 to. I came up with two solutions: "0101" or "1110". In both cases, Vref- is Vss but Vref+ is RA3 and Vdd respectively. Could anyone shed some light on which one i should use and why? Also, I need this data to be displayed on a LCD (every 5s or so) and at the same time be made availiable to a GPRS modem with a SIM card. Any ideas? Lastly, if you have any form of code or schematic diagram of how i should go about doing this task please let me know... Thanks
 

a/d pic16f877

Here is a simple adc program from melabs in picbasic pro. It is using the 877 and displaying it on an LCD.

' PicBasic Pro program to read pots on 16F877 ADC

' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
Define LOADER_USED 1

' Define LCD pins
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG PORTE
Define LCD_EBIT 1

' Allocate variables
x var byte
y var byte
z var byte

ADCON1 = 4 ' Set PortA 0, 1, 3 to analog inputs

Low PORTE.2 ' LCD R/W line low (W)
Pause 100 ' Wait for LCD to start

Goto mainloop ' Skip subroutines


' Subroutine to read a/d convertor
getad:
Pauseus 50 ' Wait for channel to setup

ADCON0.2 = 1 ' Start conversion
Pauseus 50 ' Wait for conversion

Return

' Subroutine to get pot x value
getx:
ADCON0 = $41 ' Set A/D to Fosc/8, Channel 0, On
Gosub getad
x = ADRESH
Return

' Subroutine to get pot y value
gety:
ADCON0 = $49 ' Set A/D to Fosc/8, Channel 1, On
Gosub getad
y = ADRESH
Return

' Subroutine to get pot z value
getz:
ADCON0 = $59 ' Set A/D to Fosc/8, Channel 3, On
Gosub getad
z = ADRESH
Return


mainloop:
Gosub getx ' Get x value
Gosub gety ' Get y value
Gosub getz ' Get z value

Lcdout $fe, 1, "x=", #x, " y=", #y, " z=", #z ' Send values to LCD
Pause 100 ' Do it about 10 times a second

Goto mainloop ' Do it forever

End

Hope it helps.

regards

dfullmer
 
adc pic 16f877

The A/D uses the ref voltage as its full scale value.
If you choose to use Vdd for Vref, then the accuracy of the A/D result will depend on the stability and noise levels of the Micro's Vdd rail. This is adaquate in most cases.
For a higher accurate A/D result, you could choose to use a Reference voltage input on RA3. The reference voltage could be generated by a stable band gap diode. You can buy these designed for this purpose. For example, using a 4.096 voltage ref with a twelve bit A/D convertor, the result is 1mV per bit.
 

pic 16f877 adc

you can use VDD as VRef+ and VSS as VRef- in 4-20mA loop you can convert 4mA->1V and 20mA ->5v as it happens you can use entire VDD range.
 

pıc16f877 4 20 ma

Well i decided to use a 250Ω pot in order to vary the voltage from 1V to 5V which corresponds to 4mA - 20mA. Should I use the internal osc of the PIC or should I use an external one? I have read somwhere that the external osc is more accurate than the internal one found in the PIC. Also, I am using Assembly language so if anyone has ASM code to share I will really appriciate it.
Any ideas on the GPRS part?

P.S Thanks dfullmer for your time and effort...
 

pic16f877 adc lcd

Hi S_51,

ADC:
I usualy use VDD and VSS as reference voltage. PIC has 10bit ADC, this means an unprecise measurement in term of number conversion of bits. So, I think that precise voltage reference, with 10bit ADC doesn't have much sence.


Internal/external osilator:
Internal osilator is temperature dependant, so in project where you do not need accurate time measurement, internal osc. is quite OK. If you use external osilator with XTAL (with 10ppm or similar) your clock on PIC will be very same over temperature working range.

GPRS:
This depends of GPRS modem you use. In most cases today, GPRS modems are capable to make TCP/IP connection, so you have "black box" with serial port.

MCU --- Max232 --- GPRS modem - - - - - - - GPRS modem --- other device which expecting analog measurement.

In that case you just need to make message (convert your analog value to ascii caracters) and to send it via seria port to GPRS modem.


Best regards,

Mr.Cube
 

a/d converter in pic16f877a using three channels

Hello there.

To help me learn Picbasic I used the files that were published for the Lab-x1 devopment board. Instead of purchasing the board I built it in Proteus and then simulated the program/hardware. Included in the files below are the example from the second post.

bas/hex files
**broken link removed**

Proteus schematic
**broken link removed**

I will be adding files and updating schematic for temperature/rtc operations over the next few days.

Hope these files have been helpful.
 

a/d pic16f877a

which programming language you are using???
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top