In my project I’m using different analog inputs for reading voltage, temperature etc.
I couldn’t get my voltage to be correct, so I started tracking down the problem, and it seems that when I enable ADC0, my reading from ADC2 gets screwed up. If I don’t enable it, the readings are correct). Below are some raw reading from ADC2 (just with the pin floating with nothing attached, so i jumps arround a bit):
…
21
2
34
0
29
46
33
0
36
0
48
14
Enable analog 0
100
190
190
188
144
191
201
102
102
137
224
…
As you can see the values are suddenly larger. Why is that? Am i missing something? I don’t use the touch controller, I use my own I2C capacitive touch, so I should be able to use ADC0.
I also have seen this and my voltages are well below 3V.
More troubling for me was the ripple that is present on the analog inputs. My scope can’t pick up much variance in the analog signal, but connected to Cobra I get a bunch.
My solution was to write some filtering routines (stdev, moving average etc.), but I wish I did not have to. Putting caps on the signal did not help. Made me think the issue was internal to the EMX board or I was doing someting wrong. Since accuracy is not critical for me yet I have left this to later debug sessions.
I don’t know how the GHI controls the ADC’s but maybe the problem is they don’t wait long enough to sample the input after they switch the analog channel multiplexer to another channel.
@ Gus
Yes the cap touch works very vell…very responsive
Regarding the ADC. Currently there’s no voltage comming in on the pin… the test is on a completely clean EMX dev. board with nothing attached to the pins. So it’s not voltage problem. Furthermore this behavior only occurs when i enable ADC0 or ADC1, the others are fine.
So my thoughts is that this is caused by something related to the default touch controller?
Below is the code i used for testing:
public static void Main()
{
Program myApplication = new Program();
Window mainWindow = myApplication.CreateWindow();
GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);
myApplication.Run(mainWindow);
}
private Window mainWindow;
private AnalogIn ad2;
private AnalogIn ad0;
public Window CreateWindow()
{
mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth;
mainWindow.AddHandler(Buttons.ButtonUpEvent, new RoutedEventHandler(OnButtonUp), false);
mainWindow.Visibility = Visibility.Visible;
Buttons.Focus(mainWindow);
ad2 = new AnalogIn(AnalogIn.Pin.Ain2);
Thread t = new Thread(ReadAnalog);
t.Start();
return mainWindow;
}
private void ReadAnalog()
{
while(true)
{
double rawVoltage = (double) ad2.Read();
Debug.Print(rawVoltage.ToString());
Thread.Sleep(100);
}
}
private void OnButtonUp(object sender, RoutedEventArgs evt)
{
ButtonEventArgs e = (ButtonEventArgs)evt;
Debug.Print("Enable analog 0");
if(ad0 == null)
ad0 = new AnalogIn(AnalogIn.Pin.Ain0);
Debug.Print(ad0.Read().ToString());
}
try to attach somthing to ADC. It’s probably hardware not a software.
When there is nothing on ADC it catches inputs from other (near ones) pins.
On AVR mega I saw situation when sensor connected to adc0 made proportional input to adc7 and all pins in between. Tho when there was connected sensors on all adc’s they messured correct readings. I think it might be the same on your controller.
I’m curious, does setting the AD0 (IO8) to an outputport have the same positive effect? I assume you had to ground directly to the EMX board because IO8 is not exposed on the IO header, but rather the Display header?