fast PWM as an audio DAC

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello All,

does someone have some example code (in C) that just puts a value out onto the fast PWM that they don't mind me ripping off, err... I mean looking at ? I know it's a bit lazy of me, but I don't want to 're-invert the wheel' if a block of code already exists.

I want to use the ATtiny24v to play out an audio signal, 'telelphone' quality low-fi, say 8 bits @ 8Khz.

Thanks

Dren

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmel did this for you in AVR335. It works well.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OCR1=value; //put value in fast pwm

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow - that's easy, I was expecting something more involved ! Well I am used to working with PICs after all :S

Excellent - thanks + thanks for the pointer to the app note.

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The DAC is up and running. I just need to up the frequency and filter off more of the noise and it'll probably do the job. I mean it's not hi-fi but it is (even currently - without proper filtering) acceptable for speech.

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,
What are you using as an digital input signal stream?

The Tiny24 memory can only hold a second or so of sound.

Are you feeding digital audio bytes into the Tiny24 through a software serial port from a PC? Are you using the Tiny24 primarily as a Digital-to-Analog converter? Are you creating a repeating waveform like a triangle wave, a sine wave, or sawtooth wave? Are you changing the frequency of the sound by adjusting the system clock of the Tiny24?

Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

isn't fast pwm only on the pll-enabled devices?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know that this sounds daft to anyone not involved in the project (I think it's a daft idea... and it was mine !), but there are sound reasons why we are doing it this way, trust me.

We are digitising an audio signal and then recontructing it so that we can adjust it's volume from commands over the serial link. Luckily the audio is only very low res speech, so the process seems pretty transparent.

The first thing I did was to generate a test signal sine wave @ 120Hz (I'll post the test code if anyone wants it). Then I put in the ADC and simply played the data through the AVR, then I included a scaling factor and now I'm just about to add in a serial protocol so we can change this value.

The ATtiny24V doesn't have enough memory to store much audio data, and the 8 bit DAC isn't good enough to use the device as some sort of DSP. I suppose that you could make it do text to speech, by building up phonetics from white noise and shifting the frequency of sine waves ?

The ATtiny24V doesn't have PLL, but the 'DAC fn' is extremely simple to use, far easier than I was expecting. You just set up the timer then put values into OCR1 as Bob said. I'm running it at 31K25Hz (8Mhz/256) and have an audio bandwidth of about 4KHz so filtering off the 'noise' is easy as well, even just an RC wasn't too bad.

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

The ATtiny24V doesn't have enough memory to store much audio data,

AT45's are a nice, cheap way, to add more audio data storage to any (SPI) AVR if you need it.