|
|
View previous topic :: View next topic |
Author |
Message |
johnh
Joined: 03 Jan 2004 Posts: 19 Location: UK - Brighton
|
Basics of A/D |
Posted: Wed Apr 07, 2004 2:26 am |
|
|
Hi Guys,
Now these questions may sound daft, but i must start somewhere!!
OK
No. 1 With a 5v internal reference on a 16F873 (10bit) will the result of a READ_ADC automatically be within the range of 0 and 1023? so a voltage of 2.5v will give a reading of 512? Is it as simple as that....? (i know the ADC has to be set up etc etc)
No. 2 I will have an INT every ~16.5ms and within the INT the READ_ADC value will be used. I notice that a delay of around 10ms should be used when switching ADC pins (i am going to use 3 ADC pins). Is this ringing any warning bells with anyone. ie will i be pulling my hair out trying to get this to work.
The code will have 2 modes. Calibration mode and running mode:
In calibration mode 3 ADC's will be used. The 3 values will be read and the size of the values will be added together and alter the size of a uS delay that is within the INT routine.
In running mode just one ADC will be used and this value will alter the size of a uS delay within the INT routine.
The modes will be selected by testing an input for high or low.
Any advice and sharing of experiences most welcome.. just about to start coding this and not being too experienced at this it would be good to have some comments/things to look out for.
Cheers everyone.
John _________________ There are 10 kinds of people who understand binary, those who do and those who don't |
|
|
Guest
|
Re: Basics of A/D |
Posted: Wed Apr 07, 2004 4:10 am |
|
|
johnh wrote: | Hi Guys,
Now these questions may sound daft, but i must start somewhere!!
OK
No. 1 With a 5v internal reference on a 16F873 (10bit) will the result of a READ_ADC automatically be within the range of 0 and 1023? so a voltage of 2.5v will give a reading of 512? Is it as simple as that....? (i know the ADC has to be set up etc etc)
No. 2 I will have an INT every ~16.5ms and within the INT the READ_ADC value will be used. I notice that a delay of around 10ms should be used when switching ADC pins (i am going to use 3 ADC pins). Is this ringing any warning bells with anyone. ie will i be pulling my hair out trying to get this to work.
The code will have 2 modes. Calibration mode and running mode:
In calibration mode 3 ADC's will be used. The 3 values will be read and the size of the values will be added together and alter the size of a uS delay that is within the INT routine.
In running mode just one ADC will be used and this value will alter the size of a uS delay within the INT routine.
The modes will be selected by testing an input for high or low.
Any advice and sharing of experiences most welcome.. just about to start coding this and not being too experienced at this it would be good to have some comments/things to look out for.
Cheers everyone.
John |
1) Yes.
2) I'd suggest something like this (in the interrupt handler).
Code: |
//have this as a global definition
int16 adval[3];
int8 counter=0;
int8 adnum=0;
switch case (counter++) {
case 0:
set_adc_channel(adnum);
break;
case 1:
read_adc(ADC_START_ONLY);
break;
case 2:
adval(adnum)=read_adc(ADC_READ-ONLY);
if (++adnum==4) adnum=0;
counter=0;
break;
}
|
Now seriously, forget about changing delay times inside the interrupt. delays inside interrupt routines, unless extremely short (a couple of uSec, for synchronisation), should be avoided like scrofulus. If you need the delayed event to be synchronous to the interrupt, have a global 'tick' value, that is toggled in the interrupt routine, and when this changes do your arithmetic and delay in the main code.
Remember that you must have the ADC=10 declaration of the data returned will be only 8bits.
Best Wishes |
|
|
|
|
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
|