CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

DAC audio to PWM audio with PIC18

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Skirmitt



Joined: 19 May 2009
Posts: 60

View user's profile Send private message

DAC audio to PWM audio with PIC18
PostPosted: Wed Nov 19, 2014 7:34 am     Reply with quote

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:
Code:
set_timer1(65498);

gives 22KHz and by changing this value a bit I can pitch the sound
Code:
output_b(buffer1);
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Thu Nov 20, 2014 4:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Nov 21, 2014 4:26 am     Reply with quote

Thanks, I'll leave it as is.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group