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?
Remove PWM-frequency sound
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Remove PWM-frequency sound
You can try adding a large-ish capacitor across the motor leads to smooth things out a bit.
- blckpstv
- Posts: 55
- Joined: Mon Jan 06, 2014 8:06 pm
Re: Remove PWM-frequency sound
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
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
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: Remove PWM-frequency sound
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.
You might have better luck changing the PWM frequency and adjusting your "millis()" timing to compensate.
- blckpstv
- Posts: 55
- Joined: Mon Jan 06, 2014 8:06 pm
Re: Remove PWM-frequency sound
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?
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?
- blckpstv
- Posts: 55
- Joined: Mon Jan 06, 2014 8:06 pm
Re: Remove PWM-frequency sound
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?!
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?!
-
- Posts: 306
- Joined: Wed Jun 12, 2013 5:01 pm
Re: Remove PWM-frequency sound
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.Hey is there a way I can see the frequency that goes thru the trinket.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Remove PWM-frequency sound
Which PWM output pins are you using?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Remove PWM-frequency sound
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)
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);
- blckpstv
- Posts: 55
- Joined: Mon Jan 06, 2014 8:06 pm
Re: Remove PWM-frequency sound
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.
I'm going to try it now if it works! Just don't know what the randomseed will do.
- blckpstv
- Posts: 55
- Joined: Mon Jan 06, 2014 8:06 pm
Re: Remove PWM-frequency sound
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?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Remove PWM-frequency sound
OK, try this:
Using millis for a random seed won't affect the random numbers you get.
Code: Select all
TCCR0B |= CS02;
TCCR0B &= ~(CS01 | CS00); //note! that's a tilde '~', not a minus sign
- blckpstv
- Posts: 55
- Joined: Mon Jan 06, 2014 8:06 pm
Re: Remove PWM-frequency sound
It's different alright, the tempo differs en is constant aswell as the frequency tone, its still hearable though but less.
Any suggestions?
Any suggestions?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Remove PWM-frequency sound
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 differencelazyfattree wrote:Any suggestions?
Please be positive and constructive with your questions and comments.