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

PIC12F675 - Problem with ADC

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







PIC12F675 - Problem with ADC
PostPosted: Tue Mar 06, 2007 10:30 am     Reply with quote

Hi,
I have problem with the ADC conversion, the variable "value" contain just the LSB of the 10 bits ADC conversion. What is the manipulation to obtain "value" with the 10 bits ?

This is the code example :

#include <12F675.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,MCLR
#use delay (clock=4000000) // Quartz de 4Mhz
#define OUT1 PIN_A5 // Signal de sortie sur RA5


//******Déclaration des variables******//
long value; // utilisé dans la conversion Analog/numérique


//******Programme principal******//
void main(void)
{

set_tris_a(0b00011101); // RA0, RA2 3 et 4 en entrée
setup_adc(ADC_CLOCK_DIV_8);
setup_adc_ports(sAN0|VSS_VDD); // RA0 en entrée analogique
setup_comparator(NC_NC_NC_NC); // Désactive le mode comparateur

//***Initialisation***//
output_low(OUT1); // Initialisation sur un état bas

set_adc_channel(0);
delay_us(10);
value=read_adc();

while(1)
{
output_low(LED);
value=read_adc();
delay_us(value);
output_high(LED);
delay_us(value);
} // fin du while(1)
} // fin du main
Ttelmah
Guest







PostPosted: Tue Mar 06, 2007 10:38 am     Reply with quote

You are already getting 10bits.
The problem you are seeing, is that the delay_us function, only accepts variables of 8bits. Hence the extra bits are then getting thrown away.
There have been modified versions of this function posted here in the past, to accept a 'long'.

Best Wishes
Charles J
Guest







PostPosted: Tue Mar 06, 2007 10:53 am     Reply with quote

Thank a lot !
This problem is now resolved
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