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 CCS Technical Support

How can I read in this mode - AD conv. SEQM2

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



Joined: 18 Jul 2005
Posts: 14

View user's profile Send private message

How can I read in this mode - AD conv. SEQM2
PostPosted: Wed Aug 24, 2005 11:01 am     Reply with quote

Hello

I want to read four samples if interrupt occurs.
But it always read the same strange thing.

int16 value1,v2,v3,v4;

// This function turns the LEDs on and off
void flash_led() {

output_low(TOGGLE_PIN);
delay_us(value1*10);
output_high(TOGGLE_PIN);
delay_us(value1*10);
}

#int_AD
AD_isr()
{

set_adc_channel(1);
value1 = Read_ADC(ADC_READ_ONLY);
set_adc_channel(0);
v2 = Read_ADC(ADC_READ_ONLY);
set_adc_channel(6);
v3 = Read_ADC(ADC_READ_ONLY);
set_adc_channel(7);
v4 = Read_ADC(ADC_READ_ONLY);
//value = Read_Adc();
flash_led();
// Start the initial conversion
Read_ADC(ADC_START_ONLY);

}


void main()
{

setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|sAN5|sAN6|sAN7|sAN8|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0|ADC_CONT_A_B_C_D|ADC_INT_EVERY_FOUR);
setup_spi(FALSE);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
enable_interrupts(INT_AD);
enable_interrupts(GLOBAL);
setup_low_volt_detect(FALSE);
setup_oscillator(False);

output_high(PIN_D1);
output_high(PIN_D2);
output_high(PIN_C0);


// Start the initial conversion
Read_ADC(ADC_START_ONLY);
while(1)
{}
}

It's the code..
but it alwyas shows the same thing and blinking the LED with strange rate (not pot reference).

Thank you
Ttelmah
Guest







PostPosted: Thu Aug 25, 2005 2:50 am     Reply with quote

The largest value that 'delay_us' can accept from a variable is 255. You are therefore seeing wrapping of the counter, giving variable length delays as the ADC changes. Use something like:
Code:

void flash_led() {
   int16 ctr;
   output_low(TOGGLE_PIN);
   for (ctr=0;ctr<value1;ctr++) delay_us(5);
   output_high(TOGGLE_PIN);
   for (ctr=0;ctr<value1;ctr++) delay_us(5);
}


Depending on your clock rate, the delay will need to be shorter to allow for the time to do the arithmetic on the counter, and the test, but the results should then give a growing delay with larger ADC values.

Best Wishes
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