pwm and beep

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

I have to generate a sound like a beep using the pwm. I'm using an atmega8535 and I don't know how to do it

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

There are threads in the tutorials section that tell you how to use PWM.

Regards,
Steve A.

The Board helps those that help themselves.

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

It's not that the problem. I don't know how to sample a beep. The frequency of the signal

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

Something in the audio range. Concert A is 440Hz.

Regards,
Steve A.

The Board helps those that help themselves.

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

Yeah, something between 440 and 1000 Hz should be good. Make it a square wave and you'll have a "purer" tone. Change the duty cycle away from 50-50 and you'll get a tone with more "edge".

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

Thanks a lot :)

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

Another question. Does the beep happen when TCNT0 reach ocr0, with the rising edge of the square wave?

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

Quote:

Another question. Does the beep happen when TCNT0 reach ocr0, with the rising edge of the square wave?

If you are using PWM you record a beep on your PC (or any "WAV" for that matter - you can use music or voice if you like). This gives you a table of "PCM" samples. On the AVR you setup a timer to do PWM with an overflow interrupt that occurs at the same rate that you sampled the sound on the PC (maybe 8kHz?). Each time the timer overflows you take the next PCM value from the table of samples and set it into OCR. What comes out of the OCx pin of the micro is the same audio you sampled in the first place (well it's really varying width pulses but after RC filtering this reconstitutes the analog).

If you haven't dnoe so already read AVR335 - this has pictures and everything and tells you exactly how to record/playback.

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

I did it with audacity. I took signal value every 0,0001 sec for 0,0047 sec. Thanks a lot. Now my question is:
can i test the OCF2 or should i use necessary the interrupt "Timer2 compare match Vector Address"?