View previous topic :: View next topic |
Author |
Message |
ali6094
Joined: 31 Jan 2007 Posts: 18
|
ADC questions |
Posted: Sat Mar 31, 2007 10:52 pm |
|
|
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
|
Re: ADC questions |
Posted: Sat Mar 31, 2007 11:34 pm |
|
|
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
|
|
Posted: Sun Apr 01, 2007 11:35 am |
|
|
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
|
|
Posted: Sun Apr 01, 2007 12:03 pm |
|
|
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
|
|
Posted: Sun Apr 01, 2007 12:25 pm |
|
|
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] |
|
|
|