|
|
View previous topic :: View next topic |
Author |
Message |
Pilot
Joined: 06 Jul 2004 Posts: 9
|
ADC using interrupts |
Posted: Sun Aug 01, 2004 11:47 am |
|
|
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
|
Re: ADC using interrupts |
Posted: Sun Aug 01, 2004 2:51 pm |
|
|
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
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);
}
|
|
|
|
|
|
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
|