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
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Remove PWM-frequency sound

Post by adafruit_support_bill »

You could go still slower on the clock rate
You would probably have better luck going faster. At a high enough frequency, the inductance of the motor coils plus any filter capacitance will do a better job of filtering it out.

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

Re: Remove PWM-frequency sound

Post by blckpstv »

I've read that a 20khz frequentie should eliminate the sound.

I want to try it but how do I do it on a trinket?

It's really important, if this is fixed my whole project is finished :)

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 »

If you want to try faster, then do this:

Code: Select all

   TCCR0B |= CS01;
   TCCR0B &=  ~(CS02 | CS00);  //note! that's a tilde '~', not a minus sign
This will reduce the prescaler to clock-divided-by-8. Your millis and delays will now be fast by a factor of 8 - the processor will count a millisecond every 125 microseconds. You don't need to worry about that for your random numbers, but it will affect any delay() statements you have.

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

Re: Remove PWM-frequency sound

Post by blckpstv »

adafruit_support_rick wrote:If you want to try faster, then do this:

Code: Select all

   TCCR0B |= CS01;
   TCCR0B &=  ~(CS02 | CS00);  //note! that's a tilde '~', not a minus sign
This will reduce the prescaler to clock-divided-by-8. Your millis and delays will now be fast by a factor of 8 - the processor will count a millisecond every 125 microseconds. You don't need to worry about that for your random numbers, but it will affect any delay() statements you have.


This is the solution I think, without my mic it's not heard, going to try it with the mic later on.

The delay I have to bring much higher like 8000 to give it the pause again, maybe even higher.

I'll post if it completly works!

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

Re: Remove PWM-frequency sound

Post by blckpstv »

This solves the sound question perfectly!

The only thing is the delay works strange when I gave it 12000 it did a ritmic varation.

When giving it 300 it just keeps on going.

It's fun to play with.

Thanks GURU's!!!

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

Return to “Microcontrollers”