Pages: [1]   Go Down
Author Topic: Control multiple FDD drives via PD  (Read 478 times)
0 Members and 1 Guest are viewing this topic.
Poland
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can fully control single FDD. When send "20" by object "comport" from the PD then run a line of code:
Code:
if (incomingByte == 20) vibe (40, 4291);
and so on

My problem is that I connected two FDD and I would like to have played two different sounds simultaneously that is run two commands at once. Unfortunately, it works like this:

  • 20 launches drive A
  • 30 launches both drives, despite the fact that should work only drive B
  • 20 and 30 simultaneously - launches first drive A and B after a long delay


I Make a mistake somewhere, but I do not understand where.

Arduino code:

Code:
/*
SETTINGS
 */

#define StepA 2
#define DirA 3
#define SelA 4
#define StepB 5
#define DirB 6
#define SelB 7

int incomingByte = 0;

/*
START
 */
 
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  pinMode(DirA, OUTPUT);
  pinMode(StepA, OUTPUT);
  pinMode(SelA, OUTPUT);
  digitalWrite(SelA, HIGH);
  pinMode(DirB, OUTPUT);
  pinMode(StepB, OUTPUT);
  pinMode(SelB, OUTPUT);
  digitalWrite(SelB, HIGH);
  initHead();  // move header half way
}

void initHead() {
  digitalWrite(StepA, HIGH);
  digitalWrite(DirA, HIGH);
  doSteps(80, 1911);  // move header to start position wherever it is, 80 steps at ~261 step/s
  digitalWrite(DirA, LOW);
  doSteps(40, 1911);

  digitalWrite(StepB, HIGH);
  digitalWrite(DirB, HIGH);
  doSteps(80, 1911);  // move header to start position wherever it is, 80 steps at ~261 step/s
  digitalWrite(DirB, LOW);
  doSteps(40, 1911);
}

void doSteps(int steps, int stepDelay) {
  digitalWrite(SelA, LOW);
  for(int i=0;i<steps; i++) {
    digitalWrite(StepA,LOW);
    delayMicroseconds(stepDelay);
    digitalWrite(StepA,HIGH);
    delayMicroseconds(stepDelay);
    digitalWrite(StepB,LOW);
    delayMicroseconds(stepDelay);
    digitalWrite(StepB,HIGH);
    delayMicroseconds(stepDelay);

  }
  digitalWrite(SelA, HIGH);
}

/*
VIBE VIBE VIBE
 */
 
void vibeA(int count, int period) {
  for(int l=0;l<count; l++) {
    digitalWrite(DirA, HIGH);
    doSteps(1, period);
    digitalWrite(DirA, LOW);
    doSteps(1, period);
  }
}

void vibeB(int count, int period) {
  for(int l=0;l<count; l++) {
    digitalWrite(DirB, HIGH);
    doSteps(1, period);
    digitalWrite(DirB, LOW);
    doSteps(1, period);
  }
}

/*
FIRST FDD
 */

void loop() {
  if (Serial.available()>0) {
    incomingByte=Serial.read();
  
  if (incomingByte == 20) vibeA(40, 4291);  //C
  if (incomingByte == 21) vibeA(40, 4050);
  if (incomingByte == 22) vibeA(40, 3823);
  if (incomingByte == 23) vibeA(40, 3609);

   /*
SECOND FDD
 */
    
  if (incomingByte == 30) vibeB(40, 4291); //C
  if (incomingByte == 31) vibeB(40, 4050);
  if (incomingByte == 32) vibeB(40, 3823);
  if (incomingByte == 33) vibeB(40, 3609);
  
  }
}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50245
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your doSteps() function is a blocking function that takes time to complete. You will never get both drives to move at the same time with the blocking delay() calls.

How is PD (whatever that is) sending the data. The code you posted is not expecting "20" or "30" or any other string.

Quote
Unfortunately, it works like this:

    20 launches drive A
    30 launches both drives, despite the fact that should work only drive B
    20 and 30 simultaneously - launches first drive A and B after a long delay
The middle issue looks like it might be a PD issue, since there is nothing in the code that I see that would explain it.
« Last Edit: May 22, 2012, 12:56:16 pm by PaulS » Logged

Pages: [1]   Go Up
Jump to: