|
|
View previous topic :: View next topic |
Author |
Message |
skyforme
Joined: 18 Jul 2005 Posts: 14
|
How can I read in this mode - AD conv. SEQM2 |
Posted: Wed Aug 24, 2005 11:01 am |
|
|
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
|
|
Posted: Thu Aug 25, 2005 2:50 am |
|
|
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 |
|
|
|
|
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
|