I am trying to control the position of the HDD read/write head with PWM. I am using this code
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the HDD head is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 1000);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("output = ");
Serial.println(outputValue);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
I am getting strange results - when I turn the potentimeter, the head is going only in forward direction and when it hits the end it sticks there, even when I turn the potentiometer back. I have read in other topics that this is happening, because the PWM ports support only positive voltage and I need negativ to move the HDD head backwards. Strangely the guy in the video has done it, but hasn`t included the code to show how it is workin. Do you have any idea how the code should look like to get this?
Is the motor driver you are using the one that comes with the drive ?
It should be a servo motor which accepts some kind of signal (analog or digital) that tells it to go to a specific position and stay there until it receives a new command. I don't know how a PWM signal has any relevance to your application, since PWM is used for speed control and an HDD head motor is a position controlled device, not a speed controlled device. APPLES and ORANGES.
That is my guess without even seeing the schematic. Do you have the schematic ?
Yes, I do think that there is a driver in the pcb of the HDD, but I am not using it. The so called motor turned out to be a voice coil, which is a thing that I have never dealed with before. I am using a direct connection to the head (there are 2 wires on the top). Previously I have used the HDD connected to a low-frequency amp giving more power to a signal coming from the audio jack of the PC. There was a mirror mounted on the top, to which was pointed a laser (similar to the video). The head was moved by the music back and forwards very fast and this created a moving reflection of the laser (the laser oscilloscope).
So I thought that I can recreate the effect of the music signal with a PWM signal and I can move the head more precisely and with a planned direction in order to recreate the effect of a laser scanner, because the music signal is ranging and the effect is volatile.
I have no schematics and I also have no idea what to search for.
I found two things:
The HDD head vibrates when given a signal with different frequency.
When the polarity of the voltage is changed, the head moves in different direction.
How can I recreate the ranging voltage with the arduino, is it possible ?
I still can`t understand, how the guy in the video has done it :D. Any other ideas ?
raschemmel:
Is the motor driver you are using the one that comes with the drive ?
It should be a servo motor which accepts some kind of signal (analog or digital) that tells it to go to a specific position and stay there until it receives a new command. I don't know how a PWM signal has any relevance to your application, since PWM is used for speed control and an HDD head motor is a position controlled device, not a speed controlled device. APPLES and ORANGES.
That is my guess without even seeing the schematic. Do you have the schematic ?
once you remove the platters from an HDD there is no position sensor (since the magnetic
tracks are used to sense head position on the fly).
So unless you add an encoder you can't do positioning. But you can do torque control
and use the end-stops to constrain position somewhat. Add position sensing and a PID-loop
will give position control (servo loop).
You need an H-bridge to drive the voice-coil, which is inherently bidirectional.
TomGeorge:
Hi, the PWM values are from 0 to 255, not 1000.
Tom....
Yes, I understood that, because after 255 there is no change. I also tried to usw -1000 :D, but guess what... Nothing happened. I am still newbie and I am still experementing alot. I also still need help for the code to drive the voice coil.
I have found some information and I think I am in the right track. What I need to achieve the specific effect is a AC sine wave. Any ideas how to achiev that, but to have ranging positive and negative voltage?