View previous topic :: View next topic |
Author |
Message |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
slow pic chip |
Posted: Mon Feb 15, 2010 5:46 pm |
|
|
This is a problem that I've encountered before, but I've never solved it. My pic chip is running about 50 times too slow. I'm trying to blink an led 100 times a second, but it blinks about 2.7 times a second. Does anyone have a suggestion about what this could be?
Thanks!
Richard
chip: pic18f4682
compiler: 4.88.17.16
breadboard with masterclear 47k resistor, external oscilator
Code: | #include "C:\Documents and Settings\Liz Jaquette\Desktop\submersible\4682\4682a.h"
#use delay(clock=20,000,000)
void main()
{
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);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillator Config tab
// TODO: USER CODE!!
WHILE (true)
{
output_toggle(PIN_D1);
delay_ms(10);
}
}
|
.h:
Code: | #include <18F4682.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES LP //Low power osc < 200 khz
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES BBSIZ4K //4K words Boot Block size
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
|
|
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Feb 15, 2010 5:56 pm |
|
|
Quote: | external oscilator | You mean a crystal or a real oscillator module?
Code: | #FUSES LP //Low power osc < 200 khz | It is already in the comments...
For crystal frequencies 4MHz and higher you have to use the HS fuse. Or when using a real oscillator module use the EC fuse.
Code: | setup_spi(SPI_SS_DISABLED); | This is an error in the wizard and creates an invalid setup with undefined behaviour. Change to:
Code: | #use delay(clock=20,000,000) | Remove this line. You already have a '#use delay' line in your header file. Two lines might confuse the compiler, at least it is confusing me. Also, I don't know if all compiler versions handle the decimal separators correctly.
Last edited by ckielstra on Mon Feb 15, 2010 6:00 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 15, 2010 5:57 pm |
|
|
Quote: | #FUSES LP //Low power osc < 200 khz
#use delay(clock=20000000) |
You have a 20 MHz crystal but you're using the LP fuse. You need to
use the HS fuse instead.
Is this a Proteus project ? |
|
![](templates/subSilver/images/spacer.gif) |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
|
Posted: Mon Feb 15, 2010 6:03 pm |
|
|
Thanks. I've changed the fuse. (I had it this way earlier and thought it might be the problem):
#FUSES HS
I also commented out the second #use delay. The light still blinks about 50 times too slow. Any other suggestions? |
|
![](templates/subSilver/images/spacer.gif) |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
|
Posted: Mon Feb 15, 2010 6:04 pm |
|
|
Also changed the setup_spi line without any luck. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 15, 2010 6:10 pm |
|
|
Try a more simple program. Example:
This program will blink the LED on pin D1 once per second.
Code: |
#include <18F4682.h>
#fuses HS,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=20000000)
//==============================
void main()
{
while(1)
{
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
delay_ms(500);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
|
Posted: Mon Feb 15, 2010 6:30 pm |
|
|
Weird. I tried this simpler program and now the light doesn't blink. I tested different timings to be sure that I wasn't missing it. Other ideas? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 15, 2010 6:33 pm |
|
|
What is the version of your compiler ? The version number is not what
you posted. The version is a 4-digit number in this format: x.xxx
It's given at the top of the .LST file. The .LST file will be in your project
directory after a successful compilation. Examples of CCS version
numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
Are you testing this program in real hardware or is this a Proteus project?
If it's real hardware, did you build the board yourself, or did you buy it ?
If you bought it, post the manufacturer and part number of the board. |
|
![](templates/subSilver/images/spacer.gif) |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
|
Posted: Mon Feb 15, 2010 6:38 pm |
|
|
The version is 4.088. This is not a proteus project. I'm just using a breadboard. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 15, 2010 6:45 pm |
|
|
1. What voltage is the PIC running at ? Is it +5 volts ? Does it come
from a regulated power supply ?
2. Describe the circuit on the MCLR pin, including component values.
I know you said 47K, but does the pull-up resistor go to +5 volts ?
3. Describe the oscillator circuit, including component values.
4. Are you trying to run this board in Debug mode, using a hardware
debugger, such as the ICD2, or ICD-U40, etc. ? Or, are you running
it in "standalone" mode (without the debugger) ? |
|
![](templates/subSilver/images/spacer.gif) |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 15, 2010 7:06 pm |
|
|
Quote: | 1. The pic is running +5 volts from a computer's usb.
|
Do we trust this ? Is this a stable, solid, accurate +5v supply ?
Quote: |
3. I'm using this crystal on pins 11 & 12:
Mouser Part #: 73-XT49S2000-S
Manufacturer Part #: XT9SNLANA20M
Manufacturer: Vishay/Dale
Description: Crystals 20MHz SERIES
|
That's a series-resonant crystal.
The PIC's oscillator circuit expects you to use a parallel-resonant crystal.
I've never tried to use a series resonant crystal with a PIC. I don't think
we even have any here at the company. Based on what I've read, it
should oscillate but it might be off frequency. I have no way to verify
this in hardware.
Just as a test, try using the internal oscillator in the PIC and see if it
starts working. Change the oscillator fuse to INTRC_IO and change
the #use delay() to 8 MHz, as shown below:
Quote: |
#include <18F4682.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=8000000)
//==============================
void main()
{
while(1)
{
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
delay_ms(500);
}
} |
Last edited by PCM programmer on Mon Feb 15, 2010 7:13 pm; edited 2 times in total |
|
![](templates/subSilver/images/spacer.gif) |
rwjzownts
Joined: 19 Jul 2008 Posts: 16
|
|
Posted: Mon Feb 15, 2010 7:12 pm |
|
|
That works, so it must be the crystal. I've used these crystals with my 18f2620 and they've worked fine. I'll get the proper crystals. Do you have any part recommendations?
Thanks again! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 15, 2010 8:48 pm |
|
|
This one will work:
Quote: |
Mouser Part #: 520-HCU2000-20X
Manufacturer Part #: ECS-200-20-4X
Manufacturer: ECS
Description: Crystals 20MHz 20pF
Frequency: 20 MHz
Tolerance: 30 PPM
Frequency Stability: 50 PPM
Load Capacitance: 20 pF
Termination Style: Radial
Package / Case: HC-49/US
Operating Temperature Range: - 10 C to + 70 C
|
|
|
![](templates/subSilver/images/spacer.gif) |
|