CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ADC using interrupts

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Pilot



Joined: 06 Jul 2004
Posts: 9

View user's profile Send private message ICQ Number

ADC using interrupts
PostPosted: Sun Aug 01, 2004 11:47 am     Reply with quote

Hi,
I did 3 channel adc
Code:

#include "C:\PicPrj\CCSC\LCD_I2C_ADC\LCD_I2C_ADC.h"
#include <LCD.C>
// #int_AD

/*
AD_isr()
{

}
*/

#define ADCCONST 5.0/1024.0

void main()
{
   int i;
   float value1, value2, value3;


   setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   lcd_init();
 //  enable_interrupts(INT_AD);
 //  enable_interrupts(GLOBAL);

   lcd_putc("\fLCD Ok!\n");

   do {
         delay_ms(100);
         set_adc_channel( 0 );
         value1 = Read_ADC()*ADCCONST;

         delay_ms(100);
         set_adc_channel( 1 );
         value2 = Read_ADC()*ADCCONST;

         delay_ms(100);
         set_adc_channel( 2 );
         value3 = Read_ADC()*ADCCONST;

         printf(LCD_PUTC,"\n%4.2f %4.2f %4.2f",value3,value2,value1);

   } while (TRUE);
}


but i want to use interrupt for ADC conversion and dont know how to do it with 3 channels? How i will know which channel is ready for read in the interrupt routine?

Thanks in advance. Ragards.
Pilot



Joined: 06 Jul 2004
Posts: 9

View user's profile Send private message ICQ Number

Re: ADC using interrupts
PostPosted: Sun Aug 01, 2004 2:51 pm     Reply with quote

Pilot wrote:
Hi,
I did 3 channel adc
but i want to use interrupt for ADC conversion and dont know how to do it with 3 channels? How i will know which channel is ready for read in the interrupt routine?

Thanks in advance. Ragards.


I could do it on my self Very Happy

Code:
#include "C:\PicPrj\CCSC\LCD_I2C_ADC\LCD_I2C_ADC.h"
#include <LCD.C>

#define ADCCONST 5.0/1024

float value[3];

#int_AD
AD_isr()
{
   static unsigned char ch=2;
   
   value[ch] = Read_ADC(ADC_READ_ONLY)*ADCCONST;

   printf(LCD_PUTC,"\n%u %4.2f %4.2f %4.2f",ch,value[2],value[1],value[0]);

   if (ch==0) ch=3;
   set_adc_channel(--ch);
   Read_ADC(ADC_START_ONLY);
}



void main()
{
   setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
   setup_adc(ADC_CLOCK_DIV_2);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   lcd_init();
   enable_interrupts(INT_AD);
   enable_interrupts(GLOBAL);

   lcd_putc("\fLCD Ok!\n");

   set_adc_channel( 2 );
   Read_ADC(ADC_START_ONLY);;

   do {
   } while (TRUE);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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