|
|
View previous topic :: View next topic |
Author |
Message |
Morgan Guest
|
Sampling at 8kHz |
Posted: Sat Jul 26, 2003 9:47 am |
|
|
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 |
Posted: Sat Jul 26, 2003 2:53 pm |
|
|
:=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 |
|
|
|
|
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
|