# Sound generator for an EV, with RPM-controlled pitch variation



## Ziggythewiz (May 16, 2010)

I'd love to hear the details. Someday I'll have a transparent rear end to show off the motor wrapped in EL Wire that pulsates to the sound of a warp drive (Star Trek, not Netgain) approaching maximum warp. Won't happen anytime soon, but it'll be fun


----------



## Duncan (Dec 8, 2008)

Yes I would love to hear more - I want one!


----------



## Zak650 (Sep 20, 2008)

What a great deal! I'd like to have the sound of the original bug eminating from my electric version.


----------



## Woodsmith (Jun 5, 2008)

I've been looking at the sound generators used in RC models.

I quite like the sound of the 4cyl petrol one they have as it sounds most like a rough old implement diesel engine, but without the black smoke!


----------



## vmrod (Jul 2, 2010)

Awesome!

I want to have this in my trike once it is completed. I've always wanted a turbine sound and this just fits the bill!

I would not mind installing external speakers and amps just for this purpose. I even thought of using a smoke machine and blower fan along with a light. Imagine close to dark...you rev up your engine, and there is a slight glowing/growing pulse under the car, with a teeny bit of smoke, just enough to give the light something to fall onto, or something to see during the daytime.


----------



## gdirwin (Apr 7, 2009)

Do you think Ferrari sounds are possible? How about a switch between different engine sounds?

Fun stuff!


----------



## swoozle (Nov 13, 2011)

Neither hardware nor software are my field, so I'm sure experts in both can find things to fix. I welcome that, in fact there is at least one hardware quirk that would be nice to make more robust so please comment.

OK, I'll start with hardware.

The base platform is the Digilent chipKIT Uno32, an arduino look-alike board.
http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,893&Prod=CHIPKIT-UNO32







It runs on a PIC32 chip at 80mhz (Arduino is at 16mhz) and has 128k of flash (Ardunio Uno has 32kb). 
An arduino doesn't have the horsepower or memory to do this project, though it might be possible using something like the Adafruit Wave Shield. But, the Uno32 doesn't cost any more than an arduino, I wanted to play with an Uno32 and found this Polyphonic Sampling Synth project:
http://hackaday.com/2011/06/08/chipkit-sketch-mini-polyphonic-sampling-synth/
as a base to start from, so Uno32 it was.

If you want more room for samples, the Max32 with 512kb is an option. 
http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,894&Prod=CHIPKIT-MAX32
It's an Arduino Mega-like board. The synth project mentions that an Uno32 could hold about a minute of sample sound, so a Max32 could probably hold ~5 minutes in total.


----------



## swoozle (Nov 13, 2011)

The audio hardware is a simple low-pass filter straight from the Synth project. It serves to filter out the higher frequency sample DAC artifacts. The source signal comes from Pin 3 on the Uno32. 








The tach signal hardware is a simple voltage splitter to convert the 12V tach signal to 3V that the Uno32 can handle. This is fed into pin 8.
Oh, at some point early on I added a small ceramic cap across the lower resistor and it seemed to help clean up some spurious tach pulse detections. I'm not sure it actually still does anything but I haven't yet tried removing it. Maybe one of you hardware experts can suggest something here to make tach pulse detection more robust.








Both as a rough discrete solder experiment and after I put it on the protoboard shield, I had problems with spurious tach input events caused by some interference from the sound output through ground. Maybe one of you hardware experts can explain that. In both cases I got rid of the problem by separating the two circuits and taking the ground for each from two separate points on the Uno32.

Here's an overall shot.







Line out jack at top left-ish, proto shield on Uno32 at lower left-ish, display at center rightish, tach signal input at left. The wires to the right go to a Bluetooth serial board that I'm playing with to transmit the tach reading to Android devices for display, which is a separate project. I used the MIT AppInventor to create the Android receive/display app, and it works quite nicely. Neither the display nor the bluetooth module are necessary and I'll post a code version that doesn't have those in it. The display has been handy for debugging to show whether proper tach signal measurement is occurring. It's a 4D systems serial OLED from sparkfun. They no longer sell that particular one, but this is just a little smaller:
https://www.sparkfun.com/products/11377

Sound generator details:


----------



## iti_uk (Oct 24, 2011)

Just had a quick daydream about this idea - for those who are doing ICE-to-EV conversions, how about gutting a backbox, blocking the "in" pipe, and installing one or maybe two 6x9s (for the shape) into the top of the box - then you'd get an exhaust note coming out of an exhaust pipe (although you'd have no intake noise, which could be solved with a speaker under the hood...).

I wonder how it would sound...?



Chris


----------



## Zak650 (Sep 20, 2008)

The next step would be for everyone to record audio clips of desired engines and post the short clips in an attachment in this thread. Instructions in the sketch "place audio sample here" & "sample frequency/rpm"


----------



## gdirwin (Apr 7, 2009)

swoozle said:


> ... go to a Bluetooth serial board that I'm playing with to transmit the tach reading to Android devices for display


To get the tach signal, you could also use an inexpensive ($15) OBD to bluetooth adapter - this can be read by Torque apps on Android. It is a bit laggy however, so your Arduino approach for a faster/lower lag rpm signal would be better than the OBD approach.


----------



## swoozle (Nov 13, 2011)

Here's a bit better of a clip. The amp is hooked up to a subwoofer box, so it's more a show of what could be done than what I'm doing. This also has a few seconds of the android proof of concept tach app.


----------



## swoozle (Nov 13, 2011)

Sound data generation

The arduino sketch contains the sound information in the form of a large array. The production of that array data is kind of a pain in the ass. I looked around for a different way of doing it and found a program that puts out the data in a slightly different array form, but that's where my coding skills hit the wall and I wasn't able to modify the sketch to play that array successfully. So the original method from the synth project is it:
http://hackaday.com/2011/06/08/chipkit-sketch-mini-polyphonic-sampling-synth/

1. In brief, start with a sound clip you like and massage it an audio editing program of your choice until it sounds the way you want when continuously looped.
Here's the clip I started with:
View attachment med freq whoosh.zip


2. This needs to be converted to an uncompressed 8 bit mono wav file. General consensus seems to be that the conversion is most easily done by iTunes. 
a) add your clip to your itunes library. 
b) change your itunes export format to 8 bit mono wave uncompressed 
c) export your clip.
The sketch is written around a 16khz sampling frequency, but other frequencies can be used with a very simple change to the sketch. 

3. That 8bit wav file must be converted to text with a unix program included with the synth project files. In the comments to that project there is a method outlined of doing this on a windows computer using Cygwin. The comment says something about it taking 6 hours to install Cygwin, which I scoffed at. No, it really does take that long. Holy crap.
If anyone gets serious about this and wants a wav or two converted and wants to avoid the cygwin process, I'm willing to do it and send you the text array.

4. Lastly, the text array is pasted into the arduino sketch and loaded onto the Uno32.


----------



## vmrod (Jul 2, 2010)

If you wouldn't mind, I would just use your sound. That is very nice! Kinda like a howling wind or banshee.

I may start on this in another month. Gotta buy and install the batteries next.


----------



## Siwastaja (Aug 1, 2012)

Using a separate speaker sounds kind of fake to me (no offense) /.

Modulating the PWM frequency of the controller is the way to go!

Some oldish AC inverters have done this. Probably not for the sound, but for possibly easier implementation when the PWM frequency is not fixed but varies with the fundamental frequency.... Some later designs may do it just for fun.

Our DIY AC drive "emulates" the sound of some older AC metro train drives. Or, better said, is probably implemented in the similar (easiest) way that gives off the sound. I mean this sound: https://www.youtube.com/watch?v=Kz6C9drIJP8 . We haven't nailed it down yet exactly, but somewhat there, done the simplest possible way: https://www.youtube.com/watch?v=jnp2wOWdOXc

I have though of connecting the audio output of the radio to the motor controller, A/D convert, perform FFT, detect the highest spike and use it or its multiple as the PWM frequency. This would sync the motor sound with any music played.

My opinion is that an EV should be either fully silent or have an "EV" sound of its own, coming from the real technology behind it, no fake.

(We get less losses when using audible frequencies using cheap old IGBTs that are slower than the modern-day counterparts.)


----------



## njloof (Nov 21, 2011)

It would be interesting to see whether this setup could meet the proposed specs here:

http://www.nhtsa.gov/SampleSounds


----------



## swoozle (Nov 13, 2011)

Siwastaja said:


> Our DIY AC drive "emulates" the sound of some older AC metro train drives. Or, better said, is probably implemented in the similar (easiest) way that gives off the sound. I mean this sound: https://www.youtube.com/watch?v=Kz6C9drIJP8 . We haven't nailed it down yet exactly, but somewhat there, done the simplest possible way: https://www.youtube.com/watch?v=jnp2wOWdOXc


Ya, that is cool. It's too bad some auto OEM hasn't used that effect as a distinctive feature.


----------



## vmrod (Jul 2, 2010)

I dont mind 'fake' sound. As it could be shutoff for 'stealth mode'. :>

Of course, you could also install a high speed blower directly to the commuter shaft for a real whine sound.

I like the programmable and silencable one better though.


----------



## swoozle (Nov 13, 2011)

*Uno32 Code*

The sketch is attached.

From the sketch :
A sound sample player that varies playback frequency based on detected RPM.
Based heavily on "Mini Polyphonic Sampling Synth" by Phil Burgess
http://hackaday.com/2011/06/08/chipkit-sketch-mini-polyphonic-sampling-synth/

Sample data is on the next tab. Lots of room for more/bigger samples.
See the link above for instructions on turning sound clips into the appropriate data array

Phil's player sets up PWM on pin 3 and then varies the duty cycle of that PWM to approximate the sound waveform.
I added:
1. an interrupt to measure the RPM pulse interval and enable calculation of RPM
2. A task that runs every 50ms that calculates RPM and changes the waveform playback frequency by adding 3X the RPM to the nominal playback frequency. 
Faster RPM = Higher pitch/faster sound playback

The effect is relatively subtle at 3X. The multiplier is easily changed to suit personal preference.

The sound arrays and playback code are still set up such that multiple samples with on-the-fly switching between samples could easily be done. If anyone wants such a version, let me know.

I pulled out the code for the serial display and bluetooth data transmission of RPM. If anyone wants that version, let me know.


----------

