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

18f23k22, using internal clock, timing issue

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



Joined: 12 Mar 2010
Posts: 10

View user's profile Send private message

18f23k22, using internal clock, timing issue
PostPosted: Sun Feb 13, 2011 11:33 am     Reply with quote

This is the first time I have used a 'K' family of pic. Trying to do a hello-world blink and LED. If I download the following:
Code:

#include <18F23K22.h>
#device adc=16
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC                    //Internal RC Osc
#FUSES NOPLLEN               
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_NOSLEEP           
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(int=16000000)

void main()
{
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);
   while(1)
   {
      output_high(pin_c0);
      delay_ms(1000);
      output_low(pin_c0);
      delay_ms(1000);
   }
}

and run it, C0 stays high. If I run the same code, but start it from the debugger, I get C0 toggling once a second like it should. If I reduce the delay from 1000ms down to 100ms, it works with or without the debugger. If I do this:
Code:

 while(1)
   {
      output_high(pin_c0);
      delay_ms(100);
      delay_ms(100);
      delay_ms(100);
      delay_ms(100);
      delay_ms(100);
      output_low(pin_c0);
      delay_ms(100);
      delay_ms(100);
      delay_ms(100);
      delay_ms(100);
      delay_ms(100);
   }

...it fails unless started in the debugger. Seems like a clock config issue, but nothing I try seems to make a difference. Thoughts? Suggestions?

Thanks,

Zach
Zachr



Joined: 12 Mar 2010
Posts: 10

View user's profile Send private message

PostPosted: Sun Feb 13, 2011 1:18 pm     Reply with quote

Should have mentioned using I'm using 4.119

-Zach
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 13, 2011 2:18 pm     Reply with quote

Try a more simple program:
Code:

#include <18F23K22.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=16M)

//======================================
void main(void)
{

while(1)
  {
   output_high(PIN_C0);
   delay_ms(1000);
   output_low(PIN_C0);
   delay_ms(1000);
  }

}

I tested this in hardware for an 18F45K22 and it worked. I ran it in
standalone (not debugger) mode. This was with vs. 4.119.
Zachr



Joined: 12 Mar 2010
Posts: 10

View user's profile Send private message

PostPosted: Sun Feb 13, 2011 2:34 pm     Reply with quote

Thanks! That helped me figure it out. The issue is that the even though I was using the NOWDT fuse, if the WDT128 fuse is in there, the watchdog starts up.

The PIC wizard adds the WDT128 fuse even if you say you don't want to use the watchdog timer. Seems to be a bug.
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