Searching \ for '[PIC]: Analog Conversion Done Interrupt with C' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=analog
Search entire site for: 'Analog Conversion Done Interrupt with C'.

No exact or substring matches. trying for part
PICList Thread
'[PIC]: Analog Conversion Done Interrupt with CCS'
2001\05\28@002625 by Donovan Parks

flavicon
face
Hello,

I'm using the CCS C compiler and am having trouble getting a #int_ad
interrupt to fire.  I am using the following code:

void main( )
{
   puts( "Hello!");
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_ADC);
   enable_interrupts(ADC_DONE);
   set_adc_channel(0);
   while (1);
}

#INT_AD void Analog_Handler()
{
   puts ( " In Analog Handler! " );
}

Note: I am enabling serial communication and do recieve "Hello!".

Does anyone have any experience with CCS and interrupts?

Donovan

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\05\28@005158 by Donovan Parks

flavicon
face
I posted the wrong code below... here is the correct code:

#INT_AD void Analog_Handler()
{
   puts ( " In Analog Handler! " );
}

void main( )
{
   puts( "Hello!");
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_ADC);
   enable_interrupts(ADC_DONE);
   setup_adc(ADC_CLOCK_DIV_32);
   setup_adc_ports(ALL_ANALOG);
   set_adc_channel(0);
   while (1);
}

Thanks for any help.


{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\05\28@015308 by dr. Imre Bartfai

flavicon
face
Hi,

you obviously did not start the A/D conversion itself by means of

... = read_adc()

I hope this helps.

Regards,
Imre


On Sun, 27 May 2001, Donovan Parks wrote:

{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\05\28@020759 by Donovan Parks

flavicon
face
Hello,

I see... I though one had to set the channel and then wait for a int_adc
interrupt that would let you know the data is ready.  How long to I have to
wait between calling set_adc_channel( ) and read_adc( ) (or does CCS handle
this)?

Thanks


{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\05\28@022041 by Dale Botkin
flavicon
face
Donovan,

Caveat: Untested code follows, I have never used the interrupt for A/D
stuff.  Nothing I have done so far is so pressed for time it can't handle
waiting for a conversion to finish.  I just use read_adc().  That function
sets the GO/!DONE bit, waits for it to clear, then returns the ADC result.

Having said that...

On Sun, 27 May 2001, Donovan Parks wrote:

> I posted the wrong code below... here is the correct code:
>
> #INT_AD void Analog_Handler()
> {
>     puts ( " In Analog Handler! " );
> }

Looks straightforward enough.

> void main( )
> {
>     puts( "Hello!");
>     enable_interrupts(GLOBAL);
>     enable_interrupts(INT_ADC);

My helpfile lists INT_AD but not INT_ADC...

>     enable_interrupts(ADC_DONE);

And I don't see this listed at all...

>     setup_adc(ADC_CLOCK_DIV_32);
>     setup_adc_ports(ALL_ANALOG);
>     set_adc_channel(0);
>     while (1);
> }

I looked at the asm code generated by set_adc_channel(0).  All it does is
set the channel select bits in ADCON, it doesn't start a conversion.
This would explain why you never get an interrupt.  here's what I think
you may need to try, assuming you just can't wait for read_adc() to do its
thing:

#define ADCON 0x1f

if(!bit_test(ADCON,2)) bit_set(ADCON,2);

This will start the conversion if there's not one going already, and you
should see an interrupt when it's done.

In another reply you say:

>I see... I though one had to set the channel and then wait for a int_adc
>interrupt that would let you know the data is ready.  How long to I have
>to wait between calling set_adc_channel( ) and read_adc( ) (or does CCS
>handle this)?

If you want to use interrupt driven analog you don't want to use
read_adc(), since as noted above it waits for the conversion to start.
You need to wait the acquisition time after issuing the set_adc_channel()
call, which looks to be around 20usec.  I usually don't worry about it
since I do the set_adc_chanel in the initialization phase and don't use
read_Adc() until later on.  To be really safe you could do a delay_us(20)
after selecti gthe channel.

> Thanks for any help.

I hope this qualifies as help...  8-)

Dale
--
A train stops at a train station.  A bus stops at a bus station.
On my desk I have a workstation...

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\05\29@014421 by dr. Imre Bartfai

flavicon
face
Hi,

2 usec as sampling time.

Imre


On Sun, 27 May 2001, Donovan Parks wrote:

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...