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 CCS Technical Support

Problem setting up ADC in 16F690 mcu

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



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

Problem setting up ADC in 16F690 mcu
PostPosted: Wed Feb 27, 2008 5:31 am     Reply with quote

MCU: 16F690
Compiler: PCM 3.228

Hi,

I use the code below to setup the ADC of the 16F690 mcu.

Code:


#include <16F690.h>

#fuses INTRC_IO,NOWDT,PUT,NOPROTECT,NOCPD,BROWNOUT,NOIESO,NOMCLR,NOFCMEN
#use delay(clock=8000000)

#byte WPUA=0x95       //Weak Pull ups on portA
#bit WPUA0=WPUA.0

void initialise()
{
setup_comparator(NC_NC_NC_NC);

set_tris_a(0b11111111);
set_tris_b(0b01101111);
set_tris_c(0b10110111);

WPUA0=0; //turn off pullup on RA0
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);

}

//this reads channel 0 of the ADC
float read_intensity()
{
   float ft;

   set_adc_channel(CHN_LED_INTENSITY);   //Read the ADC channel
   delay_us(10);

   fTmp=((read_adc()*5.0)/1024.0)*1000;   //calculation of voltage on ADC channel

   return fTmp;
}



The above code compiles well, and I am able to get the MCU going, but I find that when powering up the mcu, the pin RA0 generates a voltage of 5.4V (whereas VDD is only 5 VDC), also the pin is not connected to any other device, so there should not be any voltage

Isn't RA0 supposed to have approx. 0 V ??, I have also managed to disable pull-ups on RA0, by clearing bit 0 of WPUA (see code above).

Kindly explain what is wrong with the code ??


thanks
arunb




[/code]
ECACE



Joined: 24 Jul 2006
Posts: 94

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 8:44 am     Reply with quote

Couple of things:

1) You have not defined CHN_LED_INTENSITY

2) You have not defined fTmp

3) In your hardware, do you have floating pins? If so, you should tie any floating pins to ground via say 2.2K. Floating pins have a way of reacting erratic.
_________________
A HW Engineer 'trying' to do SW !!! Run!!!
arunb



Joined: 08 Sep 2003
Posts: 492
Location: India

View user's profile Send private message Send e-mail

RE:
PostPosted: Wed Feb 27, 2008 11:34 pm     Reply with quote

I have extracted the relevant parts from the main program code,

CHN_LED_INTENSITY is 0 this defines the channel number of the ADC.

#define CHN_LED_INTENSITY 0

fTemp is a float value.

I believe the ADC is not setup properly, it seems I am missing out on some thing.

Kindly explain what you mean by floating pin, isn't the ADC pin supposed to be floating, but in my case the pins shows a steady voltage of 5.4 V DC !!

I wonder why ??

thanks
arunb
Ttelmah
Guest







PostPosted: Thu Feb 28, 2008 3:51 am     Reply with quote

Think about it for a moment.
The PIC _cannot_ 'generate' an output above the voltages present on it's pins (the only internal 'voltage generator', is the programming voltage generator for the flash memory, and this is itself 'slaved' to the voltage on Vpp). If you are seeing '5.4v', it implies _either_, that a voltage above 5v, _is_ being presented to the pin (most likely - triple check for a short somewhere...), _or_ that another pin is being pulled to a higher voltage, and with the internal protection diodes, is _raising_ the supply the PIC is internally using. Both scenarios, are external wiring faults, not faults with the code.
Though there may be faults that will stop the ADC working, _none_ can generate voltages above the supply rail. You need to find what is generating the 5.4v signal, bfore proceeding...

Best Wishes
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