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 support@ccsinfo.com

A/D problem in 18LF6720

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



Joined: 06 Apr 2004
Posts: 9

View user's profile Send private message

A/D problem in 18LF6720
PostPosted: Wed Jun 23, 2004 8:47 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 23, 2004 9:12 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Jun 23, 2004 9:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 23, 2004 10:01 pm     Reply with quote

Eric Minbiole,
Thanks for your suggestion but after i change my delay to 250ms second but it still can't work. Rolling Eyes
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