PWM - play music

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

PWM - play music

跳至解决方案
5,521 次查看
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,989 次查看
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,989 次查看
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,989 次查看
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,989 次查看
z2Bmnj
Contributor I

Ops...

Yes, is 8 MHz...

 

My code is in Attachment.

 

Thanks

0 项奖励
回复
3,990 次查看
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,989 次查看
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,989 次查看
kef
Specialist I

You meant 8MHz bus clock, I think?

How did you configure PWM period? Is oscilator running?

0 项奖励
回复
3,989 次查看
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,989 次查看
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 项奖励
回复