Jump to content
Sign in to follow this  
DanW

Help... Using Two Adc's As Touch Sensors (At Wits End)

Recommended Posts

I'm new to boostc and saw a pic article about using the ADC's as analog touch sensors.

http://ww1.microchip...otes/01298A.pdf

 

I've been trying for a couple of days without some success but both channels are getting detected with same value when either button is pressed.

 

Here's what I did:

 

           adcon0 = 00000001b;				   // Turn on the A/D converter, select channel 0 .

	   delay_ms(20);
	   Go_Done=1;						  // Start conversion
	   while ( Go_Done == 1 )			  // Wait for conversion to complete -- better put a timeout in here some time.
	   {

	   }
		// Separate int's need to be used to keep the shifts from screwing up.
		shiftH = ad_h;
		shiftL = ad_l;

		AD_Result2 = (shiftH<<2) | (shiftL>>6);  // Combine the two registers to get full 10 bits.


	   adcon0 = 00000101b;				   // Turn on the A/D converter, select channel 1 .
	   delay_ms(20);
	   Go_Done=1;						  // Start conversion
	   while ( Go_Done == 1 )			  // Wait for conversion to complete -- better put a timeout in here some time.
	   {

	   }
		// Separate int's need to be used to keep the shifts from screwing up.
		shiftH = ad_h;
		shiftL = ad_l;

		AD_Result3 = (shiftH<<2) | (shiftL>>6);  // Combine the two registers to get full 10 bits.
		if (AD_Result2 > 500 || AD_Result3 > 500)
		{
			   //code to output both values goes here
		}

 

 

The problem I see is when I hit button 1, both AN0 and AN1 register as input.

The microchip doc says I need to set a dummy AN port to VDD and then GND.

 

Has anyone ever done this?

 

Thanks

Dan.

Edited by Pavel
applied CODE tags

Share this post


Link to post
Share on other sites

Dan,

 

I haven't tried this myself but without your full code, the part you are using, clock frequency etc. it is difficult to debug. However, I can see some basic problems.

 

You are not doing what Microchip AN1298 tells you to do. Read the note, particularly the Sensing Steps section, and try and understand the required sequence of events and what is meant to happen before you attempt to code it.

 

Where are the port/ADC initialisation, variable definitions etc.?

 

Where are you switching the ports between ADC input and Digital?

 

Why do you have massive delays of 20mS? The process needs to be done quickly and anyway long blocking delays will stop you doing anything else useful. The best way to do this is probably to use the ADC interrupt and a simple state machine. This will allow the ADC to run at the fastest rate possible in the background. Depending on the part and clock frequency dummy reads may be required to ensure that the minimum setup time is met.

 

Your conversion of the 8-bit ADC result registers to 10/16-bit is strange. Simply set the ADC for 10-bit result. Shift adresh up by 8 bits and OR it

with adresl to get your result as a short. Alternatively use the MAKESHORT macro.

 

Good luck

 

davidb

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...