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 CCS Technical Support

Problem with INTRC + 18F46K20

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



Joined: 13 Jun 2009
Posts: 21

View user's profile Send private message

Problem with INTRC + 18F46K20
PostPosted: Sun Jun 14, 2009 3:45 am     Reply with quote

PIC18F46k20
PCW 4.078

I have tried the following, and the result is that A0 and A1 are always HIGH !! (there is no flashing effect at all)
Code:

#include <18F46K20.h>
#device adc=8

#fuses  INTRC, NOWDT, PUT ,BROWNOUT, NOLVP
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=4000000)


void main()
{
   while(TRUE){
      output_high(PIN_A1);
       output_high(PIN_A0);

      delay_ms(70);
     output_low(PIN_A1);
     delay_ms(70);
     output_low(PIN_A0);
     delay_ms(70);
   }
}


My understanding is that this does not require the external quartz crystal to work. When running the above, removing the quartz crystal does not cause A1 and A0 to go down as what happened previously with the fuse H4.

Any clues what could be causing this ??
Ttelmah
Guest







PostPosted: Sun Jun 14, 2009 4:39 am     Reply with quote

First, don't launch new threads, for an existing query. Just makes the forum messy, and annoys people.
Second, look at the data sheet. What is connected to AN0/AN1, when the chip is switched on?. What peripheral needs to be turned off to use these pins for digital I/O?.
seme1



Joined: 13 Jun 2009
Posts: 21

View user's profile Send private message

PostPosted: Sun Jun 14, 2009 7:26 am     Reply with quote

Thanks for the response.

I disabled Analog PINs with the following code, and it did not make any difference (A0 and A1 are always HIGH)

Code:

#include <18F46K20.h>
#device adc=8

#fuses  INTRC, NOWDT, PUT ,BROWNOUT, NOLVP
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=8000000)
void main()
{
   setup_port_a(NO_ANALOGS);
   setup_oscillator( OSC_8MHZ );
   setup_adc_ports(NO_ANALOGS|VSS_VDD);

   setup_adc(ADC_OFF|ADC_TAD_MUL_0);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard

 
   while(TRUE){     
   output_high(PIN_A1);
   output_high(PIN_A0);

   delay_ms(10000);
   output_low(PIN_A1);
   delay_ms(10000);
   output_low(PIN_A0);
   delay_ms(10000);
   }

}
seme1



Joined: 13 Jun 2009
Posts: 21

View user's profile Send private message

PostPosted: Sun Jun 14, 2009 7:38 am     Reply with quote

I just tried with pins B0 and B1 instead of A0 and A1 and it didn't make any different. I then tried replacing the section inside the while loop with the following

Code:

while(TRUE){
   output_high(PIN_B1); // B1 goes HIGH
   delay_ms(1000); // My guess is that there is a problem here in the delay_ms function
   output_high(PIN_B0); // B0 stays LOW
   output_low(PIN_B1);
   delay_ms(1000);
   output_low(PIN_B0);
   delay_ms(1000);
}


What happens is that B1 goes HIGH and B0 stays LOW. It's like it never gets passed the delay_ms(1000). It doesn't seem like I have a problem with the I/O configuration. the delay_ms() function seems to be not functioning right for some reason. Any idea what could be causing this ?
seme1



Joined: 13 Jun 2009
Posts: 21

View user's profile Send private message

PostPosted: Sun Jun 14, 2009 1:28 pm     Reply with quote

I tried reducing the delay time from 1000 ms to 10 (delay_ms(100) ) hoping that it would make it work. Unfortunately, it didn't make any difference (B1 is HIGH while B0 is LOW)

Sad Crying or Very sad Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 14, 2009 2:08 pm     Reply with quote

Are you testing this on a hardware board, or is this a Proteus project ?

Try this test program. Your compiler version has a problem with the
internal oscillator configuration. It's set to the wrong frequency. I have
added code to this program to fix that problem.
Code:
#include <18F46K20.h>
#fuses INTRC_IO,NOWDT,PUT,NOLVP,NOPBADEN,NOBROWNOUT
#use delay(clock=4000000)

#byte OSCCON = 0xFD3

//=========================================
void main()
{
OSCCON = 0x52;   // Internal oscillator, 4 MHz

while(1)
  {
   output_high(PIN_B0);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);
  }

}
 
seme1



Joined: 13 Jun 2009
Posts: 21

View user's profile Send private message

PostPosted: Sun Jun 14, 2009 3:07 pm     Reply with quote

I am testing it on a hardware board.

I just compiled and ran your code, and it kept B0 HIGH all the time. I then tried the following

Code:

output_high(PIN_B0);
   delay_ms(500);
output_high(PIN_B1);
   output_low(PIN_B0);
   delay_ms(500);

and B1 was never set HIGH.

Then I tried this:
Code:

output_high(PIN_B0);
output_high(PIN_B1);
   delay_ms(500);
   output_low(PIN_B0);
   delay_ms(500);

and both B0 and B1 were set to HIGH.

The conclusion I came up with is that the program execution gets stuck at the delay_ms() function for some reason. Figuring out why could be the solution to my problem.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 14, 2009 3:34 pm     Reply with quote

Did you build the board yourself, that has the 18F46K20 on it ?
Or did you buy it ? If you built it yourself, did you put a pull-up resistor
on the MCLR pin ? Did you put a 100 nF ceramic cap to ground, on each
Vdd pin ?

If you bought the board, then post the manufacturer and model number
and post a link to the web page for it.
seme1



Joined: 13 Jun 2009
Posts: 21

View user's profile Send private message

PostPosted: Sun Jun 14, 2009 4:37 pm     Reply with quote

Thanks alot...
It turned out I was missing the pull-up resistor. It's working now fine. Smile Smile
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