Remove PWM-frequency sound

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Remove PWM-frequency sound

Post by blckpstv »

I have a setup of trinket 5v motor driver, it works great.

Except for the sound it make coming from the pwm of the trinket I suppose.

I'm using the millis() in my code, so changing the hertz is not a possibility because i've heard it changes the atmega85's setting or internal clock.

Is their an other way of removing the sound?

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Remove PWM-frequency sound

Post by adafruit_support_bill »

You can try adding a large-ish capacitor across the motor leads to smooth things out a bit.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Remove PWM-frequency sound

Post by blckpstv »

Between the positive and negative of the motor?
How would that stop the noise?

I've tried 10uf, 100uf, 250uf but nothing happened?


I have a picture of what I'm working on..

http://dewildequinten.be/5.jpg

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Remove PWM-frequency sound

Post by adafruit_support_bill »

A capacitor will round off the edges of the PWM pulses. This can help reduce the audible noise in some cases. But if the PWM frequency is close to some resonant frequency for your motors, it may not help much.

You might have better luck changing the PWM frequency and adjusting your "millis()" timing to compensate.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Remove PWM-frequency sound

Post by blckpstv »

Is there anywhere you can find it for the trinket and not the arduino.

Because It's something im totally oblivious on how to do it and it would be handy if their was a small tutorial?


Will the millis still work?

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Remove PWM-frequency sound

Post by blckpstv »

Hey is there a way I can see the frequency that goes thru the trinket.

Because than I can calculate the low pass filter with the playground app!

Seems like a good Idea.

Or is there an answer to my former question?! :)

waltr
 
Posts: 306
Joined: Wed Jun 12, 2013 5:01 pm

Re: Remove PWM-frequency sound

Post by waltr »

Hey is there a way I can see the frequency that goes thru the trinket.
An O'scope is a proper instrument to 'see' Voltage in the time domain, or the period of a pulse train which is 1/frequency.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Remove PWM-frequency sound

Post by adafruit_support_rick »

Which PWM output pins are you using?

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Remove PWM-frequency sound

Post by blckpstv »

Only the 0.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Remove PWM-frequency sound

Post by adafruit_support_rick »

Unfortunately, there's no clean and easy way to do this, unless you want to go into the source code for the arduino runtime and change a few things.

The easiest thing to do would be to change the prescaler for Timer 0 from 64 to 256. millis() would still work, but it would be off by a factor of 4. That is, one millisecond would really be 4 milliseconds. delay(10) would actually be a delay of 40.

I don't even know if this would fix your problem, as the timer may still be a multiple of whatever your resonant frequency is.

I suggest you give it a try. In your setup() function, include these lines: (disclaimer: I haven't tested this, but it ought to work. It won't damage anything)

Code: Select all

	sbi(TCCR0B, CS02);
	cli(TCCR0B, CS01);
	cli(TCCR0B, CS00);

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Remove PWM-frequency sound

Post by blckpstv »

what if my millis is in randomseed and thus randomized, will I get enormous times?


I'm going to try it now if it works! Just don't know what the randomseed will do.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Remove PWM-frequency sound

Post by blckpstv »

lazyfattree wrote:what if my millis is in randomseed and thus randomized, will I get enormous times?


I'm going to try it now if it works! Just don't know what the randomseed will do.

Already got this error;


MoterDriver_random.ino:8:20: error: macro "cli" passed 2 arguments, but takes just 0
MoterDriver_random.ino:9:20: error: macro "cli" passed 2 arguments, but takes just 0
MoterDriver_random.ino: In function 'void setup()':
MoterDriver_random:7: error: 'sbi' was not declared in this scope
MoterDriver_random:8: error: 'cli' was not declared in this scope


What do I have to declare?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Remove PWM-frequency sound

Post by adafruit_support_rick »

OK, try this:

Code: Select all

   TCCR0B |= CS02;
   TCCR0B &=  ~(CS01 | CS00);  //note! that's a tilde '~', not a minus sign
Using millis for a random seed won't affect the random numbers you get.

User avatar
blckpstv
 
Posts: 55
Joined: Mon Jan 06, 2014 8:06 pm

Re: Remove PWM-frequency sound

Post by blckpstv »

It's different alright, the tempo differs en is constant aswell as the frequency tone, its still hearable though but less.

Any suggestions?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Remove PWM-frequency sound

Post by adafruit_support_rick »

lazyfattree wrote:Any suggestions?
Not really. You could go still slower on the clock rate, but I really don't think it's going to make all that much difference

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”