I'm testing out some Lilypad Vibe Boards (http://www.sparkfun.com/products/11008), and wanted to know how I could figure out what frequency the motors were vibrating at, and possibly even the amplitude (in G's) of the motor.
I also have a Lilypad accelerometer that I figured I could use to measure the amplitude, but I am not exactly sure how to go about doing this.
This is my Arudino code right now:
/* Code for Running a single vibratory motor and accelerometer */
// these constants describe the pins. They won't change:
const int xpin = A1; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A3; // z-axis (only on 3-axis models)
int vibe = 5; //motor connected to PWM 5
int sampleDelay = 2.22; //number of milliseconds between readings
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
pinMode(vibe, OUTPUT); //sets the digital pin as output
//Make sure the analog-to-digital converter takes its reference voltage from
// the AREF pin
analogReference(EXTERNAL);
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
}
void loop()
{
analogWrite(vibe,127); //set value of motor PWM from 0-255
int x = analogRead(xpin);
//add a small delay between pin readings. I read that you should
//do this but haven't tested the importance
delay(1);
int y = analogRead(ypin);
//add a small delay between pin readings. I read that you should
//do this but haven't tested the importance
delay(1);
int z = analogRead(zpin);
//zero_G is the reading we expect from the sensor when it detects
//no acceleration. Subtract this value from the sensor reading to
//get a shifted sensor reading.
float zero_GX = 500.0;
float zero_GY = 515.0;
float zero_GZ = 520.0;
//scale is the number of units we expect the sensor reading to
//change when the acceleration along an axis changes by 1G.
//Divide the shifted sensor reading by scale to get acceleration in Gs.
float scale = 102.3;
Serial.print("x val: ");
Serial.print(((float)x - zero_GX)/scale);
Serial.print("\t");
Serial.print("y val: ");
Serial.print(((float)y - zero_GY)/scale);
Serial.print("\t");
Serial.print("z val: ");
Serial.print((((float)z - zero_GZ)/scale));
Serial.print("\n");
// delay before next reading:
delay(sampleDelay);
}
Magician:
Frequencies analysis could be done via FFT. Be aware of complexity of programming.
How you gonna use a data?
I just want to verify the vibration frequency of the motor so I have an idea of what the motor's output is since the motor has a range of roughly 100 to about 225 Hz according to the data sheet.
Hope, you are using transistor to control this motor? I wouldn't connect it directly to arduino, 85/75 mA is too much.
To calculate vibration, first part would be setting the sampling rate, about 450 Hz, twice max freq. of the motor 225.
Magician:
Hope, you are using transistor to control this motor? I wouldn't connect it directly to arduino, 85/75 mA is too much.
To calculate vibration, first part would be setting the sampling rate, about 450 Hz, twice max freq. of the motor 225.
yes im currently sampling the accelerometer at 2.22 ms per reading or 450Hz i believe; I also modulated my code to up the PWM frequency to about 950Hz to be safe.
interestingly it's running without a transistor, but I have ordered some transistors and schottky diodes that are coming in, but for now its running straight from the PWM pins on the Arduino mega...
i had a question about the lilypad vibe motor:
At maximum 255 analog value, I receive a voltage reading across the motor of 3.6Volts. Since I'm using a 5V pin, does this imply the diode within the lilypad vibe board is giving a 1.4V drop? Where did my lost voltage go? I don't have any resistors or diodes connected between the pin and lilypad vibe board as the schemetic shows them installed. Wanted to know the voltage drop across the diode. Similary at 50% duty cycle (127) I am receiving 1.8Volts.
There is a mistake, when you are using sampleDelay 2.22 at the end of your loop, it doesn't mean you reading analog port with this delay, as everything what included in the code also create delay, every commands take time to execute, so you will (almost) never know how frequently you are reading the values from accelerometer. One more things, integer sampleDelay can't be 2.22, it rounded to 2.
The easy way to do sampling, its via "for" loop and array. Make your research how to fill up array with periodically sampled values.
At maximum 255 analog value, I receive a voltage reading across the motor of 3.6Volts. Since I'm using a 5V pin, does this imply the diode within the lilypad vibe board is giving a 1.4V drop? Where did my lost voltage go?
Voltage lost in AtMega chip, as it supply high current.
I don't have any resistors or diodes connected between the pin and lilypad vibe board as the schemetic shows them installed. Wanted to know the voltage drop across the diode. Similary at 50% duty cycle (127) I am receiving 1.8Volts.
What I can see on SFE web-site picture, there are diode and resistor installed on board. Diode in parallel to motor. Resistor in series. You can measure the drop voltage on a resistor, and a motor (as diode in parallel it has the same voltage).
Magician:
There is a mistake, when you are using sampleDelay 2.22 at the end of your loop, it doesn't mean you reading analog port with this delay, as everything what included in the code also create delay, every commands take time to execute, so you will (almost) never know how frequently you are reading the values from accelerometer. One more things, integer sampleDelay can't be 2.22, it rounded to 2.
The easy way to do sampling, its via "for" loop and array. Make your research how to fill up array with periodically sampled values.
At maximum 255 analog value, I receive a voltage reading across the motor of 3.6Volts. Since I'm using a 5V pin, does this imply the diode within the lilypad vibe board is giving a 1.4V drop? Where did my lost voltage go?
Voltage lost in AtMega chip, as it supply high current.
I don't have any resistors or diodes connected between the pin and lilypad vibe board as the schemetic shows them installed. Wanted to know the voltage drop across the diode. Similary at 50% duty cycle (127) I am receiving 1.8Volts.
What I can see on SFE web-site picture, there are diode and resistor installed on board. Diode in parallel to motor. Resistor in series. You can measure the drop voltage on a resistor, and a motor (as diode in parallel it has the same voltage).
ok so if i remove the sample delay I have in my code and just have the serial monitor open @9600 baud, those values that are streaming in sure seem higher than 500Hz. what is it with no delay?
Not interesting at all. It just means you are damaging your arduino. Do it for long enough and it will stop working. You have already screwed its long term reliability.
Not interesting at all. It just means you are damaging your arduino. Do it for long enough and it will stop working. You have already screwed its long term reliability.
that doesn't make sense...the motor's startup current is rated for roughly 80mA, and an operating current of 60mA, if the pins are providing 40mA, how am I damaging the arduino? if anything it should not even start the motor...
i found this quote from someone about the lilypad vibe board:
"The diode works like a surge-protector. It is super-important if you are going to drive the motor using a microprocessor, motor controller, or transistor. Without the diode you could easily destroy these. (It’s no fun toasting your Arduino). You don’t need the diode when driving the motor directly with a battery, or through a switch.
Most microprocessors have relatively weak outputs (20-25mA). The 33 ohm resistor in series is there so the motor doesn’t draw too much current from the microprocessor."
i just checked and there is a 33.2Ohm resistor on the motor as well as a diode with 0.3V...
those values that are streaming in sure seem higher than 500Hz.
???
With all this printing stuff in main loop, I'd expect the period of accelerometer reading much lower, may be 10 Hz, or even less.
well looks like I have a problem, read up on bandwidth and accelerometers,
turns out the ADXL335 Lilypad accelerometer that I have has 0.1 microfarad capacitors attached giving it a bandwidth of only 50Hz!! so I guess that is useless for my application since I need to be much higher in the 300-500Hz range.
that doesn't make sense...the motor's startup current is rated for roughly 80mA, and an operating current of 60mA, if the pins are providing 40mA, how am I damaging the arduino? if anything it should not even start the motor...
You are totally misunderstanding this.
Your arduino pin is not providing 40mA, it is providing what the motor's impedance is demanding, or at least trying to. The current at 40mA is called a limit not because you can't get any more from it, but because if you do equal it or exceed it then damage will occur.
The mechanism of damage is localised overheating of the chip, or sometimes electromigration in the interconnect layers. Mild overstress will cause gradual degradation, diffusion of dopant atoms will reduce the performance of nearby transistors until something really stops working. Its insidious and irreversable damage, so best avoided unless you enjoy replacing parts that fail seemingly at random...
that doesn't make sense...the motor's startup current is rated for roughly 80mA, and an operating current of 60mA, if the pins are providing 40mA, how am I damaging the arduino? if anything it should not even start the motor...
You are totally misunderstanding this.
Your arduino pin is not providing 40mA, it is providing what the motor's impedance is demanding, or at least trying to. The current at 40mA is called a limit not because you can't get any more from it, but because if you do equal it or exceed it then damage will occur.
so how am I damaging the arudino again?
you said:-
at 100% duty cycle so 3.6 Volts its drawing 42mA
Get it yet!!!
ah this makes sense, thank you for the clarifications!
im awaiting my transistors and schottkey diodes...
but back on my main question, any help on how I can go about getting an accurate measurement of the motor's frequency or amplitude?
any help on how I can go about getting an accurate measurement of the motor's frequency or amplitude?
I am not sure what you mean by the amplitude of a motor.
The PWM frequency has nothing to do with the motor's frequency or speed. The PWM mark space ratio will change the motor's speed. You need to sample your sensors at least twice per cycle to see any frequency but that is the minimum, the faster you sample the greater you can determine the frequency. You take a bunch of samples and then you can apply a FFT to the values.
A simpler method would be to arrange some sort of optical detector like a white spot on the shaft and then time the signals.
any help on how I can go about getting an accurate measurement of the motor's frequency or amplitude?
I am not sure what you mean by the amplitude of a motor.
The PWM frequency has nothing to do with the motor's frequency or speed. The PWM mark space ratio will change the motor's speed. You need to sample your sensors at least twice per cycle to see any frequency but that is the minimum, the faster you sample the greater you can determine the frequency. You take a bunch of samples and then you can apply a FFT to the values.
A simpler method would be to arrange some sort of optical detector like a white spot on the shaft and then time the signals.
yes i thought about optical, but these motors are tiny <10 mm in a pancake style shell.
i was thinking of using an accelerometer to measure the vibrational amplitudes (in G's), but I'm assuming my accelerometer won't cut it with just a 50Hz bandwidth.