View previous topic :: View next topic |
Author |
Message |
Skirmitt
Joined: 19 May 2009 Posts: 60
|
DAC audio to PWM audio with PIC18 |
Posted: Wed Nov 19, 2014 7:34 am |
|
|
I'm trying to simplify an audio project I did in the past. With this board I play 8bit audio from an SD card with a PIC18f2685. With timer 1 I send the audio at a rate of 22kHz to an r2r network. I also need to be able to change the pitch so by changing the freq of timer 1 this is easy.
Now, how could I change my code to change this to a PWM solution ?
Do I need an extra timer ? Or can I just setup the PWM output with the code I use:
Code: | at 32MHz
setup_timer_1(t1_internal | t1_div_by_8 );
|
in the timer routine:
gives 22KHz and by changing this value a bit I can pitch the sound
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Thu Nov 20, 2014 4:57 am |
|
|
The PWM, is not really suitable for this.
The basic timing resolution, is only 8bit. Even if you fiddle around and program the prescaler as well, it only extends to 10bit. The PWM, is designed to give relatively accurate pulse widths, but frequency is only low resolution. |
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Fri Nov 21, 2014 4:26 am |
|
|
Thanks, I'll leave it as is. |
|
|
|