Thread: ADC doesnt work

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    37

    ADC doesnt work

    Code:
    void ky_dReadSteering(void){
    	uchar temp; 
    
    
    	d_kyStrADReg = u_adcPort(AN0);
    	d_kyStrADReg = d_kyStrADReg >>6;
    
    
    	if(d_kyStrADReg < 0x74)
        {
        	d_kyStrAD = 0x00;				/* K_OFF        */
    	}
    	else if(d_kyStrADReg < 0x4D8)
    	{
    		d_kyStrAD = 0x9d;				/* MUTE			*/
    	}
    	else if(d_kyStrADReg < 0x745)
        {
        	d_kyStrAD = 0xcd;				/* VOL UP       */
        }
    	else if(d_kyStrADReg < 0x278)
    	{
        	d_kyStrAD = 0x0d;				/* VOL DN       */
    	}
    	else if(d_kyStrADReg < 0xC5C)          
        {
        	d_kyStrAD = 0x21;				/* FUNC			*/
    	}
    	else if(d_kyStrADReg < 0x9EF)          
        {
        	d_kyStrAD = 0x8a;				/* SEEK UP      */
    	}
        else if(d_kyStrADReg < 0xE4C)
        {
        	d_kyStrAD = 0x44;				/* SEEK DN      */
    	}
        else 
        {
            d_kyStrAD = B00000000;				/* K_OFF        */
    	}
    
    
    	if( d_kyStrAD != (uchar)d_kyStrPort.all )
    	{
    		d_kyStrPort.all = d_kyStrAD;
    		d_stPortCnt = 0;
    		f_stPortchg = 1;
    	}
    	else
    	{
    (KY_STR_SCAN_COUNT-1) */
    		if(f_stPortchg)
    		{
    			if(d_stPortCnt > (KY_STR_SCAN_COUNT - 1))
    			{
    				f_stPortchg = 0;
    				d_stPortCnt = 0;
    				f_scnrq = 1;				/*1:key scan request		*/
    			}
    			else
    				d_stPortCnt++;
    		}
    	}
    }
    this code is for an AD converter. my voltages are
    vol dn 2.39
    vol up 1.704
    seek dn 1.08
    seek up 3.29
    func 0.19
    mute 0v

    my pull up v is 3.3 with 1000 ohm pull up resistor

    please tell me what i've done wrong!

    Thank you

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    How does it not work? Also, what are the types of the variables involved, and what are they for (you wouldn't have to explain what they are for if you used more descriptive variable names)?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    37
    hi laserlight,

    the d_kystrAD is the value of the remote key for each functions (func, mute, vol up vol dn etc) obtained from the remote via AD
    the d_kyStrADReg is the value of the converted AD from the AD converter

    while the v drop is consistent and it should be working, it doesnt. the port is declared correctly and the compiler has a built in ADC.
    im thinking its the values of the d_kyStrADReg but im not sure how am i to change the values, i meant into what value.

    does this ans your Q?

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by kim15 View Post

    my pull up v is 3.3 with 1000 ohm pull up resistor

    please tell me what i've done wrong!

    Thank you
    Where and why do you have a "1000 ohm pull up resistor"?

    What chip are you using?
    What Compiler are you using?
    Do you have Analog input enabled?
    What is wrong?
    (What is the output that is wrong? What should it be instead?)

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Dec 2012
    Posts
    37
    Quote Originally Posted by stahta01 View Post
    Where and why do you have a "1000 ohm pull up resistor"?

    What chip are you using?
    What Compiler are you using?
    Do you have Analog input enabled?
    What is wrong?
    (What is the output that is wrong? What should it be instead?)

    Tim S.
    1kohm is put at the ADC input (before the V goes into the ADC).
    and yes my analog input is enabled.
    im using a TMPM321F10FG chip
    Im using a keil microvision 4

    seems that only 2 of my buttons are functioning. the last 2 ones. for the top 4 buttons, it doesnt seem to go into the range at all. even when I have set the watch on the kyStrADReg. the values stated on the watch is similar or in the range of the keys but they do not go in. im baffled. do u know why?

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Without seeing a schematic and how you actually configure your microprocessor (Post the complete program!) it's almost impossible to tell you what is wrong. Also post a link to your microprocessor/development board data sheet.

    Jim

  7. #7
    Registered User
    Join Date
    Dec 2012
    Posts
    37
    Quote Originally Posted by jimblumberg View Post
    Without seeing a schematic and how you actually configure your microprocessor (Post the complete program!) it's almost impossible to tell you what is wrong. Also post a link to your microprocessor/development board data sheet.

    Jim
    hiya jim, thanks. but i've solved most part of it. seems that i dont need to shift it at all. and that is what the main cause for the remote not to work.I'm only left with one more and it should be done.

    Just one question (not cprog related though) i have 6 buttons and all 5 of them have different voltage drops across them except for one (which doesnt have any drop or very very little voltage drop across the switch. and therefore I cant seem to get any reading.

    Now my circuits a little rusty, but i know that with a resistor of 162 ohm and 3.3 v pull up and 1000 ohm pull up resistor, i should be getting much much lesser than that.

    Thats the only button that I am having problems with.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    What is the resolution of your ADC? 8 bit? 10 bit? 12 bit? What is your ADC reference voltage? What voltage are you using for your pullup?

    Please show a simple schematic of how you connected your switches, and the resistors in this circuit. Be sure you include the resistor values.

    Did you try printing the value the ADC is reporting when you press each switch? Are you getting your expected values? What value does your ADC report when no switches are pressed? What value does your ADC report when you connect the input to ground and VCC?


    Jim
    Last edited by jimblumberg; 05-08-2013 at 06:13 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why doesnt this work
    By Hugo716 in forum C++ Programming
    Replies: 13
    Last Post: 05-18-2006, 11:57 AM
  2. Why doesnt this work
    By digdug4life in forum C++ Programming
    Replies: 13
    Last Post: 06-19-2005, 03:22 PM
  3. Why doesnt this work
    By Jotun in forum C++ Programming
    Replies: 3
    Last Post: 04-18-2004, 04:55 PM
  4. How come this doesnt work?
    By correlcj in forum C Programming
    Replies: 2
    Last Post: 07-11-2002, 06:36 PM
  5. why doesnt this work?
    By brad123 in forum C Programming
    Replies: 3
    Last Post: 04-23-2002, 05:26 PM