Atmega32 problems Multiple ADC

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everybody. It so happened that I need to use multiple ADC in my project. I have one problem with multiple ADC so I need help a little. Actually I don't know what exactly is wrong because I use UART and I receive all my data of controller, perhaps problem is there when I transfer data type, maybe not. So I wrote 3 functions of ADC, ADC0, ADC1 and ADC2. I don't know why but last application (ADC2) is not working well I also want to add more ADC ports but I don't kwon how to do it. Perhaps somebody can to correct my mistakes with me code? And tell me exactly how to activate all ADC ports and receive correct data to UART.

My result from UART:

ADC0 value: 103
ADC1 value: 255
ADC2 value: 384 <<<<<<<<<?

Attachment(s): 

Last Edited: Mon. May 11, 2015 - 06:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wrong forum. So moving.

 

Oh and your comments are lying ;-)

 

Moderator

 

PS temp3 is an "unsigned char" - there is no way on earth an 8 bit variable could ever possibly hold 384 !

Last Edited: Mon. May 11, 2015 - 06:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for answer. Yes you are right I forgot to change it. You think the problem is regarding data types?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes you are right I forgot to change it.

???  Forgot to change >>what<<?

 

Are you posting the code you are >>actually using<<?

 

What speed is your AVR really running at?  In particular:

//9600 baud for a 16MHz Clock.
    UBRRL = 0x19;
    UBRRH = 0x00;

makes no sense to me.  4MHz?

 

You saw fit to use code with primitives for USART work.  Why don't you have the same "read_adc()" function instead of unrolling everything?

 

Once you >>are<< actually properly reporting ADC counts, then tell reference voltage and the voltage right at each of the AVR's ADC pins.  And tell the source of these voltages--do they have the proper drive?  What is the voltage on the AREF pin?  What capacitor do you have installed?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually it's very strange. I selected 255 prescaler but for some reasons shows wrong values, for example 996 when is ~0.5V. Sometimes is works well when voltage is higher than 1 V and don't know why for some reasons it is. For example 1.5 V show 118.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

for some reasons shows wrong values, for example 996 when is ~0.5V.

AN 8-BIT UNSIGNED VARIABLE CAN ONLY HAVE A VALUE FROM 0 TO 255.

 

Post the code you are actually using.  Tell how you are testing.  Tell which device is receiving the output.  Put out the numbers from 1 to n to your display device; do they come up properly?

 

If I had to guess, your left-justified output is leaving tracks on your display device.  For example, if you do two conversions and the results displayed from the first one is 123 counts and the second is 98 counts and you are not clearing the display line in between (I see cursor positioning sequence?) then:

 

ADC Value: 123  after the first; and

ADC value: 983  after the second

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I forgot to change comment in me code like this //MUX0 bit set. Input taken from ADC1

It mus to be //MUX1 bit set. Input taken from ADC1 and so on it doesn't metter.

It's good questions. :)

My boud rate is 19200 I repaired UBRRL to 12.

Yes I felt for fit in me code for USART, actually I don't find best solution for it, I have any code with USART but I don't know why is not working when I use multiple ADC. Of Course I want to find out best solution in my project. First I need to get all corect adc values.

Yes you are right for read_adc() function I was suposted to change it. Me reference voltages is about ~ 5V. Capacitor is 104 and ADC pins 16 V 47u.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I see there is a language barrier.  However, you answered virtually none of my questions, starting with:

 

-- What code are you actually using?

-- What speed is your AVR really running at?

-- Where are you sending your UART output for display?

 

If you don't understand about "left-justified output", then just change your "%u" to "%4u".  What results do you get?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I now it for unsigned variable because I want to get all data of adc between 0-255. I'm testing in real conditions. I just measurement voltage from photodiode via OA and get it to ADC input I have 4 photodiode it me device.
Okey I add below all my code. Now I need to display only 4 ADC ports but in the future I will need more that 4. In the future I will conect accelerometer to next available ADC ports.
No, I exactly know which adc ports is displayed in ADC. ADMUX 0 is ADC0, ADMUX 1 is ADC1 and so on. Seriously it works well, if you ask me what axacally ports...
I see cursor positioning sequence?

I now get it:

ADC0 value: 1
ADC1 value: 255
ADC2 value: 124

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-- What code are you actually using?

Okey I added all my code which I use now. Before last my post.

 

-- What speed is your AVR really running at?

I EXTMIIFXTARES_16 KCK_OMS  is my SUT CKSEL and outside resonator is 16 mhz.

 

-- Where are you sending your UART output for display?

Sending to my computer I display during hyperterm I use TTL convertor.

 

Actually I exaclly don't understand what's it left-justified. :/

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for %4U now it works well. :)