View previous topic :: View next topic |
Author |
Message |
angel
Joined: 19 Oct 2004 Posts: 40
|
ext_int and adc |
Posted: Wed Dec 17, 2008 7:59 am |
|
|
Hi
In my program there is an external interruption. All work correctly. After that I have tried to use in the main function an ADC code and it seems the external interruption doesn't do what it is expected.
the program is blocked...
The code I have added:
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
data_ADC=read_adc();
setup_adc(ADC_OFF);
I think there is a kind of conflict between the INT_EXT and my ADC code...
Does anyone know the problem?
has I to use #int_AD or #INT_ADOF?
thanks for your answer |
|
|
Ttelmah Guest
|
|
Posted: Wed Dec 17, 2008 8:30 am |
|
|
No, and no.
You don't tell us enough to know what the problem is. What is in your interrupt routine?. What is not doing what you expect?. What chip.
However some comments.
First, 'join the club', of the thousands of users here, who keep using 'ADC_CLOCK_INTERNAL'. On most PICs, unless you are running under 1MHz for the master clock, _you should not use this selection_. It won't stop the ADC working, but will give very poor accuracy. This is becoming one of the commonest 'blunders' posted.
There is no point in using 'ADC_OFF', unless you need to save the few uA of power.
Then, _you need a delay after you select the ADC channel, before you read the ADC_. Read the chip's data sheet about the ADC acquisition requirements. You may well be much 'better off', simply selecting the ADC channel _once_ early on in the main, and then reading the ADC when needed.
Now comes the question about 'what chip'. You are selecting 'ALL_ANALOG'. On some chips, the external interrupt pin, is also useable as an analog input. If so, then this selection is the main problem...
Best Wishes |
|
|
angel
Joined: 19 Oct 2004 Posts: 40
|
|
Posted: Wed Dec 17, 2008 8:49 am |
|
|
Thanks Ttelmah
My pic is a 18F2620.
My int_ext is very simple. I don't think the mistake is in the code:
Code: | void ext_isr(void){
//switch on
if(nnn[0]=='0'){//nnn is a global control variable
fputc(89,B45);//I send a command
nnnbis[0]='1';//global variable of control
}
//switch off
if(nnn[0]=='1'){
fputc(89,B45);
nnn[0]='0';
nnnbis[0]='0';
}
delay_ms(500); // debounce button
if (nnnbis[0]=='1')
nnn[0]='1';
} |
If it is not good to put the ADC_CLOCK_INTERNAL, it means don't I need to write this line of code?
The ADC code worked correctly without the int_ext.
Thanks, I am going to analyze and check all your suggestions. |
|
|
angel
Joined: 19 Oct 2004 Posts: 40
|
|
Posted: Wed Dec 17, 2008 8:58 am |
|
|
and I have checked setup_adc_ports(RA0_ANALOG) due to I am using only this pin to the ADC but the answer of my compiler is
Undefined identifier RA0_ANALOG |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Wed Dec 17, 2008 9:04 am |
|
|
That ADC setup parameter is not valid.
Look in the 18F2620. h file to get the valid parameters for the
SETUP_ADC_PORTS() command.
Last edited by dyeatman on Wed Dec 17, 2008 1:55 pm; edited 1 time in total |
|
|
angel
Joined: 19 Oct 2004 Posts: 40
|
|
Posted: Wed Dec 17, 2008 9:26 am |
|
|
Hi
I tested
.......
setup_adc_ports(AN0|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_16);
...........
And now it is working correctly. I don't know exactly what is VSS_VDD, the reference is 5V maybe?
Thanks |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Wed Dec 17, 2008 2:02 pm |
|
|
According to the PIC18F2620 data sheet page 226 it means the VREF+ and VREF- are
tied to VDD and VSS respectively. |
|
|
|