PWM - play music

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
5,495件の閲覧回数
z2Bmnj
Contributor I

Hello everyone!

 

I want to convert songs such as "wav" and play it on s12x. How I do that?

 

Is there any program that converts the music in any format, so I just need to load the values on the accumulators and store them on the registers of the PWM?

 

Thank's for your attention!

ラベル(1)
0 件の賞賛
返信
1 解決策
3,963件の閲覧回数
kef
Specialist I

8MHz of what? Bus clock? Oscilator clock?

 

You have PMPRCLK=0 (1:1 prescaler), PWMCAE=$80 (center aligned), PWMCLK=$80 (clock SB), PWMSCLB=0 (SB clock is clock B /512), PWMPER=$FF (PWM period = $FF=255 SB clocks). I think ith these settings and 8MHz bus clock you should get 8MHz / 2 / 512 / 255 = 30.6Hz PWM period. Where first /2 divider is due to center aligned mode.

 

I don't know why do you get 2.75kHz. Setting PWMSCLKB=0 (clock SB = clock B /2) and PWMPER=181 you should get

quite close to 11.05kHz PWM period, of course if your bus clock is really 8MHz. In this case you get less than 8bits PM resolution, duty cycle setting (PWMDTY) is limited from 0 to 181. To get the best resolution use edge aligned mode, no prescaler and concatenated (16bits) mode. PWMDTY67 = 8MHz / 11.05kHz  = 724

元の投稿で解決策を見る

0 件の賞賛
返信
8 返答(返信)
3,963件の閲覧回数
z2Bmnj
Contributor I

Thank's for the answers!

 

It's working here.

 

I had the wrong settings of the period.

I used the 'device initialization'.

Thanks!

 

0 件の賞賛
返信
3,963件の閲覧回数
m_yasir
Contributor I

I have developed a voice recording and play back system on AVR microcontroller...

 

It  records speech data through mic on Multimedia card and then after recording is done for a certain pres-set period of time.when a button for playback is pressed by the user, it plays back the recorded sound using PWM and analog filters.

 

Data is stored on the MMC in binary format with 8-bits per sample resolution and 8KHz Sampling frequency and 0.5Watt loud speaker is used for this purpose...

 

The sound quality is reasonably good...

 

 

regards

m.yasir

 

 

0 件の賞賛
返信
3,963件の閲覧回数
z2Bmnj
Contributor I

Ops...

Yes, is 8 MHz...

 

My code is in Attachment.

 

Thanks

0 件の賞賛
返信
3,964件の閲覧回数
kef
Specialist I

8MHz of what? Bus clock? Oscilator clock?

 

You have PMPRCLK=0 (1:1 prescaler), PWMCAE=$80 (center aligned), PWMCLK=$80 (clock SB), PWMSCLB=0 (SB clock is clock B /512), PWMPER=$FF (PWM period = $FF=255 SB clocks). I think ith these settings and 8MHz bus clock you should get 8MHz / 2 / 512 / 255 = 30.6Hz PWM period. Where first /2 divider is due to center aligned mode.

 

I don't know why do you get 2.75kHz. Setting PWMSCLKB=0 (clock SB = clock B /2) and PWMPER=181 you should get

quite close to 11.05kHz PWM period, of course if your bus clock is really 8MHz. In this case you get less than 8bits PM resolution, duty cycle setting (PWMDTY) is limited from 0 to 181. To get the best resolution use edge aligned mode, no prescaler and concatenated (16bits) mode. PWMDTY67 = 8MHz / 11.05kHz  = 724

0 件の賞賛
返信
3,963件の閲覧回数
z2Bmnj
Contributor I

Hello!

 

Thanks for the answers!

I managed to convert a small music to asm file by the perl script. (with the aid of GoldWave)

But I had another problem now ...
I configured the period of the PWM at 11.05 KHz.
And I used a PTI interrupt to store the values of the asm file on the Duty Cycle of PWM.
(The time used was 11,111KHz)


Using an oscilloscope, the period found was: 2.75 kHz ...

What is my mistake?

PS: the microcontroller clock frequency is 8 KHz.

Thanks again for your attention!

0 件の賞賛
返信
3,963件の閲覧回数
kef
Specialist I

You meant 8MHz bus clock, I think?

How did you configure PWM period? Is oscilator running?

0 件の賞賛
返信
3,963件の閲覧回数
hotwolf
Contributor II

Here is also a Perl script that converts WAV files into ASM tables:

 

http://github.com/hotwolf/HSW12/blob/master/Perl/wav2asm.pl

 

It is based on AN2250. The input format is WAV 11.025kHz 8-bit mono. The output is a set of ASM tables containing 8-bit values to be passed on to the PWM. Each table fits into a 16k flash page.

0 件の賞賛
返信
3,963件の閲覧回数
kef
Specialist I

I guess you didn't read this application note yet:

 

AN2250 Audio Reproduction on HCS12 Microcontrollers

 

Some zip files with souce code are available here:

 

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=S12D&fpsp=1&tab=Documentation_Tab

0 件の賞賛
返信