# Easist way to create smooth PWM waveforms for haptic feedback?

I want to create a library of waveforms for haptic feedback events using a vibration motor.

For example if I want a sine wave type signal growing from 0 to 255 and back to 0 over a 3 second period (and looping) what is the most efficient way to programme that?

Thank You

PWM and smooth seem like polar opposites to me. And PWM is a square wave, not a sine wave.

When you say

sine wave type signal growing from 0 to 255 and back

are you referring to the amplitude or the frequency?

…R

Thanks for the response.

As I understand PWM applied to a DC motor short bursts will make it run smoothly but slowly, longer bursts will make it run smoothly and quickly.

I want the frequency (or rpm of the motor) to speed up from stall state to maximum speed and then down to stall state again. The amplitude would cycle over say 3 seconds.

Thanks

How are you detecting the stall state?

AWOL: How are you detecting the stall state?

As vibration motors have a constant load of their offset weight, manufacturers give a rated minimum volt and or amp rating. Of course in practice this may differ due to several factors but I'll cross that bridge when I get to it.

At the moment I can only see a command to drive a motor at a constant rate for a certain time: analogWrite(). Are there other commands to say ramp up the speed and do so in a non-linear way?

Thanks

Are there other commands to say ramp up the speed and do so in a non-linear way?

I don't believe so, but writing one isn't difficult. Start with "blink without delay" and work up from there.

cpcp: As I understand PWM applied to a DC motor short bursts will make is run smoothly but slowly longer burts will make it run smoothly and quickly.

Yes, but your original post did not mention a DC motor so you will forgive my confusion?

With an Arduino the function analogWrite() generates a PWM signal on the selected out put pin. For example analogWrite(3, 10); should make the motor run slowly and analogWrite(3,255); will make it run at full speed. This assumes the motor is controlled by the output of pin 3. You can use your Arduino program to make the PWM duty cycle vary between 0 ad 100% according to any pattern and timing that you choose. (100% is represended by a value of 255).

You need to have a suitable motor driver circuit to interface between the Arduino and the motor as the Arduino cannot provide enough current to drive a motor. The Arduino just produces a control signal.

...R

Ah, thank you, millis() could be just the clue.

Yes, but your original post did not mention a DC motor so you will forgive my confusion?

Sorry.

You need to have a suitable motor driver circuit to interface between the Arduino and the motor as the Arduino cannot provide enough current to drive a motor. The Arduino just produces a control signal.

Thank you -I'll probably use a MOSFET

I’m developing an Ardunio-programmable board for driving a vibration motor. Here you will find some background information www.bodyinteraction.com

The programming basics are simple. As Robin2 said use e.g. analogWrite(3,255); for maximal power. Don’t forget to use the delay function after changing the output as the change takes some time to take place.

``````  for (int i=10;i<256;i++) { // increasing vibration
analogWrite(3,i); //output pin 3
delay(50);
}
``````

When I developed the board the commercial application notes from Precision Microdrives helped me a lot. They have notes about motor driver circuits as well as about using PWM and more.

binteraction:
Don’t forget to use the delay function after changing the output as the change takes some time to take place.

Surely you mean “don’t forget to not use the delay() function” ?

AWOL:

binteraction: Don't forget to use the delay function after changing the output as the change takes some time to take place.

Surely you mean "don't forget to not use the delay() function" ?

+1

Use the Blink Without Delay technique.

...R

Robin2:

AWOL:

binteraction: Don't forget to use the delay function after changing the output as the change takes some time to take place.

Surely you mean "don't forget to not use the delay() function" ?

+1

Use the Blink Without Delay technique.

...R

Sorry for the confusion... but I missed "(ramp up the speed and do so) in a non-linear way" Of course the "blink without delay" sketch is a good starting point. Another delay() function avoiding technique is described here: http://jeelabs.org/2012/03/16/millitimer-example/