PeterH:
Suggest you attach your code, and a description/drawing of your hardware, because there are different sorts of interrupt available on different pins.
Hello.
Thanks for your reply.
There is a mixed Signal oscilloscope (Tektronix),Digital caliper, and small amplifying Circuit consisting of one BJT PNP transistor (Common Collector) with several resistors to amplify the signal from 1,5v to 3,3v so the Arduino Due can read it through the Digital pins number 2 and 3,they both require 3,3v. The Data signal is connected to Digital Pin number 3, the clock signal is connected to Digital pin number 2.
This is DRO output format
2x 24bit serial data (Abosulte poistion; Relative position)
Data is LSB first, 2's complement
0x5000 (20480) count/inch or 806.299 counts / mm
clock: 13us /bit == 76.92KHz
data output rate = 3.125 Hz
Start bit length = 52.2 uS
And I also attached an image of the data and clock signals captured on Oscilloscope's Screen, though it doesn't include
the inverted and amplified Digital and Clock Signals.
Arduino DUE should read data signal at each falling edge of the clock signal, it should also confirm that the read
data was accurate at the rising edge, and if the clock signal goes low for 24 times it means that the data set is complete and ready to be sent to the pc via Serial port, there is also start bit of 52,2 uS length that should be identified and not confused with other bits.
This is the code after I modified it and had to cancel the interrupts at Rising and falling edge of the clock signal and got restricted to HIGH level interrupt.
int CAL_CLK =2;
int CAL_DATA =3;
unsigned long now;
unsigned long lastInterrupt;
volatile long finalValue; //
volatile long value;
int bits=0; // Number of received bits
volatile long data;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(CAL_CLK, INPUT); // Clock pin = 2
pinMode(CAL_DATA, INPUT); // Data pin = 3
attachInterrupt(0, dataReceived, HIGH);
}
void dataReceived() {
now=millis();
if((now-lastInterrupt)>150) //if more than 150 milliseconds have passed since the first interrupt print the value
{
Serial.println(finalValue,HEX);
}
else{
data = digitalRead(CAL_DATA);
if(bits==0)
{
value=0;
lastInterrupt=now; To measure the length of time between the first and current interrupt
}
if(bits<16) // the first 16 bits indicate the value of the data set
{
if(data==0)
{
value |= 1<<(23-bits);
}
}
if(bits==20) // if 21st fit (sign bit) is 1,then invert the value and add 1 (second complement)
{
if(data==1)
{
value = (~value)+1;
}
}
if(bits==23){
finalValue=value;
bits=0; //if 24 bits have received , set the finalValue to be sent and start again.
}
bits=bits+1;
}
}
void loop() {
// put your main code here, to run repeatedly:
}
Also I'v been told that the data output rate is 3.125 Hz, which means that 3 sets of 48 bits is sent every second,so for 24 bits of data arduino should send every 150 milliseconds approximately, but its not working, I'm having to disable the timer removing the first three lines of dataReceived() function and put Serial.println(finalValue,HEX); inside if(bits==23){} instead.
Moderator edit: code tags { sigh }