Pages: 1 [2]   Go Down
Author Topic: PWM with AtTiny85  (Read 5784 times)
0 Members and 1 Guest are viewing this topic.
Idaho, US
Offline Offline
God Member
*****
Karma: 19
Posts: 859
Special User
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

At the very least that seems to mean the pin is being toggled 4x on the AtTiny for every 1 time its toggled on the Arduino.  How that translates into higher quality audio, I'm not sure.
I probably shouldn't be posting to this thread, already having shown my cluelessness, but my understanding is the greater the sample rate, the greater the "horizontal" resolution if you were to look at the wave form on an oscilloscope.

The vertical or Y (amplitude) is any one of 255 steps (8-bit resolution), which makes for a stair-step effect and the audio quality suffers compared to 10-, 12-, or 16-bit which allows more and smaller steps: more and smaller steps gets you get a "smoother" and closer-to-a-true-sine waveform. Increasing the sample rate in the horizontal or X (frequency) axis is another way to reduce stairsteps and increase quality.

The standard Arduino Atmega chips have a 16-bit PWM ability that the ATTiny lacks. Even if the Arduino's sample rate is slower, the increased vertical resolution may make up for it. I.e., whether it's better to have 8-bit + high sample rate, or 16-bit + low sample rate, is a question I leave to the audiophiles.

Of course, your source sample rate has to match what you output. If you simply output at four times the frequency, your sounds effects will play in 1/4th the time and be and be much higher pitched.
Logged

Manchester, New Hampshire
Offline Offline
Edison Member
*
Karma: 4
Posts: 1359
Propmaker
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sample rate is actually much more important than bit depth.  An 8 bit 22khz file doesn't sound bad compared to a 16bit one.  Mainly you notice the lack of bit depth when you get static in the quiet bits.  But you can definitely hear the difference between an 11khz 16bit sound file and a 22khz 16bit file.  And an 8 bit 22khzz file is still going to sound better than an 11khz 16bit file.  Lower bit depth adds noise, but lower sampling rate means you lose high frequencies and the sound gets muddy.  But that's only to a point.  Above 44khz, you're not going to notice a difference.

Also, the 16bit pwm is of little use, because to count up to 65536 between each sample at 44khz would require the processor to be running at 2.8ghz.

At 64mhz, 10bit is doable though.
Logged

Idaho, US
Offline Offline
God Member
*****
Karma: 19
Posts: 859
Special User
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

At 64mhz, 10bit is doable though.
I thought the ATTiny had 8-bit timers/PWM? Does the ATTiny have a 10-bit timer/PWM I missed?
Logged

Manchester, New Hampshire
Offline Offline
Edison Member
*
Karma: 4
Posts: 1359
Propmaker
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some of them do:
http://forum.arduino.cc/index.php?topic=187068.msg1387338#msg1387338
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4781
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tiny x61's apparently.

There's enough specialized Tiny's to put on a whole dog show.


Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

excuse my stupidity.

the link provided http://elm-chan.org/works/sd8p/report.html

what software do you need to view the source codes?

and can this be done with the arduino?

or is there someway the arduino can view this code?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4781
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The standard Arduino Atmega chips have a 16-bit PWM ability

Which are those? 328P and 2560 have 8 bit PWM.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Idaho, US
Offline Offline
God Member
*****
Karma: 19
Posts: 859
Special User
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The standard Arduino Atmega chips have a 16-bit PWM ability
Which are those? 328P and 2560 have 8 bit PWM.
Unless I'm reading it wrong (a distinct possibility), http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM mentions that the 16-bit Timer1 can be used for PWM on, I believe, pins 9 and 10.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4781
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, you got it right. It's the analogWrite() that's limited to 8 bits.

Nope, I got that wrong, there is more bits PWM possible with different AVR's. 10 bit PWM is not a special case.
« Last Edit: November 30, 2013, 03:19:25 pm by GoForSmoke » Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4781
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

excuse my stupidity.

the link provided http://elm-chan.org/works/sd8p/report.html

what software do you need to view the source codes?

and can this be done with the arduino?

or is there someway the arduino can view this code?

If you're comfortable with AVR code and Arduino then you can embed the asm into the c.
http://www.nongnu.org/avr-libc/user-manual/group__asmdemo.html

I have done zero AVR assembler. I am fascinated at the idea of having 32 CPU registers to work with but so far the compiler is tight, faster to write, and does the right thing if I'm careful plus I already know C/C++ well enough for my Arduino needs.

There was an audio project with a wavetable or two earlier this year.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pages: 1 [2]   Go Up
Jump to: