Sunday, October 30, 2016

DJ Hard Drive Turn Table Part 2

Welcome back to this episode of "Why isn't this working?" This week, we have the DJ Hard Drive Turn Table. When we left off, we weren't getting accurate directional readings from the drive. Needless to say, that kinda sucked. So I took it to an oscilloscope to figure out what was going on with the output of the op amps. It turns out it was a really weird problem.




This is what was coming out of the op amp. The square waves were directly in phase with each other, which is absolutely useless in determining direction. So why was it doing this? I believe it was because I was comparing things incorrectly in the op amp. I don't have a good solid reason for this, maybe it was just the bread board I was using. Pro tip: if you're having an issue with a circuit, move it to another breadboard so you're forced to have to think it through again.

I also was informed by one of my electrical engineering friends that the resistor pattern I was using was not enough to amplify the wave to a full 5 volts. Because the amplitude of the wave was smaller than I thought, I needed to amplify the signal by 100x, not just 10x. So I replaced the 10k resistors with 100k resistors. Then, and I believe this is super duper important, I went ahead and used Vcc and ground from the Arduino. Now there's a base line for the Arduino to compare the output signals to. That could have been a issue as well.

And now, wouldn't you know it, the circuit works!


So now the circuit works, the code needs some touching up. I simplified it quite a bit and now it works almost flawlessly. The resolution of this hard drive isn't as fantastic as I hoped it would be (hard drives with four phases may be better for accuracy), but I was now able to determine the speed and the direction of the platter. Direction is kind of wonky at very low speeds, but it's hard to deal with that when you only have two square waves. Here's the code.

int pina = 2; 
int pinb = 3;
short pinastate = 0;
short pinbstate = 0;

void setup() {
  Serial.begin(250000);
  pinMode(pina, INPUT); //Set Mode
  pinMode(pinb, INPUT);
  attachInterrupt(digitalPinToInterrupt(pina), upa, CHANGE); //Create interrupts
  attachInterrupt(digitalPinToInterrupt(pinb), upb, CHANGE);
}

void loop() {}

void upa() {
  pinastate = !pinastate;
  if(pinastate==pinbstate && pinastate != 0) Serial.print("1");
}

void upb() {
  pinbstate = !pinbstate;
  if(pinastate==pinbstate && pinbstate != 0) Serial.print("2");
}

And now when you spin it, you should get ones or twos depending on the direction of the spin! I don't know if I'm going to actually attach this to some music software, as I'd like to make it spin by itself first and make it look prettier. But we'll see how it goes. I've been pretty busy with school work, but I like to work on stupid little projects like this when I can. Hopefully I can take this to the next step next month.

No comments:

Post a Comment