View previous topic :: View next topic |
Author |
Message |
jacqueskleynhans
Joined: 10 Apr 2008 Posts: 109 Location: Cape Town, South Africa
|
Sampling issue |
Posted: Fri Aug 29, 2008 2:01 pm |
|
|
Hi i need to sample my adc channel fast. I have accelerometer connected to it measuring vibration. Highest spectral component is 1.3k. Need to measure 3 times nyquist at 4k amounts to 250 microseconds. Need to use an interrupt. Question.
Can i use timer0 like this where i simply read the two_fifty_microsecond and when its true i do my adc routine ?
#byte timer0low = 0xfd6
SETUP_TIMER0(RTCC_INTERNAL|RTCC_8_BIT|RTCC_DIV_1);
Code: | #int_TIMER0
void TIMER0_isr(void)
{
timer0low = timer0low + 6;
two_fifty_microsecond = TRUE;
} |
What i need to accomplish is, firstly i need to read the adc every 250us. Then store the value in an array. When x amount is stored, display the array. As you can see I don't know really what to ask .
In my main loop do wait for the interrupt, or say I only have 1 task to do eg
if (two_fifty_microsecond)
return
else
adc 1
adc 2
adc 3
store data in array
if array is full display
else return.
Question: Isn't the main routine going to take longer then the interrupt because of acquisition times and then when it interrupts i have a problem.
Does the interrupt restart as soon as the routine starts or does it only restart when the main is finished ?
Im so confused _________________ "THE ONLY EASY DAY WAS YESTERDAY" |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Aug 29, 2008 2:48 pm |
|
|
When the timer interrupt occurs, it will interrupt the main code and go
do the timer interrupt code. When that routine is finished, the program
will resume executing the main code right at the point where it left off
when it got the timer interrupt. That's how interrupts work.
I suggest that you don't use interrupts for the initial testing of your code.
Just make a "for" loop in main(), and put in a 250 us delay (or a little bit
less, to account for the time spent in the loop), and do all your A/D
sampling in that loop. Store the A/D samples in an array. Then when
the loop is done collecting samples, you can do some math on the data
you have collected.
It's easier to do this if you start with simple code. |
|
![](templates/subSilver/images/spacer.gif) |
jacqueskleynhans
Joined: 10 Apr 2008 Posts: 109 Location: Cape Town, South Africa
|
|
Posted: Fri Aug 29, 2008 3:07 pm |
|
|
ill give that a try. _________________ "THE ONLY EASY DAY WAS YESTERDAY" |
|
![](templates/subSilver/images/spacer.gif) |
RayJones
Joined: 20 Aug 2008 Posts: 30 Location: Melbourne, Australia
|
|
Posted: Fri Aug 29, 2008 4:10 pm |
|
|
I always find it useful to generate a blip on one of the pins so you monitor the sampling period with an oscilloscope.
Simply use something like
Code: | pin = !pin;
pin = !pin; |
pin of course needs to be defined earlier as a #bit variable on an unused pin on your device.
If you look at the listing file, you will see the compiler generates bit toggle instructions BTG so it is quick and effective.
Cheers, Ray |
|
![](templates/subSilver/images/spacer.gif) |
|