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.

ADC/PIC16F877 problem

Status
Not open for further replies.

coyoteboy

Newbie level 1
Joined
Dec 11, 2007
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,304
pic16f877 problem

Dear all, I'm hoping you can help me out a little here as I'm a tad confused. I've done a good bit of PIC work before but from a self-taught basis so sometimes I miss things that are obvious - hence questioning here!

I'm currently debugging a bit of hardware developed by someone else - I have
the code and the hardware in front of me and from my previous PIC work I'm
99% certain it should be working fine. Its coded in C and essentially boils
down to something that tests two ADC values and reports them over the
serial port. Using pins 3 and 4 (adc channels 1 and 2) the code goes:

setup_adc_ports(A_ANALOG);
setup_adc_(ADC_CLOCK_INTERNAL);
setup_comparator(NC_NC_NC_NC);
port_b_pullups(0x00);


set_adc_chennel(1);
result=read_adc();
Print some chars,
print the result,.
set_adc_channel(2);
result-read_adc();
Print some chars
print result

It does this, waits some time, does it again and then stops.

The strange output is that the ADC reading is somewhere around 17-25 for the
first "result" and then 5 or 6 for the second. The actual voltage monitored
on the pins is 0.441v and 0.12v respectively, steady to the third decimal
place. On the second run similar results are obtained but not always the same.

Changing the voltage (they are pressure sensors) to 0.580 seems to make zero
difference to the first reading but changing the second to a voltage of
0.2v reads around 11. Reducing the voltage on the pins to zero yields no
change in the first but 0 on the second. These voltages have been tested at
the actual pin-body joint of the processor so are the actual pin voltages.

Taking off the sensor daughtercard and pegging the either pin high using a 10K resistor to 5v causes readings of ~230 on both pins/adcs. Pegging it to 0v gives 0 on both pins/adcs.

Can one pin be blown without affecting the others? I've only ever had a
whole port blow before. I had considered the switchover time being too
short with no delay before read_adc but the same happens before the second
reading and that is "correct". I'm still thinking this latter item may be the problem but without reprogramming it with delays I have no way of testing that theory (going to take some getting the bits together and typing the code up from hardcopy, but I'll do it if i have to). I'm not sure what impedance the sensors are effectively when running, but when powered off they have a resistance of 230K.

Any hints appreciated!
 

adc pic16f877

Hi, looks like you are using CCS C?

I think what you need to do is in fact, delay, for a slight time, between setting the ADC channel, and reading it. You shouldn't need to do this before the first reading. What I would do is set the channel, print what your are going to, then read the channel, and change it, print....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top