the encoder needs to run around 15,000 pulses per second. based on what I found in the forums it looks like I can use timer1 with a prescale divider of 1 to generate a clock signal around 31k which should be sufficient (though way lower than the max clock of 33mhz). I added the following code to make this happen- also connected the clock input on the IC to pin 11:
TCCR1B = (TCCR1B & 0xF8) | 1 ;
analogWrite (11, 128) ;
Additionally, I tied the RST and INDEX to their own digital pins and wrote them low in the setup function.
However, I am still getting the same 0000 output. I am wondering two things now. First, am I simply converting the data wrong as it comes into the software? I am pretty sure they way it is suppose to work is that the 4 bytes that I am collecting should form a 32bit value that tells me the encoder count. Secondly, I have seen a few other examples where 8 bit parallel communication is used and in those examples there are small delays between random steps of getting the data from the buffer- do I also need to include these delays?
Thank you all for the help- it's really appreciated. esp @johnwasser!
Again just for reference here is the revised basic wiring and the code I am using:
Vdd -> +5v
Vss -> Ground
CLK -> SCL (D21)
OE -> D43
SEL1 -> D44
SEL2 -> D45
RST -> D42 (not used)
D0 -> D46
D1 -> D47
D2 -> D48
D3 -> D49
D4 -> D50
D5 -> D51
D6 -> D52
D7 -> D53
CHA -> Encoder A
CHB -> Encoder B
INDEX -> D41 (not used)
Open pins on 2022:
U/D
TEST
int oePin = 43;
int sel1Pin = 44;
int sel2Pin = 45;
int daPin0 = 46;
int daPin1 = 47;
int daPin2 = 48;
int daPin3 = 49;
int daPin4 = 50;
int daPin5 = 51;
int daPin6 = 52;
int daPin7 = 53;
int indexPin = 41;
int resetPin = 42;
int clockPin = 11;
int dataValue;
byte MyByte;
void setup() {
Serial.begin(9600);
Serial.println("online");
pinMode(oePin, OUTPUT);
pinMode(sel1Pin, OUTPUT);
pinMode(sel2Pin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(resetPin, OUTPUT);
pinMode(indexPin, OUTPUT);
pinMode(daPin0, INPUT);
pinMode(daPin1, INPUT);
pinMode(daPin2, INPUT);
pinMode(daPin3, INPUT);
pinMode(daPin4, INPUT);
pinMode(daPin5, INPUT);
pinMode(daPin6, INPUT);
pinMode(daPin7, INPUT);
//setup timer1 prescale divider to be 1
TCCR1B = (TCCR1B & 0xF8) | 1 ;
//setup clock output
analogWrite (clockPin, 128) ;
//write these pins LOW so they don't do anything
digitalWrite(indexPin,LOW);
digitalWrite(resetPin, LOW);
}
void loop()
{
ReadData();
delay(250);
}
void ReadData() {
//set the OE pin low to read the tr-state buffer
digitalWrite(oePin, LOW);
//first byte
digitalWrite(sel1Pin, LOW);
digitalWrite(sel1Pin, HIGH);
delay(10);
MyByte =
digitalRead(daPin0)|
(digitalRead(daPin1)<< 1) |
(digitalRead(daPin2)<< 2) |
(digitalRead(daPin3)<< 3) |
(digitalRead(daPin4)<< 4) |
(digitalRead(daPin5)<< 5) |
(digitalRead(daPin6)<< 6) |
(digitalRead(daPin7)<< 7);
Serial.print(MyByte,BIN);
//second byte
digitalWrite(sel1Pin, HIGH);
digitalWrite(sel1Pin, HIGH);
delay(10);
MyByte =
digitalRead(daPin0)|
(digitalRead(daPin1)<< 1) |
(digitalRead(daPin2)<< 2) |
(digitalRead(daPin3)<< 3) |
(digitalRead(daPin4)<< 4) |
(digitalRead(daPin5)<< 5) |
(digitalRead(daPin6)<< 6) |
(digitalRead(daPin7)<< 7);
Serial.print(MyByte,BIN);
//third byte
digitalWrite(sel1Pin, LOW);
digitalWrite(sel1Pin, LOW);
delay(10);
MyByte =
digitalRead(daPin0)|
(digitalRead(daPin1)<< 1) |
(digitalRead(daPin2)<< 2) |
(digitalRead(daPin3)<< 3) |
(digitalRead(daPin4)<< 4) |
(digitalRead(daPin5)<< 5) |
(digitalRead(daPin6)<< 6) |
(digitalRead(daPin7)<< 7);
Serial.print(MyByte,BIN);
//fourth byte
digitalWrite(sel1Pin, HIGH);
digitalWrite(sel1Pin, LOW);
delay(10);
MyByte =
digitalRead(daPin0)|
(digitalRead(daPin1)<< 1) |
(digitalRead(daPin2)<< 2) |
(digitalRead(daPin3)<< 3) |
(digitalRead(daPin4)<< 4) |
(digitalRead(daPin5)<< 5) |
(digitalRead(daPin6)<< 6) |
(digitalRead(daPin7)<< 7);
Serial.print(MyByte,BIN);
//set OE pin high to fish tr-state reading
digitalWrite(oePin, HIGH);
}