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.

pic16f877a ADC source code for lm35

Status
Not open for further replies.

Tys0n

Newbie level 4
Newbie level 4
Joined
Apr 8, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,317
Hi

I'm using CCS PCWHD compiler,
What changeS should I make so as to keep my PIC ADC : +Vref = 1.2v and -Vref = ground
(which I kept using potential divider arrangement)

_______________________________________________
Transmitting side code
#include <16F877A.h>
#device *= 16
#device adc=8
#fuses HS, NOWDT, NOPROTECT,
NOLVP, PUT
#fuses NOBROWNOUT, CPD,
NODEBUG, NOWRT
#use delay(clock=10MHz)
#use rs232(baud=1200, xmit=PIN_
C6, bits=8, parity=N)
#include <lcd.c>
void main()
{
byte s=0;
lcd_init();
lcd_putc("\f");
setup_adc_ports(adc_clock_internal);
setup_adc(AN0);
set_adc_channel(0);
while(true)
{
read_adc(adc_start_only);
while(!adc_done());
s = read_adc(adc_read_only);
lcd_gotoxy(1,1);
printf(lcd_putc, "\fTx Data = %u" s);
putc(s);
delay_ms(100);
}
}
 

I just want to know how to configure PIC adc for given reference voltage in that source code.....

setup_adc(???);
 

But its not helping, in proteus simulation it is showing 255 equivalent to 5V. I just want my range to be btwn 0 to 1.2V for ADC.
 

LM35 max output is 1.5 V, So your Vref+ should be around 1.8V. Post your project files. Maybe you used an int8 variable to hold the value of adc read. You need a 16bit int or float for that.

I found the problem.

Code C - [expand]
1
#device adc=8

is wrong. You have to use

Code C - [expand]
1
#device adc=10

as PIC16F877A's adc is 10 bit.

If adc=8 is used then 8bit is considered and 2^8 is 256 i.e., 0-255, so, you are getting 255.
 

Actualy I used byte since my I'm doing 8-bit data transmission later so can't use 10bit adc.... So as to increase the 8bit resolution, I want my ADC conversion range to be just 0-1.2 V
i.e. 1.2v should be equivalent to 255
 

8bit ADC is working fine, but by this source code its taking 5V as reference even aftr applying 1.2V to Vref+ i.e pin 5
How to configure ADCON in CCS code to make PIC to take into account the reference voltage?
 

Post your setup_adc() statement you used in your code. If possible post 16f877a.h file included in your code.


Code C - [expand]
1
2
setup_adc_ports(AN0_AN1_AN2_AN4_AN5_AN6_AN7_VSS_VREF);
setup_comparator(NC_NC_NC_NC);

 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top