PDA

View Full Version : 16f818 from 16f628a



andybarrett1
- 25th August 2014, 12:24
Hi....

Help !!!!

Have just ported a program fom 16f628 to 16f818 but nw it wont go....
reason for porting was needing faster clock speed 818 can go at 20Megs 628 only 4 !

having spent morning getting nowhere thought I would blink an LED... Easy !!

No Joy.... So somthing wrong with my config. But what ???

INC File :- I am using MPASM!




;************************************************* ***************
;* 16F818.INC *
;* *
;* By : Leonard Zerman, Jeff Schmoyer *
;* Notice : Copyright (c) 2004 microEngineering Labs, Inc. *
;* All Rights Reserved *
;* Date : 01/07/04 *
;* Version : 2.45 *
;* Notes : *
;************************************************* ***************
NOLIST
ifdef PM_USED
LIST
include 'M16F81x.INC' ; PM header
device pic16F818, hs_osc, wdt_on, pwrt_on, lvp_off, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F818, r = dec, w = -302
INCLUDE "P16F818.INC" ; MPASM Header
__config _INTRC_CLKOUT & _PWRTE_ON & _LVP_OFF & _CP_OFF & _MCLRE_OFF
NOLIST
endif
LIST

CODE :-




' Example program from manual to blink an LED

DEFINE OSC 8 'Set oscillator in MHz

trisa = 0
trisb = 0
adcon1 = 7

main: High PORTB.5 ' Turn on LED connected to PORT
Pause 1000 ' Delay for 1 seconds
Low PORTB.5 ' Turn off LED connected to PORT
Pause 1000 ' Delay for 1 seconds

Goto main ' Go back to loop and blink LED forever
End

What is wrong here....... PLease help advise !!

Thank you

HenrikOlsson
- 25th August 2014, 13:31
Hi,
There are 628's available that are specified to run at 20MHz - i used one this weekend.
With that said, your config for the 818 says INTRC which means you're running from the internal oscillator. Looking at the oscillator section of the datasheet it's clear that the internal oscillator defaults to 31.25kHz while you're telling the compiler that your chip is running at 8MHz - which it isn't. I notice this:

DEFINE OSC 8 'Set oscillator in MHz
Please note that DEFINE OSC xxx does not SET the oscillator speed in any way. What it does is inform the compiler at which speed you intend to run the PIC so that it can calculate the proper delays etc. In this case you're telling the compiler that the PIC is operating at 8MHz when in fact it's operating at 31.25kHz. Your one second pause becomes a 256 second pause. I think that if you leave the circuit powered up long enough you will see the LED blink.

/Henrik.

EDIT: Add OSCCON = 112 to set the oscillator to 8MHz.
EDIT2: As far as I can see all 16F628A's are specified to run at 20MHz.

Acetronics2
- 25th August 2014, 13:33
Halas ...


reason for porting was needing faster clock speed 818 can go at 20Megs 628 only 4 !


nor the 628 nor 818 have 20 Mhz INTERNAL available ...

sooo, you just have to use an EXTERNAL XTAL in HS mode ...
no need to choose an exotic number and try to port your program for it ... as the 628/04 easily can run @ 20 Mhz EXTERNAL ...

... Alain

andybarrett1
- 25th August 2014, 15:08
EDIT: Add OSCCON = 112 to set the oscillator to 8MHz.
EDIT2: As far as I can see all 16F628A's are specified to run at 20MHz.

Ahhhhhh…. I am hoping this maybe the answer …. Will try this later.

Will let you know if it works.

Am trying to get stuff going using internal RC clock…. Then can do drop in upgrade !

TY

Andy

andybarrett1
- 27th August 2014, 07:31
Yes ….

Was the clock misunderstand on my part!

Thank you for pointers and help

Andy