Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Regarding disabling of ADC in Microcontroller.

Status
Not open for further replies.

achar.deepak

Member level 1
Joined
Dec 12, 2016
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,696
Hi all,

I have a doubt regarding ADC in Microcontroller. Can we disable ADC in the microcontroller is the sensor is not connected? I am writing code in C. Please help regarding this.

Thanks
Deepak
 

hi

yes you can disable , actually MCU has multiplex pin (on single I/O different peripherals can be configured ) to use I/O as GPIO only you need to configure accordingly
check with Peripheral Multiplexing on I/O lines table there you get more info
 

hI,

Can I make pin as pull down to disable ADC?
 

hi

No, All the I/O lines integrate a programmable pull-up resistor. Programming of this pull-up resistor is performed independently for each I/O line through the GPIO Controllers. After reset, I/O lines default as inputs with pull-up resistors disabled, except when indicated otherwise in the column “Reset State” of the GPIO Controller multiplexing tables. (taken from datasheet)

- - - Updated - - -

you can configure your I/O for specific peripheral using Peripheral Function Selection,
use Peripheral Mux Register 0 & Peripheral Mux Register 1 registers . they have mentioned pin multiplexing table (page 45 of data sheet) function A,B,C,D

- - - Updated - - -

you can select accordingly i.e.
PIN GPIO Pin Function A Function B Function C
PA00 GPIO 0 USART0 - RXD TC - CLK0 NA

for using pin PA00 as uart rx pin you need to select Function B for that you need to refer (page 179 of datasheet) put 01 (00->A,01->B,10->C,11->D)
 

Hi,

One clarification how the controller knows weather the sensor is connected or not.

- - - Updated - - -

Hi,

If I did not connected the sensor means it is showing some random values.

Thanks
 

hi
if you have configure your pin as analog and no sensor is connected so definatly it will give you some random values. controller will not understand that nothing is connected , it will create digital values for whatever it gets as i/p on that analog pins generating continous random values
 

A trick that might work is to use a high value resistor (~47K) between the sensor input pin and another IO pin if you have one spare. The resistor will provide a weak pull-up or pull-down depending on the IO pin state but should easily be overdriven by the sensor output current. If toggling the IO pin makes the ADC voltage go up and down, it indicates the sensor is disconnected.

Brian.
 

Hi,

Here is my ADC code. I need to disable ADC function if the sensor is not connected. Please help.

Code:
uint8_t temperature_get(void)
{
	signed short adc_value_temp = -1;
	signed short adc_samples[8], average_temp=0,i;
	float vout,rt,temp;
	static int pre_temp;

	for(i=0;i<8;i++)
	{
		adc_start(&AVR32_ADC);
		adc_value_temp = adc_get_value(&AVR32_ADC, ADC_TEMPERATURE_CHANNEL);// Get value for the temperature adc channel
		adc_samples[i]=adc_value_temp;
		average_temp+=adc_samples[i];
		delay_ms(3);
	}
	
	average_temp/=8;
	vout = average_temp * ADC_RESOLUTION;//output voltage of the voltage divider
	rt=((RFIX*vout)/(VCC-vout));//calculate the resistance of temperature sensor
	temp=(-R0 * a +sqrt (R0 * R0 * + a * a - 4 * R0 * b * (R0 - rt))) / (2 * R0 * b);  //find the temperature in 'C (Callendar-Van Dusen equation)
	
	rt=((int)temp+pre_temp)/2;   //rt holds average temperature value
	pre_temp=(int)temp;
	temp=rt;
	
	return (int)temp;
}

Thanks
Deepak
 

hi

what is your temperature range ? for example 0 to 40 degree like that?

- - - Updated - - -

you need to decide on adc count if adc counts not in the that perticular range consider it as no temperature probe is connected, or simply impleament one algorithm ,
I can see here your taking average of ADC, in the same routine you can. Like if no sensor is connected you get random values if more then three random values descard reading and consider as no sensor connected

- - - Updated - - -

But for that you need to take some obeservations & continous data like what kind of adc counts your receiving when no sensor connected

- - - Updated - - -

try this once

Code:
uint8_t temperature_get(void)
{
 [B]static int error_count = 0;   // added one var[/B]
signed short adc_value_temp = -1;
signed short adc_samples[8], average_temp=0,i;
float vout,rt,temp;
static int pre_temp;

for(i=0;i<8;i++)
{
adc_start(&AVR32_ADC);
adc_value_temp = adc_get_value(&AVR32_ADC, ADC_TEMPERATURE_CHANNEL);// Get value for the temperature adc channel
adc_samples[i]=adc_value_temp;


// algorithm example .. evaluate at your side.. suggested 
[B]if(i!=0)
{
  int ADC_cnt_difference = adc_samples[i] - adc_samples[i-1] ;
  if(ADC_cnt_difference > 10) // take trial with random values just example
  error_count++;
  if(error_count>3)
  {
     error_count = 0;
     // disable adc i.e turn off adc i.e adc_stop(&AVR32_ADC);
     printf ("no sensor connected");  // debug statement just example
   }

}[/B]
average_temp+=adc_samples[i];
delay_ms(3);
}

average_temp/=8;
vout = average_temp * ADC_RESOLUTION;//output voltage of the voltage divider
rt=((RFIX*vout)/(VCC-vout));//calculate the resistance of temperature sensor
temp=(-R0 * a +sqrt (R0 * R0 * + a * a - 4 * R0 * b * (R0 - rt))) / (2 * R0 * b); //find the temperature in 'C (Callendar-Van Dusen equation)

rt=((int)temp+pre_temp)/2; //rt holds average temperature value
pre_temp=(int)temp;
temp=rt;

return (int)temp;
}
 

Temperature range is 0 to 150 degree.

- - - Updated - - -

Code:
uint8_t temperature_get(void)
{
	
	static int error_count = 0; 
	signed short adc_value_temp = -1;
	signed short adc_samples[8], average_temp=0,i;
	float vout,rt,temp;
	static int pre_temp;

	for(i=0;i<8;i++)
	{
		adc_start(&AVR32_ADC);
		adc_value_temp = adc_get_value(&AVR32_ADC, ADC_TEMPERATURE_CHANNEL);// Get value for the temperature adc channel
		adc_samples[i]=adc_value_temp;
		
		if(i!=0)
		{
			int ADC_cnt_difference = adc_samples[i] - adc_samples[i-1] ;
			if(ADC_cnt_difference > 10) // take trial with random values just example
			error_count++;
			if(error_count>3)
			{
				error_count = 0;
				adc_disable(ADC_TEMPERATURE_PIN, ADC_TEMPERATURE_CHANNEL);
				lcdClear();
				lcdMoveCursor(0,0);
				lcdPrintStr("Sensor not Connected");
			}

		}
		
		average_temp+=adc_samples[i];
		delay_ms(3);
	}
	
	average_temp/=8;
	vout = average_temp * ADC_RESOLUTION;//output voltage of the voltage divider
	rt=((RFIX*vout)/(VCC-vout));//calculate the resistance of temperature sensor
	temp=(-R0 * a +sqrt (R0 * R0 * + a * a - 4 * R0 * b * (R0 - rt))) / (2 * R0 * b);  //find the temperature in 'C (Callendar-Van Dusen equation)
	
	rt=((int)temp+pre_temp)/2;   //rt holds average temperature value
	pre_temp=(int)temp;
	temp=rt;
	
	return (int)temp;
}
Please help its not working.
 

hi
its just trial value I have put , check for your random values and there occurance , put breakpoints and check when no sensor is connected what are values your getting.
when no sensor is connected take values in array and print it so you will get it what exactly conditions you need to put
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top