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

ADC questions

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



Joined: 31 Jan 2007
Posts: 18

View user's profile Send private message

ADC questions
PostPosted: Sat Mar 31, 2007 10:52 pm     Reply with quote

my objective is to get 450 samples of an analogue input in 88 sec
almost one sample in 0.195 sec ... using PIC16F877A

how can i do that ?
i have to start this sampling with an intrupt, like a trigger? any help in this regard?
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: ADC questions
PostPosted: Sat Mar 31, 2007 11:34 pm     Reply with quote

ali6094 wrote:
i have to start this sampling with an intrupt, like a trigger?

Yes. Set up a timer interrupt that overflow in 0.195 sec. Read the data from the ADC in the ISR or set a flag in the ISR and read the ADC in main(), this choice depends on your timing requirements. Decrement the counter until you count down from 450 to 0.
ali6094



Joined: 31 Jan 2007
Posts: 18

View user's profile Send private message

PostPosted: Sun Apr 01, 2007 11:35 am     Reply with quote

how to calculate the value for

set_timer1( 0x???? );

For a crystal of 20MHz
and Mode setup_timer_1( T1_INTERNAL );[/quote][/code]
Ttelmah
Guest







PostPosted: Sun Apr 01, 2007 12:03 pm     Reply with quote

ali6094 wrote:
how to calculate the value for

set_timer1( 0x???? );

For a crystal of 20MHz
and Mode setup_timer_1( T1_INTERNAL );
[/code][/quote]

Don't....
Use timer2.
The problem is that setting a timer 'to' a value, itself takes time, and if done in an ISR, more time will already have passed, leading to cumulative errors. Timer2, has the ability to reset itself in hardware.
Have a system 'tick', using timer2, with a prescaler of 15, postscaler of 10, and resetting at 249 (gives 250 counts). This will occur :

20000000/(4*15*10*250) times per second

Just count in this, from 0 to 25. I'd suggest on interrupt 24, starting the ADC, then on interrupt 25, reading it. 26 counts, gives exactly 0.195 secs.

Best Wishes
ali6094



Joined: 31 Jan 2007
Posts: 18

View user's profile Send private message

PostPosted: Sun Apr 01, 2007 12:25 pm     Reply with quote

well i dont know how to do it -- Bad on my part -- any help?

but my question still remain there?
ali6094 wrote:
how to calculate the value for

set_timer1( 0x???? );

For a crystal of 20MHz
and Mode setup_timer_1( T1_INTERNAL );
[/code][/quote]
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