View previous topic :: View next topic |
Author |
Message |
serching
Joined: 06 Apr 2004 Posts: 9
|
A/D problem in 18LF6720 |
Posted: Wed Jun 23, 2004 8:47 pm |
|
|
I have some problems when running the program as below:
Code: | #include <18F6720.H>
#device ADC=10
#fuses HS,WDT128
#use delay(clock = 10000000)
#OPT 9
#define DB9Xmit pin_C6
#define DB9Rcv pin_C7
#use rs232(baud = 9600, xmit = DB9Xmit, rcv=DB9Rcv) //DB9
#include <stdio.h>
#include <string.h>
main()
{
long value;
restart_wdt();
SETUP_ADC(ADC_CLOCK_INTERNAL);
SETUP_ADC_PORTs(RA0_ANALOG);
set_adc_channel(0);
restart_wdt();
delay_ms(1000);
restart_wdt();
value=read_adc();
restart_wdt();
delay_ms(1000);
restart_wdt();
printf("\n\rA/D value = %4Lx\n\r",value);
while(1)
{
restart_wdt();
}
} |
I found that the program will restart when read_adc() is run so i cannot get any result. Can anyone help me in this problem. Thanks. |
|
|
Eric Minbiole
Joined: 10 Jun 2004 Posts: 16 Location: USA
|
|
Posted: Wed Jun 23, 2004 9:12 pm |
|
|
It looks to me like the watchdog is timing out (and restarting your program) during the 1 second "delay_ms(1000)" calls. (The watchdog is configured for 128ms timeout.)
Try changing your #use delay line to include the "restart_wdt" directive:
Code: | #use delay(clock=10000000, restart_wdt) |
This tells CCS to restart the watchdog automatically during the delays. Another option is to break the delay_ms calls into several smaller delays, and manually restart the watchdog in between each. |
|
|
Eric Minbiole
Joined: 10 Jun 2004 Posts: 16 Location: USA
|
|
Posted: Wed Jun 23, 2004 9:31 pm |
|
|
Oops... I miscalculated the watchdog timeout. It's not 128 ms, but 128 x Watchdog Period, Twdt. According to the datasheet, this can be as low as 7ms. At that period, the timeout is 7ms * 128 counts = 896ms.
If your watchdog is running on the fast side of the spec, it's still possible that you are timing out during the delay_ms call(s). Though I may be completely off track, if your chip is running more toward the 'typical' side of the spec. |
|
|
serching
Joined: 06 Apr 2004 Posts: 9
|
|
Posted: Wed Jun 23, 2004 10:01 pm |
|
|
Eric Minbiole,
Thanks for your suggestion but after i change my delay to 250ms second but it still can't work. |
|
|
|