IPB


Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
help!!!ADC 8535
Digg this topic · Save to del.icio.us · Slashdot It · Post to Technorati · Post to Furl · Submit to Reddit · Share on Facebook · Fark It · Googlize This Post · Add to ma.gnolia · Tag to Wink · Add to MyWeb · Add to Netscape
chrisnejm
post Sep 23 2003, 01:54 PM
Post #1


Junior Member
**

Group: Members
Posts: 6
Joined: 23-September 03
Member No.: 499



hi im in desperate need of some help. using the stk500 and an 8535 chip.

All i'm trying to do is to read a voltage from portA, (which i think is the default for analog input) and output that value through a serial interface. I used the code wizard and this is what i got.

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input;

// Start the AD conversion
ADCSR|=0x40;

// Wait for the AD conversion to complete
while ((ADCSR & 0x10)==0);
ADCSR|=0x10;
return ADCW;
}

to access this function in my code.
i use:

rawdata=read_adc(0);

which as far as my knowledge goes will get the value of the reading at pin.0 and store the value in rawdata.
It does not work, i don't get the value of the voltage, i get 0 when a voltage is connected and 15 when it isn't connected.

Can anyone please hekp?? Do i need to connect something? do i need more code? Any initialisation?
Go to the top of the page
 
+Quote Post
marke
post Sep 23 2003, 07:28 PM
Post #2


Posting Freak
******

Group: Moderator
Posts: 2,097
Joined: 24-April 02
From: Christchurch, New Zealand
Member No.: 1



Hello chrisnejm

Welcome to the forum.
At an initial look, the A/D routine looks OK to me. I normally run the adc continuously under interrupt and read the value on the fly, saves waiting for the result.
Is there a problem in the way you are processing this data for output?

Best regards,


--------------------
Go to the top of the page
 
+Quote Post
chrisnejm
post Sep 24 2003, 12:54 AM
Post #3


Junior Member
**

Group: Members
Posts: 6
Joined: 23-September 03
Member No.: 499



Thanks for your reply,
maybe i do have to process the data first before outputing. But i'm not sure how to do it. The reason i'm not using interrupts is that i only need to read the input of the ADC once a minute.

Is there an ADC initialisation? It would be a great help if you could tell me how to process the result.
Go to the top of the page
 
+Quote Post
marke
post Sep 24 2003, 08:13 PM
Post #4


Posting Freak
******

Group: Moderator
Posts: 2,097
Joined: 24-April 02
From: Christchurch, New Zealand
Member No.: 1



How do you know it is not working?
There are two possibilities, one is that you are not outputing the data correctly, and the other is that the ADC is not reading the correct data.
Make sure that you hae the STK500 set up correctly, you need to ensure that you have a voltage reference for the ADC. This can be internal or external and from memory, there is a jumper to set this.

Have you proven your serial output routines, I would suggest that you output some text, hello world or some such, then output some initialised variables, then do some math on those variables and output that. At that stage, you then have the ability to output a variable that you have not directly initialised but know the value of. You should now be able to output your variable rawdata correctly.
The other thing to do, is to write the lower bite of raw data to say port B and connect that to the LEDs on the STK500. Check the polarity of the outputs relative to the LEDs, i.e. are the LEDs on for a 0 or ON for a 1.
Best regards


--------------------
Go to the top of the page
 
+Quote Post
chrisnejm
post Sep 25 2003, 04:44 AM
Post #5


Junior Member
**

Group: Members
Posts: 6
Joined: 23-September 03
Member No.: 499



Thanks again for your reply marke,

i do have the serial interface working correctly, i get text ouput when required, and i also get a value of rawdata, which is the ADC output but that result is always 0.
The value of the ADC stored in ADCW, what format is it in? HEX, BIN?
I was wondering if i need to use some code to convert the data to a decimal value? I'm not sure how to do this.
And how is it possible to set ADC voltage reference internally?
Is it :

#define ADC_VREF_TYPE 0x60

I'm not sure. I want the ref voltage to be 2.4 volts, i think this is wrong.

Tahnk you so much for your help,
Chris.
Go to the top of the page
 
+Quote Post
marke
post Sep 25 2003, 08:07 PM
Post #6


Posting Freak
******

Group: Moderator
Posts: 2,097
Joined: 24-April 02
From: Christchurch, New Zealand
Member No.: 1



The value of ADC stored in ADCW is stored as binary in a WORD.
If the output is 0, then that would suggest that you do not have a reference voltage connected to the micro. This is an external reference and is set by a jumper on the STK500

Best regards,


--------------------
Go to the top of the page
 
+Quote Post
marke
post Oct 1 2003, 09:50 AM
Post #7


Posting Freak
******

Group: Moderator
Posts: 2,097
Joined: 24-April 02
From: Christchurch, New Zealand
Member No.: 1



Hello chrisnejm

Have you managed to solve your problems yet??
Let me know haw far you have got, and if I get a chance I will see if I can help.

Best regards


--------------------
Go to the top of the page
 
+Quote Post
marke
post Oct 2 2003, 11:18 AM
Post #8


Posting Freak
******

Group: Moderator
Posts: 2,097
Joined: 24-April 02
From: Christchurch, New Zealand
Member No.: 1



Hello chrisnejm

Attached is some code for reading the ADC port under interrupt and writing the output to an LCD display using a mega128.
This code does work. Not quite what you are looking for, but you may pick up something from it.

Best regards
Attached File(s)
Attached File  lcd_test.c ( 5.17K ) Number of downloads: 85
 


--------------------
Go to the top of the page
 
+Quote Post
chrisnejm
post Oct 6 2003, 03:31 AM
Post #9


Junior Member
**

Group: Members
Posts: 6
Joined: 23-September 03
Member No.: 499



thans a lot for your help mark, i got everything working fine now.
I took a while to work out but i managed to set the right bits in the register ADSCR.
Thanks again for your help
chris
Go to the top of the page
 
+Quote Post
marke
post Oct 6 2003, 08:34 AM
Post #10


Posting Freak
******

Group: Moderator
Posts: 2,097
Joined: 24-April 02
From: Christchurch, New Zealand
Member No.: 1



Hi Chris

No problems. You can use the code wizard to set most of that up for you, makes life easy, but you don't learn how things really work till you set it manually.
Best regards,


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   0 Anant 592 23rd June 2008 - 06:30 AM
Last post by: Anant



RSS Lo-Fi Version Time is now: 21st November 2008 - 04:30 AM
hosted by : L M Photonics Ltd