Speech generation using PWM..MC9S08QE8

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Speech generation using PWM..MC9S08QE8

1,373 Views
stevec
Contributor III

Hi All,

 

I am looking to digitise voice data at 8kHz 8 bits (using the on board ADC), store it and reproduce it using the PWM facility of the processor. I have no experience of this as I have always used a DAC. Is it feasible to do at 8kHz 8 bit resolution? Also how do I work out what clock rate to use etc? I would also appreciate some pointers to  the the use of PWM for audio generation. Are there any application notes available?

 

Thanks in advance.

Steve

Labels (1)
0 Kudos
9 Replies

857 Views
Encoder1
Contributor III

Hi Steve,

The maximum 8bit res PWM frequency is equal to FBusclock max / 256.

In the case of MC9S08QE8 this is 10MHz/256 = 39kHz, surely enough to permit it to talk provided you are able to modulate it in real time. It should not be impossible: do you remember Commodore 64 in 1982 with a 2/4MHz 8bit 6502 talking? It should not be easy anyway: Commodore 64 had a dedicated sound generator but the power of its CPU was at least 1/5 to 1/10 of 9S08QE8.

You need perhaps all the processing power you may sink from your CPU, so once fixed your PWM frequency, lets say it is 8kHz, you must multiply it for 256*2^N where N is the PWM timer clock prescaler and this frequency must be lower than the maximum permitted Bus frequency (10MHz). In case of 9S08QE8 you may chose N=4 and FBus= 8.19MHz. With same N and Busclock= 10MHz, Fs would be 9765Hz which may be better than 8kHz to filter.

Considered that PWM modulation is independent from the PWM clock rate, I would use the maximum I could achieve, i.e. 39kHz @ 10MHz: this would permit a much easier filtering in the audio frequency band or a better frequency response.

Consider to use a faster CPU: I am using this days a 9S08SH8, extremely similar to -QE8 in size and pinning, at 20MHz to make audio FFT processing and display on a 'scope with 8bit 78kHz PWM. Higher memory sized -QE16/32 can run up to 25MHz Busclock.

Good work and good luck. Let us know of your results!

857 Views
admin
Specialist II

Hi Encoder,

Thanks for the info. I musty admit that I am not up on the theory of PWM audio generation or the reasoning behind your numbers. However I will investigate that further. I chose the QE8 as the RE16 chip I have used in the past is at end of life. I also need a chip that had a sub £1 ($1.50) price tag. I note that the SH8 you mention is at a similar price so will look at that one also. It is not in the LQFP package that I prefer but I can live with that. My target will have one interrupt running which will be the 125uS tick for the 8kHz. It will also serve a 1mS tick for key press detection. When speech is being generated the target will not be doing anything else except looking for the next key press. It will not be overworked. But if I can have a higher clock for the same money I'll go with it! However this will also impact battery life.I am restricted to the 8 bit 8 kHz as this is the lowest resolution I can get away with and still have legible speech and get the maximum storage time from the dataflash I am using. I have considered SD cards but the buffering times of these cards can be considerable requiring large amounts of RAM.

It's early days yet but I'll let you know how it goes. You'll probably get an idea by the amount of questions I put on this forum!

0 Kudos

857 Views
stevec
Contributor III

My only concern about the 9S08SH8 is that it is rated 2.7 to 5.5v. Operating from a 3V battery supply could be problematic if I want to use any of the low voltage detect features. The QE8 is a 1.8 to 3.6 V chip.

0 Kudos

857 Views
Encoder1
Contributor III

I would not recommend a 9S09SH8 for a new design. My best bet for a 5V part would be the new 9S08PA/PT, a 20MHz busclok device which costs ~1€ for the 32k part. In your case the best solution must probably be searched in the 1.8-3.6V parts: -QB8 (the lower cost) or in -QE8/QE16. All these ones are low-power and limited to 10MHz busclock for the 8k parts. -QE16 costs very little more than -QE8, has more memory and runs up to 25MHz.

In addition the 28 soic version of -QE8/-QE16 share the same basic pinning but the latter is much more advanced and has a lot of added peripherals besides of the faster clock.

Salvatore

0 Kudos

857 Views
stevec
Contributor III

I think I have an understanding about what is going on but perhaps you could confirm it.

As I understand it the PWM o/p will toggle when the main counter overflows. It will toggle back when the channel counter overflows, so setting the main counter to 255 with a direct clock from Fbusclk will give me the highest frequency for an 8 bit system. Setting the duty cycle is done by writing the 8 bit value (of my sample) to the channel counter. I will update this channel counter at an 8kHz rate which is the rate that it was sampled at.

I currently am using an MC9S08RE16 (I have some existing hardware I can use as a test set). This has only 1 main counter. I understand that the QE8 and QE16 have two timer modules so I can arrange my 125uS "tick" period independantly of the PWM counter (which with a 20MHz crystal can only give me a 128uS tick)?

Does all that sound ok or am I missing something?

Steve

0 Kudos

857 Views
Encoder1
Contributor III

Hi Steve,

You are almost completely right. Other than, with 10MHz BusClock your tick would be 256x0.1us, i.e. 25.6us (or 12.8us/20MHz), presuming you would run PWM at max pace of 39kHz (10MHz/256). You could manage an interrupt every 256 cycles but it would be better a longer period so a 2nd timer helps you much for that.

Salvatore

0 Kudos

857 Views
stevec
Contributor III

I now have the QE8 wired up. One question. How do I get a 20MHz clock (10MHz bus clock) when it can only accept a 16MHz maximum crystal? I'm sure it's burried in the FLL stuff somewhere. All the processors I've used so far don't have this  feature. I was raised on 6502 stuff back in the days of the Commodore 64 that you mentioned.

Steve

0 Kudos

857 Views
Encoder1
Contributor III

Too easy... You have to study that FLL stuff... Good old day of 6502 with 1Mhz crystal...

From the data sheet you have several options in this case:

  1. You can supply an external precision clock source up to 20MHz to derive 10MHz BusClock (FBE mode)
  2. You can use an external low power, low frequency 32768Hz crystal, set DRS=0, DMX32=1, FLL=608 and achieve a DCO frequency = 19,92MHz, i.e. BusClock= 9,96MHz
  3. You can use the internal reference clock oscillator 31.25-39.0625kHz range, trim it to its higher value (i.e. to 39.0625) during flash programming with the detected TRIM+FTRIM to achieve fDCO= 20.00MHz ±0.5%. DRS=0, DMX32=0, FLL factor=512. This i the method I use with 9S08SH8, putting FLL to 1024 to achieve 40MHz
  4. Use an external 5 or 10MHz crystal, divide it to 39.0625kHz to drive FLL ref and multiply it again to 20MHz in the DCO. With 10MHz crystal main parameters would be: CLKS=10 (ext. ref), RDIV=011 (/256), IREFS=0 (ext. ref) on ICSC1; BDIV=0 (/1), RANGE= 1 (High), HGO= 1 (High gain), EREFS= 1 (oscillator) on ICSC2; DRS=00 (low range DRO up to 20MHz, FLL factor= 512), DMX32=0 (wide range), IREFST= 0 (ext. clock source), CLKST=00 (FLL selected) on ICSSC

I could be wrong in something: it is late in the night and it is always difficult anyhow, I could have missed some parameters but the core of the discussion should be right.

Good luck!

Salvatore

0 Kudos

857 Views
stevec
Contributor III

Thanks Salvatore,

Some good stuff to be going on with.Thank you. I have an interest in using the internal clock source as it will save the cost of the external crystal. Also some board space as well (I have very definite cost and space restrictions). 0.5% should be good enough as I have no time critical stuff going on. I have a concern though about the trim values. Are they put in during programming and is this automatic. Our production facility is not manned by the smartest of people and anything over pressing a couple of buttons would be risky! I believe the last product I did with the 9S08RE16 in it used the Cyclone Pro but that was with an external crystal.

Thanks again.

Steve

0 Kudos