This is probably obvious, but just in case it isn't.
I could imagine if you are using a delay to do a debounce, that you would want to read both values first, then do the delay, and read them again and compare to the originals. Then just subtract. You probably don't want to do read first, delay, read first again, read second, delay, read second again.
I've read posts about allowing time for the ADC to switch and read the value of a different pin, does this still need to be put into consideration or is it handled internally? For example, if it were still relevant, you may find you get more stable readings from the following:
NathanNZ:
I've read posts about allowing time for the ADC to switch and read the value of a different pin, does this still need to be put into consideration or is it handled internally?
That's only an issue if the source impedances are high - if 10k or so or less, not an issue at all.
If you don't tell us what you have you will always get answers whoich might work -- but might not be the best or what you want. Maybe they are what you want. How would you know?
This is from the Mega 2560 Manual -- a comparator is built in. Surprise!
The Analog Comparator compares the input values on the positive pin AIN0 and negative pin AIN1. When the voltage on the positive pin AIN0 is higher than the voltage on the negative pin AIN1, the Analog Comparator output, ACO, is set. The comparator’s output can be set to trigger the Timer/Counter1 Input Capture function. In addition, the comparator can trigger a separate interrupt, exclusive to the Analog Comparator. The user can select Interrupt triggering on comparator output rise, fall or toggle. A block diagram of the comparator and its surrounding logic is shown in Figure 24-1. The Power Reduction ADC bit, PRADC, in “PRR0 – Power Reduction Register 0” on page 56 must be disabled by writing a logical zero to be able to use the ADC input MUX.
The you can decide if you want to use the comparator or not.
I am a beginner and I have a school project to develop the Arduino Mega2560.
It consists of 2 electrodes that are placed on the head. I have to measure the potential difference between them (because one of them is the reference), amplify the signal and make a chart.
My big problem is that I can not find and do not even know how to use differential inputs with gain (10x or 200x).
Somebody please (with some urgency), can give me a code example?
My big problem is that I can not find and do not even know how to use differential inputs with gain (10x or 200x).
No problem you can't. There is no differential input on any arduino board.
can give me a code example
Why, this is a hardware problem not a code issue.
This is an almost impossible project for you with limited electronics knowledge. You will end up measuring muscle movement rather than anything else. It is also dangerous having a low impedance circuit across your head if you touch any other part of the circuit.
As a start read:- http://www.researchgate.net/post/What_sensors_do_you_suggest_for_detecting_brain_waves
You'll need an instrumentation amplifier to measure the difference in potential between two electrodes. The REF pin of the IA can be tied to 2.5V so that you can handle both positive and negative inputs.
50Hz or 60Hz mains interference may be a problem, unless you run everything from batteries and go to the middle of a field to take readings.. You will probably need to follow the IA with a notch filter to remove this, and then an op amp to provide further amplification before the signal is large enough for an Arduino to digitize.
However, you should consider the safety aspects. What would happen if the Arduino was being powered from USB, and the computer developed an earth fault? Medical EEG equipment has a high degree of isolation between the electrode amplifier module and the rest of the equipment, so as to be safe in the event of an equipment fault. One possibility is for you to power the Arduino from a battery while it is taking measurements, but then you won't be able to print the data directly to a chart. You could collect the data, save it to an SD card, and subsequently generate the chart from the data on the card.
@vieuxpalleto - that is a question for your own thread. This was dealing with differential ADC input on the mega (which is possible but not very easy to use.)
As for the 5+ 0 5- problem, you have two analog inputs, each tells a direction. The one that would go -5V needs to be inverted to positive voltage with a simple inverting voltage follower/buffer. See picture .. you would then attach a small diode with stripe connected to the op-amp, this will protect the analog input from getting -5V when the sensor output swings to positive. Basically the inverting buffer just changes the input from the sensor when it goes -5V. The resistor values need to be the same for a gain of 1.
D2 - Sensor Output 0..-4.4V when input swings 0 to -5V (D2 blocks when op-amp output swings neg)
D1 - Sensor Output 0..+4.4V when input swings 0 to +5V (follows only positive part of input)
D1/D2 need separate analog inputs to determine absolute position. Good luck.
Arduino can measure +/-5volt with a normal 2-resistor voltage divider, e.g. 10k:10k.
The resistor that is normally connected to ground is now connected to 5volt.
That gives 2.5volt on the divider with 0volt input (value ~512).
Leo..
dc42:
You'll need an instrumentation amplifier to measure the difference in potential between two electrodes. The REF pin of the IA can be tied to 2.5V so that you can handle both positive and negative inputs.
True
50Hz or 60Hz mains interference may be a problem, unless you run everything from batteries and go to the middle of a field to take readings.. You will probably need to follow the IA with a notch filter to remove this, and then an op amp to provide further amplification before the signal is large enough for an Arduino to digitize.
Not so true and overkill, if proper grounding techniques are observed and implemented IE; no daisy chains or ground loops, also if you have "box" or faraday shielding, only one end of the shielded cable need be grounded to the case.
However, you should consider the safety aspects. What would happen if the Arduino was being powered from USB, and the computer developed an earth fault? Medical EEG equipment has a high degree of isolation between the electrode amplifier module and the rest of the equipment, so as to be safe in the event of an equipment fault.
A good idea and design practice. Running from a USB phone recharge pack will work well, just observe that they usually time-out if there isn't enough current draw (> ~ 200mA)