View previous topic :: View next topic |
Author |
Message |
seme1
Joined: 13 Jun 2009 Posts: 21
|
Problem with INTRC + 18F46K20 |
Posted: Sun Jun 14, 2009 3:45 am |
|
|
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
|
|
Posted: Sun Jun 14, 2009 4:39 am |
|
|
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
|
|
Posted: Sun Jun 14, 2009 7:26 am |
|
|
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
|
|
Posted: Sun Jun 14, 2009 7:38 am |
|
|
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
|
|
Posted: Sun Jun 14, 2009 1:28 pm |
|
|
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)
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 14, 2009 2:08 pm |
|
|
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
|
|
Posted: Sun Jun 14, 2009 3:07 pm |
|
|
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
|
|
Posted: Sun Jun 14, 2009 3:34 pm |
|
|
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
|
|
Posted: Sun Jun 14, 2009 4:37 pm |
|
|
Thanks alot...
It turned out I was missing the pull-up resistor. It's working now fine. |
|
|
|