|
|
View previous topic :: View next topic |
Author |
Message |
Charles J Guest
|
PIC12F675 - Problem with ADC |
Posted: Tue Mar 06, 2007 10:30 am |
|
|
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
|
|
Posted: Tue Mar 06, 2007 10:38 am |
|
|
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
|
|
Posted: Tue Mar 06, 2007 10:53 am |
|
|
Thank a lot !
This problem is now resolved |
|
|
|
|
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
|