analogread for amplitude shift keying

I am trying to use analogread function, and amplitude shift keying, in order to convert an incoming analog signal in binary. However, my serial monitor does not display the correct number of values or at regular intervals. example: the signal is a square function @ 1KHz with a 1millisecond period and peak to peak voltage of 5.44V. Considering that the analogread reference says that each value is obtained every 100microseconds (10Khz), I expect to get 5 points which read as 1023 ( my signal peaks) and 10 points which read at 0 (signal troughs). Instead I get a wild distribution that does not remain constant. What is going on?

I don't know what is going on, and neither will any one else.

Without showing us your code we can't help you.

and peak to peak voltage of 5.44V.

So that is too much. You also need to post a schematic to see what you are doing wrong.

this is the code Im using, its just to see if I can collect consistent data code: int incomingByte = 0; boolean cycle=false; int value=0;

void setup() { Serial.begin(9600); pinMode(A0,INPUT);

} void loop() { while (cycle==false){ if (Serial.available()>0) { cycle=true;


else { value=analogRead(A0); Serial.println(value,DEC); } } }

as far as a schematic there really is nothing to it either, I have an Mega 2560 board whose pin A0 is connected to an Arduino uno which is generating a square wave through a pwm pin using the following code:

void setup() {


} void loop() {

tone(3,1000); }

the arduino pmw pin, generating the signal, is connected to the mega's A0 pin, the pin taking analogreads*

else {

... and you're wondering why it's not working ...

You won't get anywhere near 10Ksps with that. Do you have any idea how long Serial.println takes to execute? Of course, it varies depending on the length of the number read, so it's going to basically give you complete gibberish.

if I can not use the serial println function then what is my alternative? I need a way to analyze my code as I am writing it because I plan on eventually implementing logic through amplitude shift keying. Should I store the values within an array first and display them once a "sample" has been taken?

That depends on the size of the sample - you don't have much memory (compared to a computer say).

I would toggle an IO pin to represent the state of the read in analog signal - above/below a threshold, then watch that on my oscilloscope. Then do the manipulations I wanted to do on the signal as the data came in - watching for edges, etc - without having to store the actual samples.

Then you can display the results once the signal comes to an end.