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
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!
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!
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.
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
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
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
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
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:
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
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