|
|
View previous topic :: View next topic |
Author |
Message |
Nora
Joined: 23 Mar 2008 Posts: 50
|
ADC Port E with 18F452 |
Posted: Mon Dec 01, 2008 5:51 am |
|
|
Hello-
I have a temperature sensor connected to an op-Amp (Gain of 10) then connected to a PIC 18F452 Pin 9, AN6, also defined as RE1 and WR.
I am using the PICDEM 2 PLUS, ROHS version. According to the schematic, nothing else seems to be connected to this pin.
http://ww1.microchip.com/downloads/en/DeviceDoc/PICDEM%202%20Plus%20RoHS.pdf
When I measure the voltage at Pin 9, it will not go higher than 0.9V, no matter what the mV signal is at the temperature sensor. For example, with a mV reading of 0.202, I would expect a V reading at the ADC pin of ~2.02V.
I believe my hardware is correct, as when I change the AC pin to any Port A Analog pin, the reading works as expected. To make my system work, I am now using AN4.
I have an LED on AN7. Could this have been loading down my AN6?
Here's a code snip:
Code: |
//*****************************************************************
#include <18F452.H>
#device adc=10
#fuses HS,NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)
//*****************************************************************
long int ch6_result, temp_cel;
long int temp;
void main()
{
setup_adc_ports(ALL_ANALOG); // All analog and +ref is VDD, -ref is VSS
set_adc_channel(4); // channel 6 active
delay_us(25); // recommendation is to delay
setup_adc(ADC_CLOCK_DIV_32); // from PIC data sheet
setpoint = 93;
while(1)
{
ch6_result=read_adc(); // read ADC
output_high(PIN_E2); // blue LED on
delay_ms(300);
output_low(PIN_E2); // blue LED off
delay_ms(300);
}
} |
Thanks in advance!
N_N |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 01, 2008 2:13 pm |
|
|
I don't have the Rohs version of that board. I have the previous version.
I modified your program by adding a #use rs232() statement and a
printf(), to show the results of reading the ADC. I changed the ADC
channel to 6, so it would actually test your problem. I added a declaration
for 'setpoint' which was missing. I used PCH vs. 4.083 for this test.
On the board, I jumpered pin A0 to pin E1. This puts the 5K trimpot
on the AN6 pin. I also jumpered pin E2 to pin B0, to provide an LED
on that pin.
Then it worked. As I turned the trimpot through its range, I got this:
Quote: | 0
0
53
91
230
376
443
590
684
792
1023
1023
1023 |
Here is the modified program:
Code: | #include <18F452.H>
#device adc=10
#fuses HS,NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//*****************************************************************
long int ch6_result, temp_cel;
long int temp;
int setpoint;
void main()
{
setup_adc_ports(ALL_ANALOG);
set_adc_channel(6);
delay_us(25);
setup_adc(ADC_CLOCK_DIV_32);
setpoint = 93;
while(1)
{
ch6_result=read_adc();
printf("%lu\n\r", ch6_result);
output_high(PIN_E2);
delay_ms(300);
output_low(PIN_E2);
delay_ms(300);
}
} |
|
|
|
Guest
|
|
Posted: Mon Dec 01, 2008 2:23 pm |
|
|
Interesting!
Thanks for taking the time to check it out.
I'll look at this again later tonight.
~N_N |
|
|
Nora
Joined: 23 Mar 2008 Posts: 50
|
|
Posted: Tue Dec 02, 2008 8:04 pm |
|
|
I put the pin back on AN6 with my same result as before.
I tried your code and it worked fine.
OK- must be my code. I hadn't posted my entire code here....
I finally got it working, by commenting out
//set_tris_e(0b01000000); // set all PORTE output, input, rest output
No matter how I set the tris, outs and ins order, I got flaky voltage readings.
Thanks for the help!
N_N |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|