Jump to content

help!!!ADC 8535


chrisnejm

Recommended Posts

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?

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

lcd_test.c

Link to comment
Share on other sites

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,

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...