Controlando a unidade de disquete com o Arduino


14

Estou tendo problemas para controlar uma unidade de disquete de 3,5 "com um Arduino Uno.

Eu tenho a unidade de disquete alimentada por uma fonte de alimentação de computador ligada e o Arduino alimentado por USB do meu computador. Cortei a fita de um conector IDC de 34 pinos para poder rotear os pinos para o meu Arduino. Consigo ligar o motor do disquete e mover a cabeça de leitura / gravação para frente e para trás, mas nunca consigo ler pulsos dos pinos Track-0 ou Index.

Tenho os pinos 7, 15, 17, 19 e 25 do disquete, todos aterrados no meu Arduino, e tenho os pinos 8, 16, 18, 20 e 26 do disquete conectado ao meu arduino como pinos de saída, para que eu possa controlar a unidade.

Estou esperando que o Índice pulsar quando o motor do disco fizer uma rotação e que a Faixa 0 mude quando estou na parte externa do disco, mas ambos são sempre BAIXOS. Estou esquecendo de algo?

Aqui está a especificação que encontrei para a parte traseira da unidade de disquete

    2   /REDWC  Input Density Select
    4   n/c N/A Reserved
    6   n/c N/A Reserved
    8   /INDEX  Output Index
    10  /MOTEA  Input Motor Enable A 
    12  /DRVSB  Input Drive Sel B
    14  /DRVSA  Input Drive Sel A 
    16  /MOTEB  Input Motor Enable B
    18  /DIR    Input Direction
    20  /STEP   Input Step 
    22  /WDATE  Input Write Data
    24  /WGATE  Input Floppy Write Enable
    26  /TRK00  Output Track 0
    28  /WPT    Output Write Protect
    30  /RDATA  Output Read Data
    32  /SIDE1  Input  Head Select
    34  /DSKCHG Output Disk Change/Ready

Aqui está um esquema do que eu conectei (A placa de ensaio neste diagrama de circuito representa o conector IDC que está conectado à unidade de disquete de 3,5 ").

Conexões de disquete e Arduino

Aqui está uma foto do conector IDC e identifiquei quais fios estão conectados ao Arduino.

Conector IDC rotulado

Aqui está o código que estou executando.

//constants
static const int IN = LOW;
static const int OUT = HIGH;
static const int pulseDelayTime = 6;

//pins
int indexPin = 2; //8 on the drive INDEX
int track0Pin = 3; //26 on the drive. TRACK 0
int dirPin = 6; //18 on the drive. DIRECTION
int stepPin = 7; //20 on the drive. STEP
int motorEnableBPin = 9; //16 on the drive. MOTOR ENABLE B

unsigned long motorSpinTime = 1000UL; //in ms


void setup() {

  //initial delay
  delay(3000);

  //setup serial monitor
  Serial.begin(9600);      

  //setup pins.
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(motorEnableBPin, OUTPUT);
  pinMode(indexPin, INPUT);
  pinMode(track0Pin, INPUT);

  //turn the motor off initially
  digitalWrite(motorEnableBPin, HIGH);

  //print state here.
  printState("Setup done.");

  //spin the disk some.
  printState("Begin to spin motor");
  spinMotorForThisManyMs(motorSpinTime);
  spinMotorForThisManyMs(motorSpinTime);
  printState("Done spinning motor");

  //step read/write head all the way in.
  stepAllTheWayIn();

  //spin the disk some more.
  printState("Begin to spin motor");
  spinMotorForThisManyMs(motorSpinTime);
  spinMotorForThisManyMs(motorSpinTime);
  printState("Done spinning motor");

  //step read/write head all the way out.
  stepAllTheWayOut();

  //spin the disk even more.
  printState("Begin to spin motor");
  spinMotorForThisManyMs(motorSpinTime);
  spinMotorForThisManyMs(motorSpinTime);
  printState("Done spinning motor");

  //never completes.
  waitForIndex();
}

void loop() {
}

//spins the disk motor for a number of ms and prints the state
void spinMotorForThisManyMs(unsigned long msToSpin) {

  //start spinning
  digitalWrite(motorEnableBPin,LOW);

  //delay.. keep printing the state
  unsigned long maxTimeMs = millis() + msToSpin;  
  while(millis() < maxTimeMs ) {
    printState("Spinning");    
  }

  //stop spinning
  digitalWrite(motorEnableBPin,HIGH);
}



//step the read/write head all the way to the center
void stepAllTheWayIn() {
  for(int i=0;i<100;i++) {
    printState("Stepping In");
    stepInALittle();
  }
}

//step the read/write head all the way to the outside
void stepAllTheWayOut() {
  for(int i=0;i<100;i++) {
    printState("Stepping Out");
    stepOutALittle();
  }
}

//print the state of the index and track
void printState(const char* charPrint) {
  Serial.print(" Index:");
  Serial.print(digitalRead(indexPin));
  Serial.print(" Track:");
  Serial.print(digitalRead(track0Pin));
  Serial.print(" ");
  Serial.println(charPrint);
}

//move the head towards the outside a little
void stepOutALittle() {
  digitalWrite(dirPin,HIGH);
  stepPulse();
}

//move the head towards the center a little
void stepInALittle() {
  digitalWrite(dirPin,LOW);
  stepPulse();
}

//pulse the step pin
void stepPulse() {
  digitalWrite(stepPin,LOW);
  delay(pulseDelayTime);
  digitalWrite(stepPin,HIGH);
}

//waits for the index to trigger. this never gets completed.
void waitForIndex() {

  printState("beginning to wait for index pin to pulse");

  //start spinning
  digitalWrite(motorEnableBPin,LOW);

  //wait for pulse
  while(digitalRead(indexPin));
  //wait for end of pulse 0
  while(!digitalRead(indexPin));

  printState("end of waiting for index pin to pulse");

  //stop spinning
  digitalWrite(motorEnableBPin,HIGH);
}

Aqui está a saída que estou recebendo.

 Index:0 Track:0 Setup done.
 Index:0 Track:0 Begin to spin motor
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Done spinning motor
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Stepping In
 Index:0 Track:0 Begin to spin motor
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Done spinning motor
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Stepping Out
 Index:0 Track:0 Begin to spin motor
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Spinning
 Index:0 Track:0 Done spinning motor
 Index:0 Track:0 beginning to wait for index pin to pulse

ATUALIZAÇÃO: Agora estou recebendo meus resultados esperados devido à resposta da geometrikal. Enquanto pesquisava esse problema, encontrei alguns exemplos de código do Arduino para o disquete. Notei que eles estavam definindo seus pinos de entrada como HIGH, mas nunca percebi por que eles estavam fazendo isso. Depois de corrigir meu problema, encontrei isso em alguma documentação do Arduino (o que me fez perceber os exemplos de código que eu estava usando uma versão mais antiga do IDE do Arduino):

"Antes do Arduino 1.0.1, era possível configurar os pull-ups internos da seguinte maneira:"

pinMode(pin, INPUT);           // set pin to input
digitalWrite(pin, HIGH);       // turn on pullup resistors`

No Arduino 1.0.1+, você pode fazer desta maneira.

pinMode(pin, INPUT_PULLUP);

Ambos os métodos para ativar o trabalho de pull-up. O segundo método, usando o pinMode INPUT_PULLUP, é melhor porque usa 1 linha a menos e porque é muito mais fácil de ler.
Duncan C

Respostas:


10

De acordo com este (link morto):

http://bitsavers.trailing-edge.com/pdf/nec/FD1035_Product_Description_Jul84.pdf

Esta é uma cópia arquivada da unidade de disquete FD1035 de 3,5 ": Descrição do produto Julho de 1984 - PDF :

https://archive.org/details/bitsavers_necFD1035Pl84_876629

As saídas são de coletor aberto, portanto é necessário um resistor de pull-up. Em vez disso, você pode ativar os pull-ups internos do Arduino nesses pinos

pinMode(indexPin, INPUT_PULLUP);
pinMode(track0Pin, INPUT_PULLUP);

Não posso agradecer o suficiente. Isso é exatamente o que eu precisava.
jeffctown

3

Você deve substituir intpor unsigned longem todos os locais em que lida com o tempo em milissegundos.

O ponto é que millis()retorna um unsigned long, usando, assim, inta loja de millis()valor, você tem uma perda de informação devido ao elenco automática realizada pelo compilador.

As alterações que você precisa executar são:

unsigned long motorSpinTime = 1000UL; //in ms

e:

//spins the disk motor for a number of ms and prints the state
void spinMotorForThisManyMs(unsigned long msToSpin) {

  //start spinning
  digitalWrite(motorEnableBPin,LOW);

  //delay.. keep printing the state
  unsigned long maxTimeMs = millis() + msToSpin;  
  while(millis() < maxTimeMs ) {
    printState("Spinning");    
  }

  //stop spinning
  digitalWrite(motorEnableBPin,HIGH);
}

Observe que também realizei alguma otimização no loop de espera calculando o tempo máximo uma vez e depois comparando millis()diretamente com esse valor. Isso não é obrigatório, mas acho que é um pouco mais limpo.


Great catch! Infelizmente, alterar esse código não corrige a saída inesperada que estou recebendo. Ainda estou recebendo todos os 0s para o índice e rastrear 0 pinos. Eu ainda estou perplexo. Eu diria que talvez a unidade seja ruim, mas eu comprei 2 unidades de disquete de 3,5 "para este projeto e recebo a mesma saída com as duas (acho que elas podem ser ruins, mas quais são as chances disso?).
jeffctown

Isso é potencialmente importante, mas de forma alguma responde à pergunta, assim como o tipo de argumento que deve ser apresentado como um comentário.
Chris Stratton
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.