I spoke too soon. (sad face - but hoping for an embarrasing correction to an obvious mistake I have missed)
This shows measurements from pins A0 and Pin A1. A0 is connected to my 50Hz signal. Pin 1 is grounded. All made with the version of the core software I downloaded yeaterday.
The blue line is measuring A0 pause 50uS and A0 again and pause 50uS in a loop. Very good!
The red line is the same for A1. It runs along the origin and has values of 0 or 1. Still very good
The green line is A0 (the pin with 50Hz) when I measure A0 pause 50uS A1 pause 50uS in a loop
The purple line is A1 measured at the same time. Something is wrong! Purple is grounded Green is 50Hz. I’ve checked many times.
I have checked my software and the readings really are apparently the wrong way round and how about the noise - where did that come from? Increasing the delay in the loop to 250uS makes no difference except to the number of cycles sampled…
Bear in mind there is absolutely no change in the hardware between the good and bad results, purely interleving ADC readings from pins A0 and A1.
The software for the interleved case is below. For the non-interleved just use A0 or A1 for both measurements.
/*
* File: PCtestADC
* Author: Pete
* This waits for a ready signal and sends a string to the client
* Created on 08 February 2014, 11:36
* Uses Serial
*
*/
/* Includes ------------------------------------------------------------------*/
#include "application.h"
/* Function prototypes -------------------------------------------------------*/
/* Variables -----------------------------------------------------------------*/
int LED = D7;
int ADC = A0;
//
//char UDPincomingData[256];
//char UDPoutgoingData[256];
unsigned long lastRead;
unsigned long t1;
unsigned long t2;
unsigned long t3;
unsigned long t4;
int lag;
int netTime;
int i;
int j = 0;
unsigned int myADC0[256];
unsigned int myADC1[256];
/* This function is called once at start up ----------------------------------*/
void setup() {
pinMode(D7, OUTPUT); // Turn on the D7 led so we know it's time
pinMode(A0, INPUT);
digitalWrite(D7, HIGH); // to open the Serial Terminal.
Serial.begin(9600); // Open serial over USB.
while (!Serial.available()); // Wait here until the user presses ENTER in the Serial Terminal
digitalWrite(D7, LOW);
Serial.println("Ready");
do{
myADC0[0] = analogRead(A0);
}
while ((myADC0[0]<2036) && (myADC0[0]>2060));
lastRead = millis();
t1 = millis();
t2 = millis();
digitalWrite(D7, HIGH);
for (int i = 0; i < 256; i++) {
myADC0[i] = analogRead(A0);
//digitalWrite(D7, !digitalRead(D7));//delay
delayMicroseconds(200);
myADC1[i] = analogRead(A1);
delayMicroseconds(200);
}
t3 = millis();
delay(500);
digitalWrite(D7, HIGH);
Serial.println(((t3-t2)-(t2-t1)));
Serial.println(((t3-t2)-(t2-t1))/256.0);
for (int i = 0; i < 256; i++) {
Serial.println(myADC0[i]);
delay(10);
}
Serial.println("----------------------------------");
for (int i = 0; i < 256; i++) {
Serial.println(myADC1[i]);
delay(10);
}
}
/* This function loops forever --------------------------------------------*/
void loop() {
}
I’m afraid that’s me done for a while. I have a plane to catch.