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 support@ccsinfo.com

Sampling issue

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



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Sampling issue
PostPosted: Fri Aug 29, 2008 2:01 pm     Reply with quote

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 Confused .

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"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 29, 2008 2:48 pm     Reply with quote

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.
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

PostPosted: Fri Aug 29, 2008 3:07 pm     Reply with quote

ill give that a try.
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
RayJones



Joined: 20 Aug 2008
Posts: 30
Location: Melbourne, Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri Aug 29, 2008 4:10 pm     Reply with quote

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
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