CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ADC Port E with 18F452

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

ADC Port E with 18F452
PostPosted: Mon Dec 01, 2008 5:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Dec 01, 2008 2:13 pm     Reply with quote

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








PostPosted: Mon Dec 01, 2008 2:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 02, 2008 8:04 pm     Reply with quote

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! Smile
N_N
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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