Jump to content


Photo

help!!!ADC 8535


  • Please log in to reply
9 replies to this topic

#1 chrisnejm

chrisnejm

    Junior Member

  • Members
  • PipPip
  • 6 posts

Posted 23 September 2003 - 01:54 PM

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?

#2 marke

marke

    Posting Freak

  • Moderator
  • PipPipPipPipPipPip
  • 2,651 posts
  • Gender:Male
  • Location:Christchurch, New Zealand

Posted 23 September 2003 - 07:28 PM

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,

#3 chrisnejm

chrisnejm

    Junior Member

  • Members
  • PipPip
  • 6 posts

Posted 24 September 2003 - 12:54 AM

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.

#4 marke

marke

    Posting Freak

  • Moderator
  • PipPipPipPipPipPip
  • 2,651 posts
  • Gender:Male
  • Location:Christchurch, New Zealand

Posted 24 September 2003 - 08:13 PM

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

#5 chrisnejm

chrisnejm

    Junior Member

  • Members
  • PipPip
  • 6 posts

Posted 25 September 2003 - 04:44 AM

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.

#6 marke

marke

    Posting Freak

  • Moderator
  • PipPipPipPipPipPip
  • 2,651 posts
  • Gender:Male
  • Location:Christchurch, New Zealand

Posted 25 September 2003 - 08:07 PM

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,

#7 marke

marke

    Posting Freak

  • Moderator
  • PipPipPipPipPipPip
  • 2,651 posts
  • Gender:Male
  • Location:Christchurch, New Zealand

Posted 01 October 2003 - 09:50 AM

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

#8 marke

marke

    Posting Freak

  • Moderator
  • PipPipPipPipPipPip
  • 2,651 posts
  • Gender:Male
  • Location:Christchurch, New Zealand

Posted 02 October 2003 - 11:18 AM

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 Files



#9 chrisnejm

chrisnejm

    Junior Member

  • Members
  • PipPip
  • 6 posts

Posted 06 October 2003 - 03:31 AM

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

#10 marke

marke

    Posting Freak

  • Moderator
  • PipPipPipPipPipPip
  • 2,651 posts
  • Gender:Male
  • Location:Christchurch, New Zealand

Posted 06 October 2003 - 08:34 AM

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,




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users