Page 1 of 1
any example of adc
Posted: Sat Sep 29, 2012 1:14 pm
by ganeshredcobra
Hi,
Can i get any example regarding the working of adc...the documentation is not that much good for a beginner its pretty hard to understand...and i couldnt find any sample codes...usually in pic i do adc like this
void main()
{
int x;
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_us(20);
while(True)
{
x=read_adc();
output_B(x) ;
delay_us(20);
}
}
can i get an example like this...
Re: any example of adc
Posted: Sat Sep 29, 2012 1:21 pm
by Giovanni
Hi,
I agree that the ADC driver is a bit complex, under ./testhal there are ADC test applications (and for all other device drivers), try there.
Giovanni
Re: any example of adc
Posted: Sun Sep 30, 2012 1:07 pm
by ganeshredcobra
can you give the code of a simple example ie if vary input using a pot then i must get digital out can you post code for that so that i can understand the example on testhal is also a complex didnt even understand the working of it...
Re: any example of adc
Posted: Sun Sep 30, 2012 1:51 pm
by Giovanni
Hi,
Sorry, it does not get much simpler that this because it is not meant for beginners:
The example reads IN11 eight times in a buffer.
Code: Select all
#define ADC_GRP1_NUM_CHANNELS 1
#define ADC_GRP1_BUF_DEPTH 8
static adcsample_t samples1[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
/*
*
* ADC conversion group.
* Mode: Linear buffer, 8 samples of 1 channel, SW triggered.
* Channels: IN11.
*/
static const ADCConversionGroup adcgrpcfg1 = {
FALSE,
ADC_GRP1_NUM_CHANNELS,
NULL,
NULL,
0, /* CR1 */
ADC_CR2_SWSTART, /* CR2 */
ADC_SMPR1_SMP_AN11(ADC_SAMPLE_3),
0, /* SMPR2 */
ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
0, /* SQR2 */
ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
};
...
/*
* Activates the ADC1 driver.
*/
adcStart(&ADCD1, NULL);
/*
* Linear conversion.
*/
adcConvert(&ADCD1, &adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH);
Taken from the example in testhal. You have to undestrand the ADCConversionGroup structure, it is all defined there. Reading the reference manual helps.
Giovanni