NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Basic Electronics » acd with 2 inputs?
June 30, 2011 by nimaaj |
is it possible to use the analog to digital converter on the atmega chip to measure 2 signal voltages? I imagine it may be possible to make one measurement in a few milliseconds and then switch the signal over using transistors(?) or flagged opamps(?) to be measured for another few milliseconds and then switch back again is this possible? if so can anyone propose a scheme? thanx |
---|---|
June 30, 2011 by Rick_S |
The ATMega168 and 328 both have 6 ADC inputs on pins 23 thru 28. If you search the forum you'll find references to other projects that have done this. To do this, a small modification to the tempsensor project will get you up and running. To change channels to read, you'll need to change the ADMUX register. The datasheet will also give you some great info. Rick |
June 30, 2011 by Ralphxyz |
Hi nimaaj, like Rick said search the forum for Multi-Sensor you will see lots of discussions. Ralph |
July 01, 2011 by nimaaj |
Thank you very much. This made it much easier than I had anticipated. now I have another problem. setting the admux to 0 and 1 the inputs work fine. but admux 2 and 3 do not return the expected values no matter what input is connected to the corresponding pins. Is there any specific treatments i need to do to use the third and fourth pins for input? |
July 01, 2011 by nimaaj |
I should add that, when input three and four are shorted to the ground or vcc the correct output is displayed however when the signal such as the one that is applied to inputs 1 and 2 are connected to pin 3 or 4 the correct input is not displayed. It is behaving as if pin 3 and 4 have an intrinsic voltage coming out through an internal resistor.. any help would be appreciated. |
July 01, 2011 by Ralphxyz |
[quote] Is there any specific treatments i need to do to use the third and fourth pins for input? [/quote] Short answer NO! That is strange if you are literally switching input 1 or 2 with input 3 or 4 with out any difference in wiring or code (besides pointing to the correct pin). Show us your code please. In retrospect I have gotten similar behavior, but there was something "I was doing" unknowingly. Ralph |
July 03, 2011 by BobaMosfet |
Make sure you have the ADC pins configured as inputs. They all reference ADC Ref, don't change this, and whatever you measure must be on the same ground loop. BM |
July 03, 2011 by nimaaj |
thanks for the replies, I have attached the code. Also all inputs are relative to the same ground. I tested the circuit by applying the same analog input to the different input pins, but only the first 2 inputs return acceptable results.
|
July 03, 2011 by Ralphxyz |
Are you switching between the same sensor or using different sensors? What do you get when you tie all pins to Grn at the same time? What do you get when you tie all pins to Vcc (+) at the same time? Ralph |
July 03, 2011 by nimaaj |
I am using the same sensor for all pins. I am getting 0 when all pins are grounded. I get 100 when all pins are tied to Vcc+ |
July 04, 2011 by Ralphxyz |
Darn, ok, now what sensors are you using? Are you using the same type sensors on all of the pins? I do not know why you age seeing 100 @ Vcc you should be seeing 1024 there must be a division in your code, that shouldn't matter any way. Have you tried running my Multi-sensor code? That works for me. Ralph |
July 07, 2011 by Hexorg |
Ralph, he's doing a division by 10.24 to get a scale from 0 to 100 instead of 0-1023... Which makes me realize, nimaaj, you should divide by 10.23, because ADC will output 1023 maximum (1023 = 0b111111111111). But like Ralph said, that shouldn't affect the result dramatically. I don't see anything bad in the code, so check your wiring, something might be wrong there. |
July 07, 2011 by bretm |
One minor problem, and probably not the main issue, is that you need to throw away the first sample you take after changing ADMUX because the previous reading started a new measurement with the prior ADMUX value. Or you could just change the sampling function so it doesn't do that. The tempsensor code really needs a comment added to it to warn people that its not suitable for multi-channel ADC. |
July 07, 2011 by nimaaj |
thanks for the responses. I will modify the code to get rid of the first reading. At this point I'm thinking that the adjacent pins on the board are connected by some resistance or through a short somehow, or possibly a damaged chip. But I have been occupied with another project for the past few days. I have ordered new chips from nerdkits and will be testing the circuit again after my other project is completed. If I manage to figure out the problem I will post it on the forums. |
July 13, 2011 by nimaaj |
Ok so I got my new chip today. I tried the new chip and I'm still getting the same results That is if I set 3 pins for input : 1) when left floating they read 3% to 4% of 5 Volts 2)when one of the pins is connected to +VS, that pin reads 100% of 5 Volts and the other 2 pins read 30% to 40% of 5 Volts!! 3) when a voltage somewhere between 0 and 5 Volts is connected to one of the adc inputs it will give the correct reading but it will also effect the other 2 unconnected adc pin readings!! At this point I'm thinking I should put high resistances between adc pins and ground to act as a pull down resistor for the floating pins... Or if anyone else has any ideas or suggestions I'd be very grateful |
July 13, 2011 by nimaaj |
new finding: Ok I was using a program I made to plot the adc readings as a time graph on my laptop and it seems that the pins charge and discharge like capacitors. I've attached a picture of the graph: The yellow is adc 1 and the red is adc 2. The jump in voltage is when i short the one of the adcs to +VS |
July 13, 2011 by BobaMosfet |
nimaaj- I hate to see you flounder. First of all, yes- you are experiencing capacitive effects- that is what you would expect. It virtually univeral in electrical engineering that you tie your inputs hi or low to eliminate this problem. Outputs are less bothersome. As for ADC resolution, that is 1024, not 1023, as some have suggested. Zero to 1023 is, in fact, 1024 discrete values. BM |
July 14, 2011 by Ralphxyz |
And since the other pns are "floating" what do you care what they might read? If you want to read them as ADC input then you have to have an ADC source (0 - 5v) they can not be left floating. Ralph |
Please log in to post a reply.
Did you know that one NerdKits customer controlled a laser pointer with his computer using a microcontroller? Learn more...
|