PDA

View Full Version : PIC18F45K80 runs way to fast.



bmoe79
- 19th December 2014, 11:53
Hi.

Im using the PIC18F45K80 for the very first time and use a 64MHz external clock source.
To test the new hardware, and to see that it's alive, I just blinks en LED.
The example blinks the LED way to fast, I just can se a flicker, but if I increse the pause to 5000, then it blinks 36 times in one minute.
Anyone got an idea why this happens?


while 1
high portd.7
pause 500
low portd.7
pause 500
wend



Here is my complete code:

' PIC18F45K80 Configuration Bit Settings
' Basic source line config statements

#CONFIG
CONFIG RETEN = OFF
CONFIG INTOSCSEL = HIGH
CONFIG SOSCSEL = HIGH
CONFIG XINST = OFF
CONFIG FOSC = EC3
CONFIG PLLCFG = OFF
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRTEN = ON
CONFIG BOREN = OFF
CONFIG BORV = 3
CONFIG BORPWR = ZPBORMV
CONFIG WDTEN = OFF
CONFIG WDTPS = 1048576
CONFIG CANMX = PORTB
CONFIG MSSPMSK = MSK7
CONFIG MCLRE = ON
CONFIG STVREN = OFF
CONFIG BBSIZ = BB2K
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CPB = OFF
CONFIG CPD = OFF
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF
CONFIG EBTRB = OFF
#ENDCONFIG


'************************* DEFINES ******************************
define osc 64


define adc_bits 12 ' Set number of bits in result
define adc_clock 3 ' Set clock source (3=rc)
define adc_sampleus 50 ' Set sampling time in uS




'lcdout $FE,$80 rad 1, $FE,$C0 rad 2
define lcd_dreg portc
define lcd_dbit 0
define lcd_rsreg portc
define lcd_rsbit 4
define lcd_ereg portc
define lcd_ebit 5
define lcd_bits 4
define lcd_lines 2
define lcd_commandus 3000
define lcd_dataus 100



'************************ REGISTERS *****************************
ancon0 = 100000
ancon1 = 000000
adcon2.7 = 1




'*********************** PORT CONFIG ****************************
trisa = 100000 'porta direction 0=OUTPUT 1=INPUT
porta = 000000 'porta preset
trisb = 010111 'portb direction 0=OUTPUT 1=INPUT
portb = 000000 'portb preset
trisc = 000000 'portc direction 0=OUTPUT 1=INPUT
portc = 000000 'portc preset
trisd = 111111 'portd direction 0=OUTPUT 1=INPUT
portd = 110000 'portd preset
trise = 001111 'porte direction 0=OUTPUT 1=INPUT
porte = 000000 'porte preset




'************************************************* ***************
'******************* MAIN PROGRAM ************************
'************************************************* ***************
while 1
high portd.7
pause 500
low portd.7
pause 500
wend


end

HenrikOlsson
- 19th December 2014, 12:34
I haven't looked at your CONFIGs and I've never run a PIC with a direct clock signal but the first thing that pops is

define osc 64
defines are case sensitive, osc and OSC are not the same.
It absolutely MUST be define OSC 64.

bmoe79
- 19th December 2014, 13:09
Thank you very much, now it works.

HenrikOlsson
- 19th December 2014, 13:24
Great, and remember that it applies to the other defines you've got in there as well.