View previous topic :: View next topic |
Author |
Message |
dpechman
Joined: 04 Dec 2007 Posts: 43
|
How to use int_AD with 18F67J60 ? |
Posted: Wed Oct 26, 2011 5:20 pm |
|
|
I´m trying to use int_AD with 18F67J60.
According to datasheet
2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• Set GIE bit
So I:
Code: |
//turn on int_ad
bit_clear(*0xF9E, 6); //ADIF
bit_set(*0xF9D, 6); //ADIE
bit_set(*0xFF2, 7); //GIE
|
and
Code: |
#INT_AD
void int_ad()
{
myAD[ad_index] = read_adc();
output_high(USER_LED2);
}
#INT_timer2
void timer2_isr()
{
if(readAd){
//output_toggle(USER_LED2);
ad_sel = 0;
set_adc_channel(0);
delay_us(15);
read_adc(ADC_START_ONLY);
ad_index++;
}
}
|
Where timer2 starts the adc conversion, quit the timer2 and will read at int_ad, but its not working.
the pic is running ok, timer2 ok but it dont fire the int_AD never.
any sugestion? |
|
|
dpechman
Joined: 04 Dec 2007 Posts: 43
|
|
Posted: Wed Oct 26, 2011 6:39 pm |
|
|
complementing, I have set enable_interrupts(INT_AD); |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 27, 2011 2:45 pm |
|
|
I don't see where the 18F67J60 datasheet says that Timer2 starts the A/D
conversion. Here's the data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39762f.pdf
In the A/D section, it says that Timer1 or Timer3 is used (not Timer2):
Quote: |
21.6 Use of the ECCP2 Trigger
An A/D conversion can be started by the Special Event
Trigger of the ECCP2 module. This requires that the
CCP2M3:CCP2M0 bits (CCP2CON<3:0>) be
programmed as 1011 and that the A/D module is
enabled (ADON bit is set). When the trigger occurs, the
GO/DONE bit will be set, starting the A/D acquisition
and conversion and the Timer1 (or Timer3) counter will
be reset to zero. Timer1 (or Timer3) is reset to automatically
repeat the A/D acquisition period with minimal
software overhead (moving ADRESH/ADRESL to the
desired location). The appropriate analog input
channel must be selected and the minimum acquisition
period is either timed by the user, or an appropriate
TACQ time is selected before the Special Event Trigger
sets the GO/DONE bit (starts a conversion).
|
Then in the ECCP section, it says you must use Compare mode:
Quote: | 1011 = Compare mode; trigger special event (ECCPx resets TMR1 or TMR3, sets CCPxIF bit, ECCPx trigger also starts A/D conversion if A/D module is enabled). |
What is your overall purpose ? Why do you want to read the A/D at
a specific rate ? What is the desired rate ? What device will supply
the analog voltage that you are reading ? What is the oscillator
frequency of the PIC ? |
|
|
dpechman
Joined: 04 Dec 2007 Posts: 43
|
|
Posted: Thu Oct 27, 2011 2:56 pm |
|
|
Its for my application. The timer2 will be adjusted according to a taco signal in rb0, the reading intervals are dynamic according to the speed of the mechanical part of my machine. (balancing shafts)
The input AD are 2, from piezoelectric sensors and have an big circuit a part to treat it. and its working.
By the way, I make it work, the problem was in initialization of my program, now its working. The code I paste in previous post are correct.
I am sampling at 1.4khz max.
thank you
Last edited by dpechman on Thu Oct 27, 2011 3:02 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 27, 2011 2:59 pm |
|
|
You're right. I misinterpreted your post. You are using code inside Timer2
to start the ADC. I had skipped that part (lol) and thought you were
trying to use Special Event trigger. |
|
|
|