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

Sampling at 8kHz

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







Sampling at 8kHz
PostPosted: Sat Jul 26, 2003 9:47 am     Reply with quote

Hi

I'm using a 20MHz clock on a Pic16F876 and need to sample analog input (sound) at exactly 8kHz. I know I have to use the timer interrupt as I want to do other stuff while I'm waiting, but don't know how to do this. Would appreciate it if anybody could help me.

Thanx
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516386
R.J.Hamlett
Guest







Re: Sampling at 8kHz
PostPosted: Sat Jul 26, 2003 2:53 pm     Reply with quote

:=Hi
:=
:=I'm using a 20MHz clock on a Pic16F876 and need to sample analog input (sound) at exactly 8kHz. I know I have to use the timer interrupt as I want to do other stuff while I'm waiting, but don't know how to do this. Would appreciate it if anybody could help me.
:=
:=Thanx

I'd suggest:

int16 ADvalue;

#INT_TIMER2
void T2INT(void) {
ADvalue=read_adc(ADC_READ_ONLY);
read_adc(ADC_START_ONLY);
}

In main:

setup_timer_2(T2_DIV_BY_1,125,5);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);

and obviously set the ADC to the required channel, and setup as required.

The timer will be called 20000000/(4*125*5) times per second, and immediately reads the ADC value, from the _last_ conversion, and triggers the next conversion. This way, the interrupt code, doesn't have to wait for the ADC hardware.
You will also have to set a flag in the interrupt, to tell the main code to store the number.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516389
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