electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

PIC16F877 internal ADC


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers > PIC16F877 internal ADC
Author Message
S_51



Joined: 06 Jan 2009
Posts: 9


Post08 Jan 2009 13:28   

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
Back to top
dfullmer



Joined: 07 Jun 2006
Posts: 247
Helped: 33
Location: Some place Hot - Not an Island


Post08 Jan 2009 16:25   

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
Back to top
btbass



Joined: 20 Jul 2001
Posts: 1267
Helped: 115
Location: Oberon


Post08 Jan 2009 18:37   

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.
Back to top
saeed_pk



Joined: 20 May 2006
Posts: 200
Helped: 5
Location: Islamabad, Pakistan


Post08 Jan 2009 18:56   

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.
Back to top
Google
AdSense
Google Adsense




Post08 Jan 2009 18:56   

Ads




Back to top
S_51



Joined: 06 Jan 2009
Posts: 9


Post08 Jan 2009 20:46   

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...
Back to top
mrcube_ns



Joined: 10 Apr 2002
Posts: 430
Helped: 11
Location: Dark side of the Moon


Post08 Jan 2009 23:00   

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
Back to top
btbass



Joined: 20 Jul 2001
Posts: 1267
Helped: 115
Location: Oberon


Post09 Jan 2009 0:13   

pic16f877 a/d conversion


Some time ago I wrote a small program to help with writing assembler code, posted here.

www.elektroda.pl/eboard/viewtopic.php?p=205856

Give it a try.
Back to top
msm



Joined: 14 Jul 2002
Posts: 16


Post16 Mar 2009 23:51   

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
http://rapidshare.com/files/210080020/msm_Picbasic_lab-x1.rar

Proteus schematic
http://rapidshare.com/files/210079846/msm_lab-x1.rar

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

Hope these files have been helpful.
Back to top
akvii



Joined: 04 Nov 2006
Posts: 54
Helped: 2


Post28 Mar 2009 13:40   

a/d pic16f877a


which programming language you are using???
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers > PIC16F877 internal ADC
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
Internal Clock for ADC (3)
PIC16F877 ADC jinx (8)
adc in pic16f877 (6)
pic16f877 adc programming (1)
PIC16F877 ADC EXAMPLES (11)
ADC/PIC16F877 problem (1)
adc problem in pic16f877 (1)
PIC16F877 ADC coding help (9)
reduce adc bits of pic16f877 (13)
PIC16F877 adc oscillation in 4 channels (2)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS