![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
hundil Guest
|
ADC does not work with rtos on 18F24J10 |
Posted: Mon Jan 29, 2007 6:17 am |
|
|
Hiii...
When I use the code below on 18F24J10, with a 44780 compatible LCD
and connect a 0-3V3 adjustable DC voltage to the AN0 pin.
Garbage values are displayed on LCD.
What is wrong with my code?
Thanks in advance...
hundil
Code:
#include <18F24J10.h>
#device adc=10
#FUSES WDT,WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NODEBUG //No Debug mode for ICD
#FUSES XINST //Extended set extension and Indexed Addressing mode enabled
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES PROTECT //Code protected from reads
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES PRIMARY //Primary clock is system clock when scs=00
#use delay(clock=10000000, oscillator, RESTART_WDT) //
#ZERO_RAM
#use rtos(timer=0,minor_cycle=100ms)
#include "lcd.c"
unsigned long a1, a2;
#int_AD
AD_isr()
{
set_adc_channel(0); // input voltage
delay_us(20);
a1= read_adc();
return 0;
}
#task(rate=500ms,max=100ms)
void The_second_rtos_task ( )
{
printf(lcd_putc, "\f VI:%lu VC:%lu", a1 , a2);
}
void main()
{
setup_adc_ports(AN0_TO_AN1|VSS_VDD );
setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_12);
setup_spi(FALSE);
setup_wdt(WDT_ON);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER1);
disable_interrupts(INT_EXT1);
disable_interrupts(INT_EXT2);
enable_interrupts(INT_AD);
setup_oscillator(False);
enable_interrupts(GLOBAL);
READ_ADC(ADC_START_ONLY);
lcd_init();
rtos_run ( );
do{
restart_wdt();
}while(1);
} |
|
![](templates/subSilver/images/spacer.gif) |
hundil Guest
|
missing |
Posted: Mon Jan 29, 2007 6:20 am |
|
|
Sorry For Missing OF CCS Ver. that I use in the message...
The ver. is 4.03...
hundil |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 29, 2007 7:49 am |
|
|
V4.03 is not a correct version number, it should have 3 digits after the dot. You can find the version number at the top of your *.lst file.
Please use the 'code' button when posting code in order to preserve the layout, this make it easier for us to read the code.
Variable a2 never gets a value, so to see garbage is as expected.
What is the value printed for a1, and what value did you expect to get?
Does the value change when you change the input voltage?
Interrupt routines never return values. Remove the 'return 0' and make the function void.
You enable and activate timer1 but you don't have an interrupt handler installed. This is bad practice and could cause your program to hang. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|